-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
This issue is to implement the command necessary to list repository autolinks as discussed within #9420 underneath gh repo autolink.
This should follow similar form as existing GitHub CLI commands as well as necessary tests.
cc: @hoffm @nitrocode
Acceptance Criteria
Note
Successful commands should return 0 exit code whereas errors should return 1 unless otherwise stated.
When I run gh repo autolink list --help
Then I see an informative help usage containing descriptive command information:
-
Long description explaining command purpose
-
Usage:
gh repo autolink list [flags] -
Aliases:
listcommands typically allowlsalias -
Flags:
-q, --jq expression Filter JSON output using a jq expression --json fields Output JSON with the specified fields -t, --template string Format JSON output using a Go template; see "gh help formatting" -w, --web List autolinks in the web browser -
Inherited flags:
INHERITED FLAGS --help Show help for command -R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format -
JSON fields:
JSON FIELDS id, isAlphanumeric, keyPrefix, urlTemplate
Given I don't have the admin role on the repository
And Given I have a local repository cloned from GitHub
When I run gh repo autolink list
Then I see an informative error
error getting autolinks: HTTP 404: Must have admin rights to Repository. (https://api.github.com/repos/{owner}/{repo}/autolinks)Given I have the admin role on the repository
And Given I have a local repository cloned from GitHub
When I run gh repo autolink list
Then I see a message and table of repository autolinks including:
-
Message about autolinks found
-
If autolinks are not found:
no autolinks found -
If autolinks are found:
Showing X autolinks in <owner>/<repo>REST API for retrieving autolinks does not support pagination
-
-
Table containing information if autolinks are found containing:
IDKey PrefixURL TemplateAlphanumeric: eithertrueorfalse
Given I have the admin role on the repository
And Given I have a local repository cloned from GitHub
And Given There are no autolinks on the repository
When I run gh repo autolink list non-interactively
Then No message is displayed
Note
For examples, see gh variable list behavior using cmdutil.NewNoResultsError()
Given I have the admin role on the repository
And Given I have a remote repository with autolinks
When I run gh repo autolink list --repo <owner>/<repo>
Then I see a table of repository autolinks the same as when I have a local repository
Given I have the admin role on the repository
And Given I have a remote repository with autolinks
When I run GH_REPO=<owner>/<repo> gh repo autolink list
Then I see a table of repository autolinks the same as when I have a local repository
Given I have a repository with autolinks
When I run gh repo autolink list --json
Then I see a list of repository autolink fields that can be outputted in JSON format:
Specify one or more comma-separated fields for `--json`:
id
isAlphanumeric
keyPrefix
urlTemplateGiven I have a repository with autolinks
When I run gh repo autolink list --json <field>[,<field>...] with one or more relevant fields
Then I see a JSON list of repository autolinks only containing the specified fields:
[
{
"id": 1,
"isAlphanumeric": false,
"keyPrefix": "DISCORD-",
"urlTemplate": "https://discord.com/channels/<num>",
},
{
"id": 2,
"isAlphanumeric": true
"keyPrefix": "TICKET-",
"urlTemplate": "https://example.com/TICKET?query=<num>",
}
]Given I have a repository with autolinks
When I run gh repo autolink list --json <field>[,<field>...] --jq '...' with a valid jq filter
Then I see the JSON result from applying the jq filter to the standard gh repo autolink --json <field>[,<field>...] result:
gh repo autolink list --json id,is_alphanumeric,--jq '[ .[] | select(.is_alphanumeric == true) ]'resulting in:
[
{
"id": 2,
"isAlphanumeric": true
"keyPrefix": "TICKET-",
"urlTemplate": "https://example.com/TICKET?query=<num>",
}
]Given I have a repository with autolinks
When I run gh repo autolink list --json <field>[,<field>...] --template '...' with a Go template
Then I see the formatted JSON result from applying the template Go template filter to the standard gh repo autolink --json <field>[,<field>...] result
Given I have the admin role on the repository
And Given I have a local repository cloned from GitHub
When I run gh repo autolink list --web
Then I have a web browser opened to Autolinks references section of the repository settings page