Skip to content

Add support for gh repo autolink create #10119

@andyfeller

Description

@andyfeller

This issue is to implement the command necessary to create 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 create --help
Then I see an informative help usage containing descriptive command information:

  1. Long description explaining command purpose

  2. Usage: gh repo autolink create <keyPrefix> <urlTemplate> [flags]

  3. Aliases: create commands typically allow new alias

  4. Flags:

      -n, --numeric                  Mark autolink as non-alphanumeric
  5. Inherited flags:

    INHERITED FLAGS
          --help                     Show help for command
      -R, --repo [HOST/]OWNER/REPO   Select another repository using the [HOST/]OWNER/REPO format
  6. Examples

    # Create alphanumeric autolink
    gh repo autolink create "TICKET-" "https://example.com/TICKET?query=<num>"
    
    # Create numeric autolink
    gh repo autolink create "DISCORD-" "https://discord.com/channels/<num>" --numeric

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 create <keyPrefix> <urlTemplate>
Then I see an informative error

error creating autolink: 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 create <keyPrefix> <urlTemplate>
Then I see an informational message confirming the repository autolink was created

✓ Autolink "<keyPrefix>" created in <owner>/<repo>

Given I have the admin role on the repository
And Given I have a remote repository
When I run gh repo autolink create <keyPrefix> <urlTemplate> --repo <owner>/<repo>
Then I see an informational message confirming the repository autolink was created the same as when I have a local repository


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 create <keyPrefix> <urlTemplate>
And When <urlTemplate> does not contain literal <num>
Then I see an informative error explaining <urlTemplate> must contain <num>

Metadata

Metadata

Assignees

Labels

gh-reporelating to the gh repo commandhelp wantedContributions welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions