Skip to content

Commit

Permalink
Allow multiple pull requests per job
Browse files Browse the repository at this point in the history
This way two interdependant pull requests can be tested together.

The only work around before was creating a branch on
buildout.coredev and tracking all the branches there.

This fixes:
#126
  • Loading branch information
gforcada committed Oct 30, 2015
1 parent 4ca4079 commit 4ba1250
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -714,50 +714,69 @@
parameters:
- text:
name: PULL_REQUEST_URL
description: 'URL of the github pull request, e.g. "https://github.com/plone/plone.app.discussion/pull/56".'
description: 'URLs of the github pull requests, e.g. "https://github.com/plone/plone.app.discussion/pull/56", when testing multiple pull requests put one on each line.'

scm:
- buildout-coredev:
branch: '{plone-version}'

builders:
- python: |
import fileinput
import json
import os
import re
import sys
import urllib2
pull_request_url = os.environ['PULL_REQUEST_URL']
pull_request_urls = os.environ['PULL_REQUEST_URL']
github_api_call = pull_request_url.replace('github.com', 'api.github.com/repos')
github_api_call = github_api_call.replace('/pull/', '/pulls/')
PKG_RE = r'^{{0}}\s.*'
SOURCE_RE = r'{{0}} = git git://github.com/{{1}}/{{0}}.git branch={{2}}'
response = urllib2.urlopen(github_api_call)
json_data = json.loads(response.read())
PKGS = []
COREDEV = 0
org, branch = json_data['head']['label'].split(':')
pkg = json_data['base']['repo']['name']
for i, pr in enumerate(pull_request_urls.split()):
github_api_call = pr.replace('github.com', 'api.github.com/repos')
github_api_call = github_api_call.replace('/pull/', '/pulls/')
response = urllib2.urlopen(github_api_call)
json_data = json.loads(response.read())
org, branch = json_data['head']['label'].split(':')
pkg = json_data['base']['repo']['name']
if pkg != 'buildout.coredev':
PKGS.append(pkg)
for line in fileinput.input('sources.cfg', inplace=True):
if line.find(pkg) != -1:
line = re.sub(
PKG_RE.format(pkg),
SOURCE_RE.format(pkg, org, branch),
line
)
sys.stdout.write(line)
else:
COREDEV = 1
with open('vars.properties', 'w') as f:
f.write(u'PULL_REQUEST_PACKAGE_NAME = {{0}}\n'.format(pkg))
f.write(u'PULL_REQUEST_FORK = {{0}}\n'.format(org))
f.write(u'PULL_REQUEST_BRANCH = {{0}}\n'.format(branch))
f.write(u'PKGS = {{0}}\n'.format(' '.join(PKGS)))
f.write(u'COREDEV = {{0}}\n'.format(COREDEV))
- inject:
properties-file: vars.properties

- shell: |
if [ "{plone-version}" = "4.3" ]; then
$PYTHON27 bootstrap.py -c jenkins.cfg
else
$PYTHON27 bootstrap.py --setuptools-version=18.2 -c jenkins.cfg
fi
if [ "$PULL_REQUEST_PACKAGE_NAME" != "buildout.coredev" ]; then
sed -ie "s/^$PULL_REQUEST_PACKAGE_NAME\s.*/$PULL_REQUEST_PACKAGE_NAME = git git:\/\/github.com\/$PULL_REQUEST_FORK\/$PULL_REQUEST_PACKAGE_NAME.git branch=$PULL_REQUEST_BRANCH/g" sources.cfg
bin/buildout -c jenkins.cfg install add-package-to-auto-checkout
bin/add-package-to-auto-checkout $PULL_REQUEST_PACKAGE_NAME
else
$PYTHON27 bootstrap.py --setuptools-version=18.2 -c jenkins.cfg

This comment has been minimized.

Copy link
@pbauer

pbauer Nov 5, 2015

Member

@gforcada This seems to break the pull-request-job for 4.3: See http://jenkins.plone.org/job/pull-request-4.3/154/console

This comment has been minimized.

Copy link
@gforcada

gforcada Nov 5, 2015

Author Member

@pbauer thanks for noticing and providing the fix!

if [ "$COREDEV" = "1" ]; then
# TODO(gforcada): allow to test remote branches (i.e. branches not in github.com/plone/buildout.coredev)
git checkout $PULL_REQUEST_BRANCH
else
bin/buildout -c jenkins.cfg install add-package-to-auto-checkout
for pkg in $PKGS; do
bin/add-package-to-auto-checkout $pkg
done
fi
bin/buildout -c jenkins.cfg
bin/alltests --xml --all
Expand Down Expand Up @@ -785,15 +804,15 @@
content-type: default
always: true
failure: false
subject: "Jenkins Pull Request Job [${{BUILD_STATUS}}]: ${{PULL_REQUEST_PACKAGE_NAME}} ${{PULL_REQUEST_BRANCH}}"
subject: "Jenkins Pull Request Job [${{BUILD_STATUS}}]: packages ${{PKGS}}"
body: |
Dear ${{BUILD_USER}},
the Jenkins pull request job you requested has finished:
${{BUILD_URL}}
Comment/merge the pull request:
Comment/merge the pull request(s):
${{PULL_REQUEST_URL}}
Expand Down

0 comments on commit 4ba1250

Please sign in to comment.