Skip to content

Instantly share code, notes, and snippets.

@leplatrem leplatrem/merge.py
Created Jan 30, 2019

Embed
What would you like to do?
merge.py
import os
from github import Github
WITH_BORS = [("mozilla-services", "kinto-dist")]
def main():
g = Github(os.getenv("TOKEN"))
repos = [tuple(repo.split("/", 1)) for repo in os.getenv("REPOS").split(",")]
for owner, name in repos:
org = g.get_organization(owner)
repo = org.get_repo(name)
for pr in repo.get_pulls(state="open"):
if "dependabot" in pr.user.login:
print(f"{pr.html_url} {pr.title}", end=" ")
commit = pr.get_commits().reversed[0]
state = commit.get_combined_status().state
if state == "success":
is_bors = (owner, name) in WITH_BORS # XXX: query API to check if bors enabled
if is_bors:
pr.create_review(commit=commit, body="bors r+", event="APPROVE")
print("APPROVED")
else:
pr.merge(merge_method="squash")
print("MERGED")
else:
if len(list(commit.get_statuses())) == 0:
pr.merge(merge_method="squash")
print("MERGED")
else:
print(f"SKIP (status={state})")
if __name__ == "__main__":
# TOKEN=ac6d1f0...dfd REPOS=mozilla-services/kinto-dist,Kinto/kinto python main.py
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.