The following
Python script will help to export list of any open pull requests from CodeCommit
repositories from an AWS account. The output will be saved within CSV file.
#!/usr/bin/env python3.8
# This script is used to find out any open pull requests from all the repositories
# from an account and write output to the csv file
import boto3
import csv
import time
profile = "default"
region = "us-east-1"
session = boto3.Session(profile_name=profile, region_name=region)
repo_client = session.client('codecommit')
repos = repo_client.list_repositories(
sortBy='repositoryName'
)
repo_list = repos
repo_name =repo_list['repositories']
# Getting current date and time
date_time = time.strftime("%d%m%Y_%H%M%S")
# Setting up file name
fname = "Open_PullReqsIDs_"
ftime = date_time
fext = ".csv"
filename = fname + ftime + fext
# Open file to write output
with open(filename,'w') as f:
print('Repository Name , PullRequest_ID', file=f)
# Get the repository name only
for name in repo_name:
rep_name = name['repositoryName']
response = repo_client.list_pull_requests(
repositoryName=rep_name,
pullRequestStatus='OPEN'
)
# Check if there is any open Pull Request and print it
if response['pullRequestIds'] != []:
print(rep_name,',', response['pullRequestIds'], file=f)
Hope you find
it useful.
Disclaimer:
www.TechieTalks.co.uk does not conceal the possibility of error and
shortcomings due to human or technical factors. www.TechieTalks.co.uk does not
bear responsibility upon any loss or damage arising from conduct or activities
related to the use of data and information contained in this blog.
Comments
Post a Comment