Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Load GitHub Credentials from secrets_tool
Browse files Browse the repository at this point in the history
Reviewed By: jamesgpearce

Differential Revision: D3380340

fbshipit-source-id: 660deb4edc5b6cf739d11761fab84088b9af9c6a
  • Loading branch information
sdwilsh authored and Facebook Github Bot 2 committed Jun 7, 2016
1 parent 491b1a4 commit 2dfb8d4
Showing 2 changed files with 80 additions and 10 deletions.
62 changes: 52 additions & 10 deletions fb-examples/tests/FBGitHubUtilsTest.php-example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?hh
<?hh // strict
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
@@ -11,28 +11,70 @@ namespace Facebook\ShipIt;

final class FBGitHubUtilsTest extends BaseTest {
public function exampleProjectCredentials(
): array<(string, string, string, string)> {
): array<(FBGitHubUtils::TAllCredentials, string, string, string, string)> {
return [
tuple('facebook', 'hhvm', '/^hhvm-bot$/', '/^[email protected]$/'),
tuple(
array(
'FACEBOOK_HHVM' => array(
'hhvm-bot' => shape(
'access_token' => 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
),
),
'FACEBOOK_DEFAULT' => array(
'facebook-github-bot' => shape(
'access_token' => 'beefdeadbeefdeadbeefdeadbeefdeadbeefdead',
),
),
),
'facebook',
'hhvm',
'/^hhvm-bot$/',
'/^[email protected]$/',
),
tuple(
array(
'FACEBOOK_DEFAULT' => array(
'facebook-github-bot' => shape(
'access_token' => 'beefdeadbeefdeadbeefdeadbeefdeadbeefdead',
),
),
),
'facebook',
'not-a-real-project',
'/^facebook-github-bot-\d+$/',
'/^facebook-github-bot-*\d*$/',
'/^facebook-github-bot.*@fb.com$/',
),
];
}

static private function getCredentialsForProjectFrom(
FBGitHubUtils::TAllCredentials $credentials,
string $organization,
string $project,
?ShipItGitHubCredentialOverrides $overrides = null,
): ShipItGitHubCredentials {
return self::invoke_static_bypass_visibility(
FBGitHubUtils::class,
'getCredentialsForProjectFrom',
$credentials,
$organization,
$project,
$overrides,
);
}

/**
* @dataProvider exampleProjectCredentials
*/
public function testPerProjectCredentials(
FBGitHubUtils::TAllCredentials $credentials,
string $organization,
string $project,
string $user_regexp,
string $email_regexp,
): void {
$credentials = FBGitHubUtils::getCredentialsForProject(
$credentials = self::getCredentialsForProjectFrom(
$credentials,
$organization,
$project,
);
@@ -90,12 +132,12 @@ final class FBGitHubUtilsTest extends BaseTest {
* @dataProvider exampleOverrides
*/
public function testOverrides(
ShipItGitHubCredentialOverrides $override
ShipItGitHubCredentialOverrides $override,
): void {
$projects = $this->exampleProjectCredentials();
$credentials = FBGitHubUtils::getCredentialsForProject(
$projects[0][0],
$projects[0][1],
$credentials = self::getCredentialsForProjectFrom(
$this->exampleProjectCredentials()[1][0],
'facebook',
'some-project',
$override,
);
if ($override['name'] !== null) {
28 changes: 28 additions & 0 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
@@ -31,4 +31,32 @@ protected function execSteps(
);
}
}

static protected function invoke_static_bypass_visibility<T>(
classname<T> $classname,
string $method,
...$args
) {
invariant(
method_exists($classname, $method),
'Method "%s" does not exists on "%s"!',
$method,
$classname,
);
$rm = new \ReflectionMethod($classname, $method);
invariant(
$rm->isStatic(),
'"%s" is not a static method on "%s"!',
$method,
$classname,
);
invariant(
null !== $rm->getAttribute('TestsBypassVisibility'),
'"%s" is not annotated with "TestsBypassVisibility" on "%s"',
$method,
$classname,
);
$rm->setAccessible(true);
return $rm->invokeArgs(null, $args);
}
}

0 comments on commit 2dfb8d4

Please sign in to comment.