This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load GitHub Credentials from
secrets_tool
Reviewed By: jamesgpearce Differential Revision: D3380340 fbshipit-source-id: 660deb4edc5b6cf739d11761fab84088b9af9c6a
- Loading branch information
Showing
2 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters