Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ steps:
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'

- task: github-pr-comment@0
inputs:
userToken: '$(githubToken)'
repository: '$(Build.Repository.Name)'
prNumber: '$(System.PullRequest.PullRequestNumber)'
bodyFilePath: 'Tasks/GitHubPRComment/'
extension: 'txt'
getSubFolders: true
- script: |
python do-something.py
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: 'PR Comment'
17 changes: 17 additions & 0 deletions do-something.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pull_request

comment = """
## Useful Table

| Item | Col1 | Col2 | Col3 | Col4 |
|---|---|---|---|---|
| 1 | a | b | c | d |
| 2 | a | b | c | d |
| 3 | a | b | c | d |

Some additional text here
"""
msg = pull_request.Message()
result = msg.add(comment=comment)
if result is False:
print("Sending message failed")
36 changes: 36 additions & 0 deletions pull_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import requests
import os

class Message():
'''Instance of a message'''

def __init__(self):
SYSTEM_COLLECTIONURI = os.getenv('SYSTEM_COLLECTIONURI')
SYSTEM_PULLREQUEST_PULLREQUESTID = os.getenv('SYSTEM_PULLREQUEST_PULLREQUESTID')
SYSTEM_TEAMPROJECT = os.getenv('SYSTEM_TEAMPROJECT')
BUILD_REPOSITORY_ID = os.getenv('BUILD_REPOSITORY_ID')
self.url = f"{SYSTEM_COLLECTIONURI}{SYSTEM_TEAMPROJECT}/_apis/git/repositories/" \
f"{BUILD_REPOSITORY_ID}/pullRequests/{SYSTEM_PULLREQUEST_PULLREQUESTID}" \
"/threads?api-version=6.0"
self.headers = {
"content-type": "application/json",
"Authorization": f"BEARER {os.getenv('SYSTEM_ACCESSTOKEN')}"
}

def add(self, comment: str) -> bool:
''' Add a message to Azure DevOps Pull Request'''
data = {
"comments": [
{
"parentCommentId": 0,
"content": comment,
"commentType": 1
}
],
"status": 1
}
r = requests.post(url=self.url, json=data, headers=self.headers)
if r.status_code == 200:
return True
else:
return False