Last active
August 29, 2015 14:22
-
-
Save pentaho-nbaker/d8b5c776e467edab09a7 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| __author__ = 'nbaker' | |
| import requests | |
| import json | |
| import time | |
| import os | |
| if __name__ == '__main__': | |
| unmerged_pulls = [] | |
| errored_pulls = [] | |
| auto_merged = [] | |
| headers = {'content-type': 'application/json', | |
| "Content-Type": "application/json", | |
| "Accept": "application/json"} | |
| params = {'per_page':1000} | |
| org_name = os.environ['GITHUB_ORG_NAME'] | |
| print "build number = " + os.environ['BUILD_NUMBER'] | |
| print "org name = " + org_name | |
| source_branch = os.environ['SOURCE_BRANCH'] | |
| target_branch = os.environ['TARGET_BRANCH'] | |
| print "source branch = " + source_branch | |
| print "target branch = " + target_branch | |
| username = os.environ['GITHUB_USER_NAME'] | |
| password = os.environ['GITHUB_PASSWORD'] | |
| print "username = " + username | |
| print "password = " + password | |
| org_url = 'https://api.github.com/orgs/' + org_name + '/repos' | |
| print "org url = " + org_url | |
| next = org_url + '?page=1' | |
| page = 1 | |
| while True: | |
| repos_request = requests.get(next, auth=(username, password), headers=headers, params=params) | |
| repos = repos_request.json() | |
| # Check to see if we're at the end of the pagination | |
| if len(repos) == 0: | |
| break | |
| # Setup url for next loop | |
| page += 1 | |
| next = org_url + '?page=' + str(page) | |
| urls = [rep["url"] for rep in repos] | |
| for url in urls: | |
| time.sleep(5) | |
| print "processing: "+url | |
| params = { | |
| "title": "Auto-Merge refreshing development branch", | |
| "body": "Merge of master into future-develop", | |
| "head": source_branch, | |
| "base": target_branch | |
| } | |
| url = url + "/pulls" | |
| response = requests.post(url, auth=(username, password), | |
| data=json.dumps(params)) | |
| print response.text | |
| pull = response.json() | |
| if "errors" in pull: | |
| errored_pulls.append( url + str(pull["errors"]) ) | |
| else: | |
| commit_message = {"commit_message" : "Auto Merge of master into future-develop"} | |
| pull_url = pull["url"] + "/merge" | |
| response = requests.put(pull_url, auth=(username, password), data=json.dumps(params)) | |
| print response.text | |
| merge_result = response.json() | |
| if "merged" not in merge_result or merge_result["merged"] is False: | |
| print "not mergable or merge failed: "+pull_url | |
| unmerged_pulls.append(pull_url) | |
| else: | |
| auto_merged.append(url) | |
| print "\n\nerrored:" | |
| for errored in errored_pulls: | |
| print errored | |
| print "\n\nUnmerged:" | |
| for unmerged in unmerged_pulls: | |
| print unmerged | |
| print "\n\nAuto Merged:" | |
| for merged in auto_merged: | |
| print merged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment