From b9ebb81800ba08f9efe61830392ef010c6a546cf Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 13 Jun 2012 10:10:30 -0700 Subject: [PATCH] Update Github request closer script to v3 of API. Fixes bug #1012310 Github disabled v1 and v2 of their API permanently, forcing us to update the script that closes Github pull requests to v3 of the API. Update the script using the PyGithub lib. Change-Id: I90c9faacdb7a72a470b8ad6aaea674edd9b8329e --- .../files/scripts/close_pull_requests.py | 25 +++++++++++++------ modules/gerrit/manifests/init.pp | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/modules/gerrit/files/scripts/close_pull_requests.py b/modules/gerrit/files/scripts/close_pull_requests.py index 64160ed893..984bc5571f 100755 --- a/modules/gerrit/files/scripts/close_pull_requests.py +++ b/modules/gerrit/files/scripts/close_pull_requests.py @@ -25,9 +25,14 @@ # [github] # username = GITHUB_USERNAME -# api_token = GITHUB_API_TOKEN +# password = GITHUB_PASSWORD +# +# or +# +# [github] +# oauth_token = GITHUB_OAUTH_TOKEN -import github2.client +import github import os import ConfigParser import logging @@ -54,9 +59,11 @@ secure_config.read(GITHUB_SECURE_CONFIG) config = ConfigParser.ConfigParser() config.read(GITHUB_CONFIG) -github = github2.client.Github(requests_per_second=1.0, - username=secure_config.get("github", "username"), - api_token=secure_config.get("github", "api_token")) +if secure_config.has_option("github", "oauth_token"): + ghub = github.Github(secure_config.get("github", "oauth_token")) +else: + ghub = github.Github(secure_config.get("github", "username"), + secure_config.get("github", "password")) for section in config.sections(): # Each section looks like [project "openstack/project"] @@ -70,8 +77,10 @@ for section in config.sections(): continue # Close each pull request - pull_requests = github.pull_requests.list(project) + repo = ghub.get_user().get_repo(project) + pull_requests = repo.get_pulls("open") for req in pull_requests: vars = dict(project=project) - github.issues.comment(project, req.number, MESSAGE%vars) - github.issues.close(project, req.number) + issue = repo.get_issue(req.number) + issue.create_comment(MESSAGE % vars) + req.edit(state = "closed") diff --git a/modules/gerrit/manifests/init.pp b/modules/gerrit/manifests/init.pp index 6ec503fe49..c997eda815 100644 --- a/modules/gerrit/manifests/init.pp +++ b/modules/gerrit/manifests/init.pp @@ -124,7 +124,7 @@ class gerrit($virtual_hostname='', require => Package[python-dev] } - package { "github2": + package { "PyGithub": ensure => latest, # okay to use latest for pip provider => pip, require => Package[python-pip]