-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-repo-branches.php
74 lines (64 loc) · 3.11 KB
/
get-repo-branches.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
use T3docs\T3docsTools\Configuration;
use T3docs\T3docsTools\GitHub\GithubRepository;
use T3docs\T3docsTools\GitLab\GitLabRepository;
$loader = require 'vendor/autoload.php';
function usage()
{
$config = new Configuration();
$hosts = $config->getSortedFilteredHosts('all');
$users = $config->getSortedFilteredUsers('all', 'all');
print("Usage: php get-repo-branches.php [<type>] [<host>] [<user>] [<token>] [<force>]\n");
print("\n");
print("Arguments:\n");
print(" type: Consider all repositories or only those starting with \"TYPO3CMS-\" (all, docs). [default: \"docs\"]\n");
print(" host: Consider the repositories of this host (all, " . implode(', ', $hosts) . "), which has to be defined in the /config.yml or /config.local.yml. [default: \"github.com\"]\n");
print(" user: Consider the repositories of this user namespace (all, " . implode(', ', $users) . "), which has to be defined in the /config.yml or /config.local.yml. [default: \"github.com:typo3-documentation\"]\n");
print(" token: Fetch the repositories using this GitHub / GitLab API token to overcome rate limitations. [default: \"\"]\n");
print(" force: Allow user namespaces not configured in the /config.yml or /config.local.yml. Requires a specific user namespace, not the generic \"all\". [default: 0]\n");
exit(1);
}
if ($argc > 6) {
usage();
}
$type = $argv[1] ?? 'docs';
$host = $argv[2] ?? 'github.com';
$user = $argv[3] ?? 'github.com:typo3-documentation';
$token = $argv[4] ?? '';
$force = (bool)($argv[5] ?? 0);
$config = new Configuration();
if (!$force) {
$users = $config->getSortedFilteredUsers($host, $user);
} else {
$users = $config->getSortedFilteredUsers($host, $user, Configuration::CHECK_HOST_ONLY);
}
$repos = [];
foreach ($users as $userIdentifier) {
list($host, $user) = explode(':', $userIdentifier, 2);
if ($config->getTypeOfHost($host) === Configuration::HOST_TYPE_GITHUB) {
$gitRepository = new GithubRepository($host, $token);
$gitRepository->fetchRepos($user, $type);
$repos[$userIdentifier] = $gitRepository->getNames();
} elseif ($config->getTypeOfHost($host) === Configuration::HOST_TYPE_GITLAB) {
$gitRepository = new GitLabRepository($host, $token);
$gitRepository->fetchRepos($user, $type);
$repos[$userIdentifier] = $gitRepository->getNames();
}
}
foreach ($repos as $userIdentifier => $reposByUser) {
list($host, $user) = explode(':', $userIdentifier, 2);
foreach ($reposByUser as $repo) {
print("{$userIdentifier}:{$repo}\n");
$branches = [];
if ($config->getTypeOfHost($host) === Configuration::HOST_TYPE_GITHUB) {
$gitRepository = new GithubRepository($host, $token);
$branches = $gitRepository->fetchBranchNamesOfRepo($user, $repo);
} elseif ($config->getTypeOfHost($host) === Configuration::HOST_TYPE_GITLAB) {
$gitRepository = new GitLabRepository($host, $token);
$branches = $gitRepository->fetchBranchNamesOfRepo($user, $repo);
}
foreach ($branches as $branch) {
print(" $branch \n");
}
}
}