mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-07 08:05:25 +02:00
Merge branch 'develop-olympus' into develop
* develop-olympus: [ticket/10044] Updated invocation documentation. [ticket/10044] Stop when failed to retrieve network/collaborators. [ticket/10044] Added -h to setup_github_network.php. [ticket/10044] Error handling for remote requests in setup_github_network.php [ticket/10044] Made setup_github_network.php runnable as a script
This commit is contained in:
commit
9c268a21dd
129
git-tools/setup_github_network.php
Normal file → Executable file
129
git-tools/setup_github_network.php
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -14,7 +15,7 @@ function show_usage()
|
|||||||
echo "$filename adds repositories of a github network as remotes to a local git repository.\n";
|
echo "$filename adds repositories of a github network as remotes to a local git repository.\n";
|
||||||
echo "\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 "\n";
|
||||||
|
|
||||||
echo "Scopes:\n";
|
echo "Scopes:\n";
|
||||||
@ -30,14 +31,15 @@ function show_usage()
|
|||||||
echo " -r repository_name Overwrites the repository name (optional)\n";
|
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 " -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 " -d Outputs the commands instead of running them (optional)\n";
|
||||||
|
echo " -h This help text\n";
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle arguments
|
// 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();
|
show_usage();
|
||||||
}
|
}
|
||||||
@ -48,58 +50,68 @@ $repository = get_arg($opts, 'r', 'phpbb3');
|
|||||||
$developer = get_arg($opts, 'm', '');
|
$developer = get_arg($opts, 'm', '');
|
||||||
$dry_run = !get_arg($opts, 'd', true);
|
$dry_run = !get_arg($opts, 'd', true);
|
||||||
run(null, $dry_run);
|
run(null, $dry_run);
|
||||||
|
exit(work($scope, $username, $repository, $developer));
|
||||||
|
|
||||||
// Get some basic data
|
function work($scope, $username, $repository, $developer)
|
||||||
$network = get_network($username, $repository);
|
|
||||||
$collaborators = get_collaborators($username, $repository);
|
|
||||||
|
|
||||||
switch ($scope)
|
|
||||||
{
|
{
|
||||||
case 'collaborators':
|
// Get some basic data
|
||||||
$remotes = array_intersect_key($network, $collaborators);
|
$network = get_network($username, $repository);
|
||||||
break;
|
$collaborators = get_collaborators($username, $repository);
|
||||||
|
|
||||||
case 'organisation':
|
if ($network === false || $collaborators === false)
|
||||||
$remotes = array_intersect_key($network, get_organisation_members($username));
|
{
|
||||||
break;
|
echo "Error: failed to retrieve network or collaborators\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
case 'contributors':
|
switch ($scope)
|
||||||
$remotes = array_intersect_key($network, get_contributors($username, $repository));
|
{
|
||||||
break;
|
case 'collaborators':
|
||||||
|
$remotes = array_intersect_key($network, $collaborators);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'network':
|
case 'organisation':
|
||||||
$remotes = $network;
|
$remotes = array_intersect_key($network, get_organisation_members($username));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case 'contributors':
|
||||||
show_usage();
|
$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)
|
function clone_repository($username, $repository, $pushable = false)
|
||||||
{
|
{
|
||||||
$url = get_repository_url($username, $repository, false);
|
$url = get_repository_url($username, $repository, false);
|
||||||
@ -133,12 +145,21 @@ function get_repository_url($username, $repository, $ssh = false)
|
|||||||
|
|
||||||
function api_request($query)
|
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)
|
function get_contributors($username, $repository)
|
||||||
{
|
{
|
||||||
$request = api_request("repos/show/$username/$repository/contributors");
|
$request = api_request("repos/show/$username/$repository/contributors");
|
||||||
|
if ($request === false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$usernames = array();
|
$usernames = array();
|
||||||
foreach ($request->contributors as $contributor)
|
foreach ($request->contributors as $contributor)
|
||||||
@ -152,6 +173,10 @@ function get_contributors($username, $repository)
|
|||||||
function get_organisation_members($username)
|
function get_organisation_members($username)
|
||||||
{
|
{
|
||||||
$request = api_request("organizations/$username/public_members");
|
$request = api_request("organizations/$username/public_members");
|
||||||
|
if ($request === false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$usernames = array();
|
$usernames = array();
|
||||||
foreach ($request->users as $member)
|
foreach ($request->users as $member)
|
||||||
@ -165,6 +190,10 @@ function get_organisation_members($username)
|
|||||||
function get_collaborators($username, $repository)
|
function get_collaborators($username, $repository)
|
||||||
{
|
{
|
||||||
$request = api_request("repos/show/$username/$repository/collaborators");
|
$request = api_request("repos/show/$username/$repository/collaborators");
|
||||||
|
if ($request === false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$usernames = array();
|
$usernames = array();
|
||||||
foreach ($request->collaborators as $collaborator)
|
foreach ($request->collaborators as $collaborator)
|
||||||
@ -178,6 +207,10 @@ function get_collaborators($username, $repository)
|
|||||||
function get_network($username, $repository)
|
function get_network($username, $repository)
|
||||||
{
|
{
|
||||||
$request = api_request("repos/show/$username/$repository/network");
|
$request = api_request("repos/show/$username/$repository/network");
|
||||||
|
if ($request === false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$usernames = array();
|
$usernames = array();
|
||||||
foreach ($request->network as $network)
|
foreach ($request->network as $network)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user