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
This commit is contained in:
Monty Taylor 2012-07-29 12:54:27 -05:00 committed by Gerrit Code Review
parent 413161fd48
commit 15daf9a9f2
3 changed files with 14 additions and 34 deletions

View File

@ -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

View File

@ -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':

View File

@ -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 -%>