Skip to content

Commit b15ffe0

Browse files
authored
Merge pull request #490 from Extra-Chill/fix/github-issue-read-credentials
fix: select issue read credentials
2 parents 1255959 + a5e3090 commit b15ffe0

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

inc/Abilities/GitHubAbilities.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ public static function listIssues( array $input ): array|\WP_Error {
13571357
return new \WP_Error('missing_repo', 'Repository is required (owner/repo format).', array( 'status' => 400 ));
13581358
}
13591359

1360-
$pat = self::getPatForRepo($repo);
1360+
$pat = self::getPatForRepoCapability($repo, 'issues_read');
13611361
if ( empty($pat) ) {
13621362
return self::patError();
13631363
}
@@ -1406,7 +1406,7 @@ public static function getIssue( array $input ): array|\WP_Error {
14061406
return new \WP_Error('missing_params', 'Repository (owner/repo) and issue_number are required.', array( 'status' => 400 ));
14071407
}
14081408

1409-
$pat = self::getPatForRepo($repo);
1409+
$pat = self::getPatForRepoCapability($repo, 'issues_read');
14101410
if ( empty($pat) ) {
14111411
return self::patError();
14121412
}

tests/smoke-github-create-abilities.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,10 @@ function wp_remote_retrieve_body( $response ): string
845845
),
846846
)
847847
);
848+
\DataMachineCode\Support\GitHubCredentialResolver::$selectors = array();
848849
$result = GitHubAbilities::getIssue(array( 'repo' => 'owner/repo', 'issue_number' => 123 ));
849850
$issue = is_array($result) ? ( $result['issue'] ?? array() ) : array();
851+
$assert('getIssue selects issues_read credential by repo', array( 'repo' => 'owner/repo', 'capability' => 'issues_read' ) === ( \DataMachineCode\Support\GitHubCredentialResolver::$selectors[0] ?? null ));
850852
$assert('getIssue returns generated_at', is_array($result) && ! empty($result['generated_at']));
851853
$assert('getIssue preserves comments count', 2 === ( $issue['comments'] ?? null ) && 2 === ( $issue['comment_count'] ?? null ));
852854
$assert('getIssue fetches latest issue comment page', is_string($GLOBALS['dmc_http_calls'][1]['url'] ?? null) && str_contains($GLOBALS['dmc_http_calls'][1]['url'], '/repos/owner/repo/issues/123/comments') && str_contains($GLOBALS['dmc_http_calls'][1]['url'], 'per_page=1') && str_contains($GLOBALS['dmc_http_calls'][1]['url'], 'page=2'));

0 commit comments

Comments
 (0)