From 0f3378ca28308eec4cc61d8e5170c4f40ad41699 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Feb 2011 04:45:54 -0500 Subject: [PATCH 1/5] [ticket/10044] Made setup_github_network.php runnable as a script PHPBB3-10044 --- git-tools/setup_github_network.php | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 git-tools/setup_github_network.php diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php old mode 100644 new mode 100755 index 08e99e2f32..80cc62df8a --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php Date: Tue, 15 Feb 2011 04:49:48 -0500 Subject: [PATCH 2/5] [ticket/10044] Error handling for remote requests in setup_github_network.php PHPBB3-10044 --- git-tools/setup_github_network.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 80cc62df8a..ae3d34f5fe 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -134,12 +134,21 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - return json_decode(file_get_contents("http://github.com/api/v2/json/$query")); + $contents = file_get_contents("http://github.com/api/v2/json/$query"); + if ($contents === false) + { + return false; + } + return json_decode($contents); } function get_contributors($username, $repository) { $request = api_request("repos/show/$username/$repository/contributors"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->contributors as $contributor) @@ -153,6 +162,10 @@ function get_contributors($username, $repository) function get_organisation_members($username) { $request = api_request("organizations/$username/public_members"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->users as $member) @@ -166,6 +179,10 @@ function get_organisation_members($username) function get_collaborators($username, $repository) { $request = api_request("repos/show/$username/$repository/collaborators"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->collaborators as $collaborator) @@ -179,6 +196,10 @@ function get_collaborators($username, $repository) function get_network($username, $repository) { $request = api_request("repos/show/$username/$repository/network"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->network as $network) From bf137b70051d00f6b0e6636ae08e5579c6f3739e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Feb 2011 05:11:21 -0500 Subject: [PATCH 3/5] [ticket/10044] Added -h to setup_github_network.php. PHPBB3-10044 --- git-tools/setup_github_network.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index ae3d34f5fe..9ada9e437a 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -31,14 +31,15 @@ function show_usage() echo " -r repository_name Overwrites the repository name (optional)\n"; echo " -m your_github_username Sets up ssh:// instead of git:// for pushable repositories (optional)\n"; echo " -d Outputs the commands instead of running them (optional)\n"; + echo " -h This help text\n"; exit(1); } // Handle arguments -$opts = getopt('s:u:r:m:d'); +$opts = getopt('s:u:r:m:dh'); -if (empty($opts)) +if (empty($opts) || isset($opts['h'])) { show_usage(); } From ed53cef0aaa2a23d4688c2429cc7961ad79ca496 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Feb 2011 05:13:48 -0500 Subject: [PATCH 4/5] [ticket/10044] Stop when failed to retrieve network/collaborators. PHPBB3-10044 --- git-tools/setup_github_network.php | 98 ++++++++++++++++-------------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 9ada9e437a..a3606575b2 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -50,58 +50,68 @@ $repository = get_arg($opts, 'r', 'phpbb3'); $developer = get_arg($opts, 'm', ''); $dry_run = !get_arg($opts, 'd', true); run(null, $dry_run); +exit(work($scope, $username, $repository, $developer)); -// Get some basic data -$network = get_network($username, $repository); -$collaborators = get_collaborators($username, $repository); - -switch ($scope) +function work($scope, $username, $repository, $developer) { - case 'collaborators': - $remotes = array_intersect_key($network, $collaborators); - break; + // Get some basic data + $network = get_network($username, $repository); + $collaborators = get_collaborators($username, $repository); - case 'organisation': - $remotes = array_intersect_key($network, get_organisation_members($username)); - break; + if ($network === false || $collaborators === false) + { + echo "Error: failed to retrieve network or collaborators\n"; + return 1; + } - case 'contributors': - $remotes = array_intersect_key($network, get_contributors($username, $repository)); - break; + switch ($scope) + { + case 'collaborators': + $remotes = array_intersect_key($network, $collaborators); + break; - case 'network': - $remotes = $network; - break; + case 'organisation': + $remotes = array_intersect_key($network, get_organisation_members($username)); + break; - default: - show_usage(); + case 'contributors': + $remotes = array_intersect_key($network, get_contributors($username, $repository)); + break; + + case 'network': + $remotes = $network; + break; + + default: + show_usage(); + } + + if (file_exists('.git')) + { + add_remote($username, $repository, isset($collaborators[$developer])); + } + else + { + clone_repository($username, $repository, isset($collaborators[$developer])); + } + + // Add private security repository for developers + if ($username == 'phpbb' && $repository == 'phpbb3' && isset($collaborators[$developer])) + { + run("git remote add $username-security " . get_repository_url($username, "$repository-security", true)); + } + + // Skip blessed repository. + unset($remotes[$username]); + + foreach ($remotes as $remote) + { + add_remote($remote['username'], $remote['repository'], $remote['username'] == $developer); + } + + run('git remote update'); } -if (file_exists('.git')) -{ - add_remote($username, $repository, isset($collaborators[$developer])); -} -else -{ - clone_repository($username, $repository, isset($collaborators[$developer])); -} - -// Add private security repository for developers -if ($username == 'phpbb' && $repository == 'phpbb3' && isset($collaborators[$developer])) -{ - run("git remote add $username-security " . get_repository_url($username, "$repository-security", true)); -} - -// Skip blessed repository. -unset($remotes[$username]); - -foreach ($remotes as $remote) -{ - add_remote($remote['username'], $remote['repository'], $remote['username'] == $developer); -} - -run('git remote update'); - function clone_repository($username, $repository, $pushable = false) { $url = get_repository_url($username, $repository, false); From 5af3cfe9cae4a59478bff2581f8484657a0d5bc9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 16 Feb 2011 21:13:35 -0500 Subject: [PATCH 5/5] [ticket/10044] Updated invocation documentation. PHPBB3-10044 --- git-tools/setup_github_network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index a3606575b2..e4e212eef6 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -15,7 +15,7 @@ function show_usage() echo "$filename adds repositories of a github network as remotes to a local git repository.\n"; echo "\n"; - echo "Usage: php $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; + echo "Usage: [php] $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; echo "\n"; echo "Scopes:\n";