Skip to content

Instantly share code, notes, and snippets.

@MattHealy
Last active October 23, 2022 02:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattHealy/d9a73f32a19b426bb440770edc2c9da7 to your computer and use it in GitHub Desktop.
Save MattHealy/d9a73f32a19b426bb440770edc2c9da7 to your computer and use it in GitHub Desktop.
List all open pull requests in AWS Codecommit
import boto3
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'--repo', metavar='repo', type=str,
help='Optionally filter by repository')
args = parser.parse_args()
filterRepository = args.repo
client = boto3.client('codecommit')
region = client.meta.region_name
pullRequests = []
resp = client.list_repositories()
repositories = resp['repositories']
for r in repositories:
if filterRepository:
if r['repositoryName'] != filterRepository:
continue
resp = client.list_pull_requests(
repositoryName=r['repositoryName'],
pullRequestStatus='OPEN',
)
pullRequestIds = resp['pullRequestIds']
for p in pullRequestIds:
pullRequests.append(p)
for i in pullRequests:
resp = client.get_pull_request(
pullRequestId=i
)
pr = resp['pullRequest']
title = pr['title']
description = pr.get('description')
lastActivity = pr['lastActivityDate']
created = pr['creationDate']
authorArn = pr['authorArn']
targets = pr['pullRequestTargets']
for t in targets:
repo = t['repositoryName']
link = 'https://{}.console.aws.amazon.com/codesuite/'.format(region) + \
'codecommit/repositories/{}/pull-requests/'.format(repo) + \
'{}?region={}'.format(i, region)
print("\nLink:\n{}".format(link))
print("\nRepo: {}".format(t['repositoryName']))
print("Source branch: {}".format(t['sourceReference']))
print("Target branch: {}\n".format(t['destinationReference']))
print("Created: {}".format(created))
print("Last Activity: {}".format(lastActivity))
print("Author: {}\n".format(authorArn))
print("Title: {}".format(title))
print("Description: {}\n".format(description))
print("------------------------------------------------------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment