Created
January 30, 2019 14:10
-
-
Save leplatrem/5277fc893bab769ee629a1c4a8f75dc5 to your computer and use it in GitHub Desktop.
merge.py
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 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