From 15daf9a9f29a5a01c2ec6e370679beec8acfd37f Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 29 Jul 2012 12:54:27 -0500 Subject: [PATCH] Add support for initial project creation. If replicate_local is set, this will ensure that /var/lib/git is created, and that projects listed in the projects.config have repos there. Additionally, it creates a new config file, projects.config which is a yaml file listing all of the projects and various operational semantics about them, such as whether or not they should have pull requests closed and whether or not they track any remotes. This replaces remotes.config and github.config. Moving forward, there is no reason to not have this script be able to do github api calls to create the github repo if it's not there, set the github project description, gerrit api calls to create the project in gerrit, and initial project permissions templates. Change-Id: I1ad803b0aa5f7386206d0c3f4cd858017242fe64 --- files/scripts/close_pull_requests.py | 33 +++++++++++----------------- manifests/init.pp | 8 +------ templates/github.config.erb | 7 ------ 3 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 templates/github.config.erb diff --git a/files/scripts/close_pull_requests.py b/files/scripts/close_pull_requests.py index 202d2eb..13f9e89 100755 --- a/files/scripts/close_pull_requests.py +++ b/files/scripts/close_pull_requests.py @@ -13,12 +13,12 @@ # 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: +# Github pull requests closer reads a project config file called projects.yaml +# It should look like: -# [project "GITHUB_PROJECT"] -# close_pull = true +# - project: PROJECT_NAME +# options: +# - close-pull # Github authentication information is read from github.secure.config, # which should look like: @@ -32,16 +32,16 @@ # [github] # oauth_token = GITHUB_OAUTH_TOKEN +import ConfigParser import github import os -import ConfigParser +import yaml import logging -import re logging.basicConfig(level=logging.ERROR) -GITHUB_CONFIG = os.environ.get('GITHUB_CONFIG', - '/home/gerrit2/github.config') +PROJECTS_YAML = os.environ.get('PROJECTS_YAML', + '/home/gerrit2/projects.yaml') GITHUB_SECURE_CONFIG = os.environ.get('GITHUB_SECURE_CONFIG', '/home/gerrit2/github.secure.config') @@ -52,12 +52,9 @@ MESSAGE = """Thank you for contributing to OpenStack! 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) +config = yaml.load(open(PROJECTS_YAML)) if secure_config.has_option("github", "oauth_token"): ghub = github.Github(secure_config.get("github", "oauth_token")) @@ -67,15 +64,11 @@ else: orgs = ghub.get_user().get_orgs() orgs_dict = dict(zip([o.login.lower() for o in orgs], orgs)) -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) +for section in config: + project = section['project'] # 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'): + if 'options' not in section or 'close-pull' not in section['options']: continue # Find the project's repo diff --git a/manifests/init.pp b/manifests/init.pp index d4bc325..24b0554 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -32,13 +32,7 @@ class github ( } file { '/etc/github/github.config': - owner => 'root', - group => 'root', - mode => 444, - ensure => 'present', - content => template('github/github.config.erb'), - replace => 'true', - require => File['/etc/github'], + ensure => absent } file { '/etc/github/github.secure.config': diff --git a/templates/github.config.erb b/templates/github.config.erb deleted file mode 100644 index 2945ae9..0000000 --- a/templates/github.config.erb +++ /dev/null @@ -1,7 +0,0 @@ -# This file is managed by puppet. -# https://github.com/openstack/openstack-ci-puppet - -<% projects.each do |project| -%> -[project "<%= project['name'] %>"] -close_pull = <%= project['close_pull'] %> -<% end -%>