Skip to content

Commit 2f5f073

Browse files
committed
Added comments for each step to the advanced examples
1 parent 6f347dd commit 2f5f073

2 files changed

+23
-1
lines changed

examples/advanced-add-topic-php-to-all-repositories-that-start-their-name-with-php.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,26 @@
1212
$loop = Factory::create();
1313
$client = AsyncClient::create($loop, require 'resolve_token.php');
1414

15-
unwrapObservableFromPromise($client->user($argv[1])->then(function (UserInterface $user) use ($argv) {
15+
// Fetch the user/org given as first argument to this script
16+
unwrapObservableFromPromise($githubClient->user($argv[1])->then(function (UserInterface $user) use ($argv) {
1617
resource_pretty_print($user);
1718

19+
// Get all repositories for the given user
1820
return $user->repositories();
1921
}))->filter(function (Repository $repository) {
22+
// Filter out forks
2023
return !$repository->fork();
2124
})->filter(function (Repository $repository) {
25+
// Filter out repositories with nothing in them
2226
return $repository->size() > 0;
2327
})->filter(function (Repository $repository) {
28+
// Filter out all repositories that start their name with php
2429
return substr($repository->name(), 0, 3) === 'php';
2530
})->filter(function (Repository $repository) {
31+
// Be sure the repository doesn't have PHP in it's topics already
2632
return !in_array('php', $repository->topics(), true);
2733
})->subscribe(function (Repository $repository) {
34+
// Add php to the list of topics and update (replace) the topics
2835
$topics = $repository->topics();
2936
$topics[] = 'php';
3037

examples/advanced-enable-travis-for-non-forks-and-files-with-a-travis-yml.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,32 @@
5555
],
5656
]);
5757

58+
// Fetch the user/org given as first argument to this script
5859
unwrapObservableFromPromise($githubClient->user($argv[1])->then(function (UserInterface $user) use ($argv) {
5960
resource_pretty_print($user);
6061

62+
// Get all repositories for the given user
6163
return $user->repositories();
6264
}))->filter(function (Repository $repository) {
65+
// Filter out forks
6366
return !$repository->fork();
6467
})->filter(function (Repository $repository) {
68+
// Filter out repositories with nothing in them
6569
return $repository->size() > 0;
6670
})->filter(function (Repository $repository) {
71+
// Only check repositories that start with reactphp-http
72+
// This is optional and you can remove this to check all repositories
73+
// BUT that takes a lot of calls to check and time due to throttling
6774
return strpos($repository->name(), 'reactphp-http') === 0;
6875
})->flatMap(function (Repository $repository) {
76+
// Check if the repository contains a .travis.yml
6977
return Observable::fromPromise(new React\Promise\Promise(function ($resolve, $reject) use ($repository) {
7078
$hasTravisYml = false;
7179
$repository->contents()->filter(function ($node) {
80+
// Only let through files
7281
return $node instanceof FileInterface;
7382
})->filter(function (File $file) {
83+
// Only let the .travis.yml file through
7484
return $file->name() === '.travis.yml';
7585
})->subscribe(function () use (&$hasTravisYml) {
7686
$hasTravisYml = true;
@@ -84,19 +94,24 @@
8494
})
8595
->mapTo($repository);
8696
})->flatMap(function (Repository $repository) {
97+
// Get Travis repository for the Github repository
8798
return Observable::fromPromise($repository->travisRepository());
8899
})->flatMap(function (TravisRepository $repository) {
100+
// Check if the repository on Travis is active
101+
// We're only interested in inactive repositories
89102
return Observable::fromPromise($repository->isActive())
90103
->filter(function ($isActive) {
91104
return !$isActive;
92105
})
93106
->mapTo($repository);
94107
})->subscribe(function (TravisRepository $repository) {
108+
// Activate repository on Travis
95109
$repository->enable()->done(function (TravisRepository $repository) {
96110
resource_pretty_print($repository);
97111
}, 'display_throwable');
98112
}, 'display_throwable');
99113

100114
$loop->run();
101115

116+
// Display Github API token status
102117
displayState($githubClient->getRateLimitState());

0 commit comments

Comments
 (0)