Skip to content

Commit

Permalink
Assign issue to repository contributors in private repositories (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
guibranco authored Feb 18, 2024
1 parent 5073b24 commit 8c56ce8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 15 additions & 1 deletion Src/issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ function handleIssue($issue)

$metadata = array(
"token" => $token,
"repoUrl" => "repos/" . $issue->RepositoryOwner . "/" . $issue->RepositoryName,
"collaboratorsUrl" => "repos/" . $issue->RepositoryOwner . "/" . $issue->RepositoryName . "/collaborators",
"issuesUrl" => "repos/" . $issue->RepositoryOwner . "/" . $issue->RepositoryName . "/issues/" . $issue->Number,
);

$issueResponse = requestGitHub($metadata["token"], $metadata["issuesUrl"]);
$issueUpdated = json_decode($issueResponse["body"]);

echo "Issue " . $issueUpdated->number . " - " . trim($issueUpdated->title) . " is " . $issueUpdated->state . "\n";
if ($issueUpdated->assignee != null) {
return;
}
$repositoryResponse = requestGitHub($metadata["token"], $metadata["repoUrl"]);
$repository = json_decode($repositoryResponse["body"]);
if (!$repository->private) {
return;
}
$collaboratorsResponse = requestGitHub($metadata["token"], $metadata["collaboratorsUrl"]);
$collaborators = json_decode($collaboratorsResponse["body"]);
$collaboratorsLogins = array_column($collaborators, "login");
$body = array("assignees" => $collaboratorsLogins);
requestGitHub($metadata["token"], $metadata["assigneesUrl"], $body);
}

function main()
Expand Down
4 changes: 1 addition & 3 deletions Src/pullRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ function handlePullRequest($pullRequest)

$collaboratorsResponse = requestGitHub($metadata["token"], $metadata["collaboratorsUrl"]);
$collaborators = json_decode($collaboratorsResponse["body"]);
$collaboratorsLogins = array_map(function ($collaborator) {
return $collaborator->login;
}, $collaborators);
$collaboratorsLogins = array_column($collaborators, "login");

$botReviewed = false;
$invokerReviewed = false;
Expand Down

0 comments on commit 8c56ce8

Please sign in to comment.