Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions inc/Abilities/GitHubAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -2219,11 +2219,6 @@ public static function commentOnIssue( array $input ): array|\WP_Error {
* @return true|\WP_Error True when a comment may be posted, or an error explaining why not.
*/
private static function checkIssueAutomationCommentTurn( string $repo, int $issue_number, string $pat ): true|\WP_Error {
$actor = self::getAuthenticatedGitHubLogin($pat);
if ( is_wp_error($actor) ) {
return $actor;
}

$issue = self::apiGet(sprintf('%s/repos/%s/issues/%d', self::API_BASE, $repo, $issue_number), array(), $pat);
if ( is_wp_error($issue) ) {
return $issue;
Expand All @@ -2234,6 +2229,11 @@ private static function checkIssueAutomationCommentTurn( string $repo, int $issu
return true;
}

$actor = self::getAuthenticatedGitHubLogin($pat);
if ( is_wp_error($actor) ) {
return $actor;
}

$comments = self::apiGet(
sprintf('%s/repos/%s/issues/%d/comments', self::API_BASE, $repo, $issue_number),
array(
Expand Down
15 changes: 15 additions & 0 deletions tests/smoke-github-create-abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,21 @@ function wp_remote_retrieve_body( $response ): string
$assert('createOrUpdateFile existing branch only checks ref, contents, and PUTs', 3 === count($GLOBALS['dmc_http_calls']));
$assert('createOrUpdateFile existing branch does not create git ref', ! str_ends_with((string) ( $GLOBALS['dmc_http_calls'][1]['url'] ?? '' ), '/git/refs') && ! str_ends_with((string) ( $GLOBALS['dmc_http_calls'][2]['url'] ?? '' ), '/git/refs'));

// ---- commentOnIssue: fresh issues do not need authenticated actor lookup.
$reset_http();
$queue_response(200, array( 'comments' => 0 ));
$queue_response(
201, array(
'id' => 321,
'html_url' => 'https://github.com/owner/repo/issues/123#issuecomment-321',
'created_at' => '2026-05-10T00:00:00Z',
)
);
$result = GitHubAbilities::commentOnIssue(array( 'repo' => 'owner/repo', 'issue_number' => 123, 'body' => 'Fresh design direction' ));
$assert('commentOnIssue succeeds for issue with no comments', is_array($result) && true === ( $result['success'] ?? false ));
$assert('commentOnIssue checks issue comment count before posting', 2 === count($GLOBALS['dmc_http_calls']) && str_contains((string) ( $GLOBALS['dmc_http_calls'][0]['url'] ?? '' ), '/repos/owner/repo/issues/123'));
$assert('commentOnIssue skips GET /user for issue with no comments', ! str_contains((string) ( $GLOBALS['dmc_http_calls'][0]['url'] ?? '' ), '/user') && ! str_contains((string) ( $GLOBALS['dmc_http_calls'][1]['url'] ?? '' ), '/user'));

// ---- getIssue: metadata includes comment counts and the latest issue comment.
$reset_http();
$queue_response(
Expand Down
Loading