Skip to content

Commit

Permalink
SDK-4907: Assign integration reviewer (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavStrelchenko authored Dec 18, 2023
1 parent dea9856 commit 93426f9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ REPOSITORY_NAME=

### for one release group
# RELEASE_GROUP_ID=
# PULL_REQUEST_REVIEWERS=
# SOFT_THRESHOLD_MAJOR=100
# PACKAGE_UPGRADE_ONLY=false
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ export EVALUATOR_ENABLED=true
export RELEASE_GROUP_ID=123
```

## Specify the pull request reviewers
* Specify the GitHub user login to add as reviewers to the pull request
```bash
export PULL_REQUEST_REVIEWERS=<login_1,login_two,...>
```

## Installation
For Spryker SDK installation instructions, see [Spryker SDK](https://github.com/spryker-sdk/sdk#installation)
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ public function getReportSendAuthToken(): string;
* @return int
*/
public function getManifestsRatingThreshold(): int;

/**
* Specification:
* - Defines
*
* @return array<string>
*/
public function getPullRequestReviewers(): array;
}
10 changes: 10 additions & 0 deletions src/Upgrade/Infrastructure/Configuration/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,14 @@ public function getManifestsRatingThreshold(): int
{
return (int)getenv('MANIFESTS_RATING_THRESHOLD') ?: static::DEFAULT_MANIFESTS_RATING_THRESHOLD;
}

/**
* {@inheritDoc}
*
* @return array<string>
*/
public function getPullRequestReviewers(): array
{
return getenv('PULL_REQUEST_REVIEWERS') ? explode(',', getenv('PULL_REQUEST_REVIEWERS')) : [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class GitHubSourceCodeProvider implements SourceCodeProviderInterface
*/
protected const HTML_URL_KEY = 'html_url';

/**
* @var string
*/
protected const NUMBER_KEY = 'number';

/**
* @var \Upgrade\Infrastructure\Configuration\ConfigurationProvider
*/
Expand Down Expand Up @@ -98,10 +103,13 @@ public function createPullRequest(StepsResponseDto $stepsExecutionDto, PullReque
if (!$stepsExecutionDto->getIsSuccessful()) {
return $stepsExecutionDto;
}
$organizationName = $this->configurationProvider->getOrganizationName();
$repositoryName = $this->configurationProvider->getRepositoryName();
$prClient = $this->gitHubClientFactory->getClient()->pr();

$response = $this->gitHubClientFactory->getClient()->pr()->create(
$this->configurationProvider->getOrganizationName(),
$this->configurationProvider->getRepositoryName(),
$response = $prClient->create(
$organizationName,
$repositoryName,
[
'base' => $pullRequestDto->getTargetBranch(),
'head' => $pullRequestDto->getSourceBranch(),
Expand All @@ -117,6 +125,11 @@ public function createPullRequest(StepsResponseDto $stepsExecutionDto, PullReque
);
}

$reviewers = $this->configurationProvider->getPullRequestReviewers();
if ($reviewers) {
$prClient->reviewRequests()->create($organizationName, $repositoryName, $response[static::NUMBER_KEY], $reviewers);
}

return $stepsExecutionDto;
} catch (RuntimeException $runtimeException) {
return $stepsExecutionDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace UpgradeTest\Infrastructure\VersionControlSystem\SourceCodeProvider\GitHub;

use Github\Api\PullRequest;
use Github\Api\PullRequest\ReviewRequest;
use GitHub\Client as GitHubClient;
use PHPUnit\Framework\TestCase;
use RuntimeException;
Expand All @@ -31,11 +32,11 @@ public function createPullRequestDataProvider(): array
{
return [
// Invalid credentials
['', '', '', 'Please check defined values of environment variables: ACCESS_TOKEN, ORGANIZATION_NAME and REPOSITORY_NAME.', false],
['access_token', '', '', 'Please check defined values of environment variables: ACCESS_TOKEN, ORGANIZATION_NAME and REPOSITORY_NAME.', false],
['access_token', 'org_name', '', 'Please check defined values of environment variables: ACCESS_TOKEN, ORGANIZATION_NAME and REPOSITORY_NAME.', false],
['access_token', 'org_name', 'repo_name', 'some error', true],
['access_token', 'org_name', 'repo_name', '', false],
['', '', '', [], 'Please check defined values of environment variables: ACCESS_TOKEN, ORGANIZATION_NAME and REPOSITORY_NAME.', false],
['access_token', '', '', [], 'Please check defined values of environment variables: ACCESS_TOKEN, ORGANIZATION_NAME and REPOSITORY_NAME.', false],
['access_token', 'org_name', '', [], 'Please check defined values of environment variables: ACCESS_TOKEN, ORGANIZATION_NAME and REPOSITORY_NAME.', false],
['access_token', 'org_name', 'repo_name', [], 'some error', true],
['access_token', 'org_name', 'repo_name', ['github_user', 'github_user2'], '', false],
];
}

Expand All @@ -45,6 +46,7 @@ public function createPullRequestDataProvider(): array
* @param string $accessToken
* @param string $orgName
* @param string $repoName
* @param array $reviewers
* @param string $expectedError
* @param bool $produceException
*
Expand All @@ -54,11 +56,20 @@ public function testCreatePullRequest(
string $accessToken,
string $orgName,
string $repoName,
array $reviewers,
string $expectedError,
bool $produceException
): void {
$prMock = $this->createMock(PullRequest::class);
$prMock->method('create')->willReturn(['html_url' => 'some_url']);
$prMock->method('create')->willReturn(['html_url' => 'some_url', 'number' => 123]);

if ($reviewers) {
$reviewMock = $this->createMock(ReviewRequest::class);
$reviewMock->expects($this->once())
->method('create')
->with($orgName, $repoName, 123, $reviewers);
$prMock->method('reviewRequests')->willReturn($reviewMock);
}

// Create a mock for the GitHub client and its methods used in the createPullRequest method
$gitHubClientMock = $this->createGitHubClientMock($produceException ? null : $prMock);
Expand All @@ -78,6 +89,7 @@ public function testCreatePullRequest(
$configurationProviderMock->method('getAccessToken')->willReturn($accessToken);
$configurationProviderMock->method('getOrganizationName')->willReturn($orgName);
$configurationProviderMock->method('getRepositoryName')->willReturn($repoName);
$configurationProviderMock->method('getPullRequestReviewers')->willReturn($reviewers);

// Create mock DTOs
$stepsExecutionDto = new StepsResponseDto();
Expand Down

0 comments on commit 93426f9

Please sign in to comment.