Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Created December 6, 2021 23:42
Show Gist options
  • Save luckylittle/7a8d552188e6b974871a5d436f14dc59 to your computer and use it in GitHub Desktop.
Save luckylittle/7a8d552188e6b974871a5d436f14dc59 to your computer and use it in GitHub Desktop.
Configuration change auditing in Github
from github import Github
from tabulate import tabulate
from datetime import datetime
"""
This script produces table with all merged pull requests within a certain time period. It is useful for configuration change auditing.
"""
github_token = ''
github_api_url = 'https://githubenterprise.service.com/api/v3'
start_date = "2021-11-01 00:00:00"
end_date = "2021-11-30 23:59:59"
g = Github(base_url=github_api_url, login_or_token=github_token)
final_list = []
start = datetime.fromisoformat(start_date)
end = datetime.fromisoformat(end_date)
for repo in g.get_organization('luckylittle').get_repos():
if repo.name.startswith("prefix"):
pulls = repo.get_pulls(state='all', sort='created')
for pr in pulls:
if (pr.merged_at is not None) and (not repo.name == 'exclude1') and (not repo.name == 'exclude2'):
if start <= pr.merged_at <= end:
ticket = pr.body.splitlines()[1]
final_list.append(
[pr.merged_at, pr.user.name, repo.full_name, pr.number, ticket])
print(tabulate(sorted(final_list), headers=['Merged at', 'Creator', 'Repository', 'PR#', 'Ticket']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment