aboutsummaryrefslogtreecommitdiffstats
path: root/git-tools/merge.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-07-11 00:29:45 +0200
committerAndreas Fischer <bantu@phpbb.com>2011-07-11 00:29:45 +0200
commitc8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff (patch)
treeb7e507311afa3db9e372f9d5b8b01455dbd50841 /git-tools/merge.php
parent7f21a5f46156660d7ea6a4bdb59166ac553e2be8 (diff)
parente6572b766f7fd5f8547b28fd52d25e4a96cfc2cd (diff)
downloadforums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.gz
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.bz2
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.xz
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.zip
Merge branch 'prep-release-3.0.9'
* prep-release-3.0.9: (359 commits) [prep-release-3.0.9] Bumping version number for 3.0.9 final. [prep-release-3.0.9] Update Changelog for 3.0.9-RC4 release. [prep-release-3.0.9] Decreasing version for an RC4 release. [ticket/9859] Changing all phpBB footers to match the new credit line [ticket/9859] New footer copyright line with registered symbol [ticket/10250] The site_logo hash is different depending on imageset & language [ticket/10250] Destroy cached md5 hash of site_logo on refreshing an imageset [ticket/10250] Overwrite the site_logo width&height when the phpbb logo is used [ticket/10247] Remove attempt_id as primary key from database_update.php [ticket/10250] Added the new phpBB Logo with the Registered Trademark Symbol [ticket/10247] Use COUNT(*) instead of COUNT(attempt_id) [prep-release-3.0.9] Update Changelog for 3.0.9 release. [prep-release-3.0.9] Bumping version number for the final 3.0.9 release. [ticket/10247] Removing attempt_id column from the 3.0.8 to 3.0.9-RC1 updater. [ticket/10247] Add a db_tools test for the removal of a primary key column. [ticket/10247] Add empty data section to database update for RC4 [ticket/10247] Remove unecessary attempt_id primary key column [prep-release-3.0.9] Bump database version to RC3 too. [prep-release-3.0.9] Update Changelog for 3.0.9-RC3 release. [prep-release-3.0.9] Bumping version number for 3.0.9-RC3. ...
Diffstat (limited to 'git-tools/merge.php')
-rwxr-xr-xgit-tools/merge.php175
1 files changed, 175 insertions, 0 deletions
diff --git a/git-tools/merge.php b/git-tools/merge.php
new file mode 100755
index 0000000000..cbd84b896f
--- /dev/null
+++ b/git-tools/merge.php
@@ -0,0 +1,175 @@
+#!/usr/bin/env php
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+function show_usage()
+{
+ $filename = basename(__FILE__);
+
+ echo "$filename merges a github pull request.\n";
+ echo "\n";
+
+ echo "Usage: [php] $filename -p pull_request_id [OPTIONS]\n";
+ echo "\n";
+
+ echo "Options:\n";
+ echo " -p pull_request_id The pull request id to be merged (mandatory)\n";
+ echo " -r remote Remote of upstream, defaults to 'upstream' (optional)\n";
+ echo " -d Outputs the commands instead of running them (optional)\n";
+ echo " -h This help text\n";
+
+ exit(2);
+}
+
+// Handle arguments
+$opts = getopt('p:r:dh');
+
+if (empty($opts) || isset($opts['h']))
+{
+ show_usage();
+}
+
+$pull_id = get_arg($opts, 'p', '');
+$remote = get_arg($opts, 'r', 'upstream');
+$dry_run = !get_arg($opts, 'd', true);
+
+try
+{
+ exit(work($pull_id, $remote));
+}
+catch (RuntimeException $e)
+{
+ echo $e->getMessage();
+ exit($e->getCode());
+}
+
+function work($pull_id, $remote)
+{
+ // Get some basic data
+ $pull = get_pull('phpbb', 'phpbb3', $pull_id);
+
+ if (!$pull_id)
+ {
+ show_usage();
+ }
+
+ if ($pull['state'] != 'open')
+ {
+ throw new RuntimeException(sprintf("Error: pull request is closed\n",
+ $target_branch), 5);
+ }
+
+ $pull_user = $pull['head'][0];
+ $pull_branch = $pull['head'][1];
+ $target_branch = $pull['base'][1];
+
+ switch ($target_branch)
+ {
+ case 'develop-olympus':
+ run("git checkout develop-olympus");
+ run("git pull $remote develop-olympus");
+
+ add_remote($pull_user, 'phpbb3');
+ run("git fetch $pull_user");
+ run("git merge --no-ff $pull_user/$pull_branch");
+ run("phpunit");
+
+ run("git checkout develop");
+ run("git pull $remote develop");
+ run("git merge --no-ff develop-olympus");
+ run("phpunit");
+ break;
+
+ case 'develop':
+ run("git checkout develop");
+ run("git pull $remote develop");
+
+ add_remote($pull_user, 'phpbb3');
+ run("git fetch $pull_user");
+ run("git merge --no-ff $pull_user/$pull_branch");
+ run("phpunit");
+ break;
+
+ default:
+ throw new RuntimeException(sprintf("Error: pull request target branch '%s' is not a main branch\n",
+ $target_branch), 5);
+ break;
+ }
+}
+
+function add_remote($username, $repository, $pushable = false)
+{
+ $url = get_repository_url($username, $repository, false);
+ run("git remote add $username $url", true);
+
+ if ($pushable)
+ {
+ $ssh_url = get_repository_url($username, $repository, true);
+ run("git remote set-url --push $username $ssh_url");
+ }
+}
+
+function get_repository_url($username, $repository, $ssh = false)
+{
+ $url_base = ($ssh) ? 'git@github.com:' : 'git://github.com/';
+
+ return $url_base . $username . '/' . $repository . '.git';
+}
+
+function api_request($query)
+{
+ $contents = file_get_contents("http://github.com/api/v2/json/$query");
+
+ if ($contents === false)
+ {
+ throw new RuntimeException("Error: failed to retrieve pull request data\n", 4);
+ }
+
+ return json_decode($contents);
+}
+
+function get_pull($username, $repository, $pull_id)
+{
+ $request = api_request("pulls/$username/$repository/$pull_id");
+
+ $pull = $request->pull;
+
+ $pull_data = array(
+ 'base' => array($pull->base->user->login, $pull->base->ref),
+ 'head' => array($pull->head->user->login, $pull->head->ref),
+ 'state' => $pull->state,
+ );
+
+ return $pull_data;
+}
+
+function get_arg($array, $index, $default)
+{
+ return isset($array[$index]) ? $array[$index] : $default;
+}
+
+function run($cmd, $ignore_fail = false)
+{
+ global $dry_run;
+
+ if (!empty($dry_run))
+ {
+ echo "$cmd\n";
+ }
+ else
+ {
+ passthru(escapeshellcmd($cmd), $status);
+
+ if ($status != 0 && !$ignore_fail)
+ {
+ throw new RuntimeException(sprintf("Error: command '%s' failed with status %s'\n",
+ $cmd, $status), 6);
+ }
+ }
+}