diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e722edc92..2a1d94f00 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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 \ No newline at end of file +- script: | + python do-something.py + env: + SYSTEM_ACCESSTOKEN: $(System.AccessToken) + displayName: 'PR Comment' \ No newline at end of file diff --git a/do-something.py b/do-something.py new file mode 100644 index 000000000..3b1d48866 --- /dev/null +++ b/do-something.py @@ -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") \ No newline at end of file diff --git a/pull_request.py b/pull_request.py new file mode 100644 index 000000000..f2fecbeba --- /dev/null +++ b/pull_request.py @@ -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 \ No newline at end of file