Created
May 7, 2020 08:43
-
-
Save andi1984/58a9f35599cb189baa59c788fe3db853 to your computer and use it in GitHub Desktop.
Lambda - Bitbucket, change PR description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from botocore.vendored import requests | |
| import os | |
| def lambda_handler(event, context): | |
| payload = json.loads(event['body'], encoding='utf8') | |
| title = payload["pullrequest"]["title"] | |
| description = payload['pullrequest']['description'] | |
| with open('checklist.txt') as f: | |
| extra_text = f.read() | |
| description += f'\n \n{extra_text}' | |
| # Make request to Bitbucket API | |
| # /2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id} | |
| apiRoute = payload['pullrequest']['links']['self']['href'] | |
| payload = json.dumps({"title": title, "description": description}) | |
| appid = os.environ['bitbucketappid'] | |
| username = os.environ['username'] | |
| headers = { | |
| 'Content-Type': 'application/json' | |
| } | |
| auth=requests.auth.HTTPBasicAuth(username, appid) | |
| response = requests.request("PUT", apiRoute, headers=headers, data = payload, auth=auth) | |
| return {"statusCode": 200} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment