Skip to main content

We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.

存储库自动链接

为了帮助简化您的工作流程,您可以使用 API 向外部资源(如 JIRA 问题和 Zendesk 事件单)添加自动链接。

有关详细信息,请参阅“配置自动链接以引用外部资源”。

GitHub Apps 需要有读写权限的仓库管理权限才能使用 Autolinks API。

This returns a list of autolinks configured for the given repository.

Information about autolinks are only available to repository administrators.

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

Query parameters
Name, Type, Description
pageinteger

Page number of the results to fetch.

Default: 1

状态代码说明
200

OK

get/repos/{owner}/{repo}/autolinks
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/autolinks

Response

Status: 200
[ { "id": 1, "key_prefix": "TICKET-", "url_template": "https://example.com/TICKET?query=<num>" } ]

Users with admin access to the repository can create an autolink.

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

Body parameters
Name, Type, Description
key_prefixstringRequired

The prefix appended by a number will generate a link any time it is found in an issue, pull request, or commit.

url_templatestringRequired

The URL must contain <num> for the reference number.

is_alphanumericboolean

Whether this autolink reference matches alphanumeric characters. If true, the <num> parameter of the url_template matches alphanumeric characters A-Z (case insensitive), 0-9, and -. If false, this autolink reference only matches numeric characters.

Default: true

状态代码说明
201

Created

422

Validation failed, or the endpoint has been spammed.

post/repos/{owner}/{repo}/autolinks
curl \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/autolinks \ -d '{"key_prefix":"TICKET-","url_template":"https://example.com/TICKET?query=<num>","is_alphanumeric":true}'

response

Status: 201
{ "id": 1, "key_prefix": "TICKET-", "url_template": "https://example.com/TICKET?query=<num>" }

This returns a single autolink reference by ID that was configured for the given repository.

Information about autolinks are only available to repository administrators.

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

autolink_idintegerRequired

The unique identifier of the autolink.

状态代码说明
200

OK

404

Resource not found

get/repos/{owner}/{repo}/autolinks/{autolink_id}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/autolinks/AUTOLINK_ID

Response

Status: 200
{ "id": 1, "key_prefix": "TICKET-", "url_template": "https://example.com/TICKET?query=<num>" }

This deletes a single autolink reference by ID that was configured for the given repository.

Information about autolinks are only available to repository administrators.

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

autolink_idintegerRequired

The unique identifier of the autolink.

状态代码说明
204

No Content

404

Resource not found

delete/repos/{owner}/{repo}/autolinks/{autolink_id}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/autolinks/AUTOLINK_ID

Response

Status: 204