diff --git a/doc/gerrit.rst b/doc/gerrit.rst index 1f2ffc46..af2008dd 100644 --- a/doc/gerrit.rst +++ b/doc/gerrit.rst @@ -522,6 +522,15 @@ As a github openstack admin: * Visit the gerrit team admin page * Add the new repository to the gerrit team +Pull requests can not be disabled for a project in Github, so instead +we have a script that runs from cron to close any open pull requests +with instructions to use Gerrit. + +* Edit openstack/openstack-ci-puppet:site.pp + +and add the project to the list of github projects in the gerrit class +for the gerrit.openstack.org node. + Migrating a Project from bzr ============================ diff --git a/gerrit/close_pull_requests.py b/gerrit/close_pull_requests.py new file mode 100755 index 00000000..0355e90d --- /dev/null +++ b/gerrit/close_pull_requests.py @@ -0,0 +1,78 @@ +#! /usr/bin/env python +# Copyright (C) 2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Close Github pull requests with instructions to use Gerrit for +# code review. The list of projects is found in github.config +# and should look like: + +# [project "GITHUB_PROJECT"] +# close_pull = true + +# Github authentication information is read from github.secure.config, +# which should look like: + +# [github] +# username = GITHUB_USERNAME +# api_token = GITHUB_API_TOKEN + +import github2.client +import os +import StringIO +import ConfigParser +import logging +import re + +logging.basicConfig(level=logging.ERROR) + +GITHUB_CONFIG = os.environ.get('GITHUB_CONFIG', + '/home/gerrit2/github.config') +GITHUB_SECURE_CONFIG = os.environ.get('GITHUB_SECURE_CONFIG', + '/home/gerrit2/github.secure.config') + +MESSAGE = """Thank you for contributing to OpenStack! + +%(project)s uses Gerrit for code review. + +Please visit http://wiki.openstack.org/GerritWorkflow and follow the instructions there to upload your change to Gerrit. +""" + +PROJECT_RE = re.compile(r'^project\s+"(.*)"$') + +secure_config = ConfigParser.ConfigParser() +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")) + +for section in config.sections(): + # Each section looks like [project "openstack/project"] + m = PROJECT_RE.match(section) + if not m: continue + project = m.group(1) + + # Make sure we're supposed to close pull requests for this project: + if not (config.has_option(section, "close_pull") and + config.get(section, "close_pull").lower() == 'true'): + continue + + # Close each pull request + pull_requests = github.pull_requests.list(project) + for req in pull_requests: + vars = dict(project=project) + github.issues.comment(project, req.number, MESSAGE%vars) + github.issues.close(project, req.number) diff --git a/update_gerrit_users.py b/gerrit/update_gerrit_users.py old mode 100644 new mode 100755 similarity index 94% rename from update_gerrit_users.py rename to gerrit/update_gerrit_users.py index 3fdb4f41..3508e1f7 --- a/update_gerrit_users.py +++ b/gerrit/update_gerrit_users.py @@ -1,3 +1,20 @@ +#! /usr/bin/env python +# Copyright (C) 2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Synchronize Gerrit users from Launchpad. + import os import sys import uuid