Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit b892764

Browse files
committed
Create repository now uses populate_team_with_repos to assign new repo to each Github Team
Abstract Github access levels to the DRY helper class, and renamed a few commands and parameters
1 parent e16d109 commit b892764

5 files changed

Lines changed: 38 additions & 40 deletions

File tree

load-application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
$application->add( new Team51\Command\Plugin_List() );
3232
$application->add( new Team51\Command\Pressable_Generate_Token() );
3333
$application->add( new Team51\Command\Pressable_Grant_Access() );
34-
$application->add( new Team51\Command\Onboard_Collaborator() );
35-
$application->add( new Team51\Command\Github_Repos_To_Teams() );
34+
$application->add( new Team51\Command\Github_Team_Add_User() );
35+
$application->add( new Team51\Command\Github_Team_Add_Repos() );
3636

3737
$application->run();

src/commands/create-repository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Team51\Command;
44

55
use Team51\Helper\API_Helper;
6+
use Team51\Helper\DRY_Helper;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\ArrayInput;
89
use Symfony\Component\Console\Input\InputOption;
@@ -35,6 +36,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
3536
$filesystem = new Filesystem();
3637

3738
$api_helper = new API_Helper();
39+
$dry_helper = new DRY_Helper();
3840

3941
if ( empty( $input->getOption( 'repo-slug' ) ) ) {
4042
$output->writeln( '<error>You must pass a repository slug with --repo-slug.</error>' );
@@ -167,6 +169,14 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
167169
//exit;
168170
}
169171

172+
// Adding repo to all required teams
173+
// TODO: TEST
174+
$output->writeln( "<info>Adding '{$slug}' to the corresponding Github Teams.</info>" );
175+
$repo_names = array( $slug );
176+
$dry_helper->populate_team_with_repos( $repo_names, $dry_helper->GH_ACCESS_1['team_slug'], $dry_helper->GH_ACCESS_1['team_permission'] );
177+
$dry_helper->populate_team_with_repos( $repo_names, $dry_helper->GH_ACCESS_2['team_slug'], $dry_helper->GH_ACCESS_2['team_permission'] );
178+
$dry_helper->populate_team_with_repos( $repo_names, $dry_helper->GH_ACCESS_3['team_slug'], $dry_helper->GH_ACCESS_3['team_permission'] );
179+
170180
$ssh_url = $response->ssh_url;
171181
$html_url = $response->html_url;
172182

src/commands/github-repos-to-teams.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,11 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010

1111

12-
class Github_Repos_To_Teams extends Command {
13-
protected static $defaultName = 'github-repos-to-teams';
12+
class Github_Team_Add_Repos extends Command {
13+
protected static $defaultName = 'github-team-add-repos';
1414
private $api_helper;
1515
private $output;
1616

17-
private $ACCESS_1 = array(
18-
'team_slug' => 'triage',
19-
'team_permission' => 'triage',
20-
);
21-
private $ACCESS_2 = array(
22-
'team_slug' => 'deploy',
23-
'team_permission' => 'push',
24-
);
25-
private $ACCESS_3 = array(
26-
'team_slug' => 'admin',
27-
'team_permission' => 'admin',
28-
);
29-
3017
protected function configure() {
3118
$this
3219
->setDescription( 'Add all Repositories to all GitHub Teams in the organization, with the respective repo permission.' )
@@ -65,9 +52,9 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
6552
$output->writeln( "<comment>{$total_repos} repositories will be added to each of our Github Teams.</comment>" );
6653

6754
// Populate Teams with Repositories
68-
$this->dry_helper->populate_team_with_repos( $repo_names, $this->ACCESS_1['team_slug'], $this->ACCESS_1['team_permission'] );
69-
$this->dry_helper->populate_team_with_repos( $repo_names, $this->ACCESS_2['team_slug'], $this->ACCESS_2['team_permission'] );
70-
$this->dry_helper->populate_team_with_repos( $repo_names, $this->ACCESS_3['team_slug'], $this->ACCESS_3['team_permission'] );
55+
$this->dry_helper->populate_team_with_repos( $repo_names, $this->dry_helper->GH_ACCESS_1['team_slug'], $this->dry_helper->GH_ACCESS_1['team_permission'] );
56+
$this->dry_helper->populate_team_with_repos( $repo_names, $this->dry_helper->GH_ACCESS_2['team_slug'], $this->dry_helper->GH_ACCESS_2['team_permission'] );
57+
$this->dry_helper->populate_team_with_repos( $repo_names, $this->dry_helper->GH_ACCESS_3['team_slug'], $this->dry_helper->GH_ACCESS_3['team_permission'] );
7158

7259
$output->writeln( "<comment>All done.</comment>" );
7360
}
Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
1010

11-
class Onboard_Collaborator extends Command {
12-
protected static $defaultName = 'onboard-collaborator';
11+
class Github_Team_Add_User extends Command {
12+
protected static $defaultName = 'github-team-add-user';
1313
private $api_helper;
1414
private $output;
1515

@@ -22,29 +22,19 @@ protected function configure() {
2222
$this
2323
->setDescription( 'Adds collaborator to Github Team and Pressable sites. Collaborator can be either a11n or contractor' )
2424
->setHelp( 'This command allows you to bulk add a collaborator to all Pressable sites and a Github team.' )
25-
->addOption( 'email', null, InputOption::VALUE_REQUIRED, "Collaborator's email." )
26-
->addOption( 'github_username', null, InputOption::VALUE_REQUIRED, "Collaborator's Github username." )
27-
->addOption( 'github_team', null, InputOption::VALUE_REQUIRED, sprintf('Github team can be: %s, %s, or %s. Following this order, level 1 has less privileges than level 3', self::ACCESS_1, self::ACCESS_2, self::ACCESS_3) );
25+
->addOption( 'username', null, InputOption::VALUE_REQUIRED, "Collaborator's Github username." )
26+
->addOption( 'team', null, InputOption::VALUE_REQUIRED, sprintf('Github Team can be: %s, %s, or %s.', self::ACCESS_1, self::ACCESS_2, self::ACCESS_3) );
2827
}
2928

3029
protected function execute( InputInterface $input, OutputInterface $output ) {
3130
$this->api_helper = new API_Helper();
3231
$this->output = $output;
3332

34-
// $email = $input->getOption( 'email' );
35-
// if ( empty( $email ) ) {
36-
// $email = trim( readline( "Please provide the collaborator's email: " ) );
37-
// if ( empty( $email ) ) {
38-
// $output->writeln( "<error>Missing collaborator's email (eg: --email=user@domain.com).</error>" );
39-
// exit;
40-
// }
41-
// }
42-
4333
$github_user = $input->getOption( 'github_username' );
4434
if ( empty( $github_user ) ) {
45-
$github_user = trim( readline( "Please provide the collaborator's Github username : " ) );
35+
$github_user = trim( readline( "Please provide the collaborator's Github username: " ) );
4636
if ( empty( $github_user ) ) {
47-
$github_user->writeln( "<error>Missing collaborator's Github username (eg: --github=their_username).</error>" );
37+
$github_user->writeln( "<error>Missing collaborator's Github username (eg: --username=their_username).</error>" );
4838
exit;
4939
}
5040
}
@@ -53,17 +43,14 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
5343
if ( empty( $github_team ) || ! in_array($github_team, [self::ACCESS_1, self::ACCESS_2, self::ACCESS_3]) ) {
5444
$github_team = trim( readline( sprintf("Please provide the collaborator's Github team. Values can be: %s, %s, or %s: ", self::ACCESS_1, self::ACCESS_2, self::ACCESS_3) ) );
5545
if ( empty( $github_team ) || ! in_array($github_team, [self::ACCESS_1, self::ACCESS_2, self::ACCESS_3]) ) {
56-
$output->writeln( '<error>Missing collaborator github_team (eg: --github_team='.self::ACCESS_1.').</error>' );
46+
$output->writeln( '<error>Missing collaborator github_team (eg: --team='.self::ACCESS_1.').</error>' );
5747
exit;
5848
}
5949
}
6050

6151
// Start process
6252
$this->onboard_github( $github_user, $github_team );
6353

64-
// TODO: onboard_pressable()
65-
66-
6754
$output->writeln( '<info>All done!<info>' );
6855
}
6956

src/helpers/dry-helper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
class DRY_Helper {
66
private $api_helper;
77

8+
// Github Access Levels
9+
public $GH_ACCESS_1 = array(
10+
'team_slug' => 'triage',
11+
'team_permission' => 'triage',
12+
);
13+
public $GH_ACCESS_2 = array(
14+
'team_slug' => 'deploy',
15+
'team_permission' => 'push',
16+
);
17+
public $GH_ACCESS_3 = array(
18+
'team_slug' => 'admin',
19+
'team_permission' => 'admin',
20+
);
21+
822
function __construct() {
923
$this->api_helper = new API_Helper();
1024
}

0 commit comments

Comments
 (0)