根据GitHub REST API的说法,要列出在GitHub拉请求上发布的评论,我们需要将网址放在一起:
/repos/:owner/:repo/pulls/:pull_number/comments
在这个URL中有三个参数::owner
、:repo
和:pull_number
。
下面是一个curl
命令行示例,该示例获取对一个拉请求的json
响应:
curl "https://api.github.com/repos/37signals/sub/issues/2/comments" -v
让我们打破这个网址..。
:owner
是37signals
。:repo
是sub
。:pull_number
是2
我正在处理的拉请求是:
https://github.prod.mycompany.com/MyTeamName/MyRepoName/pull/3
同样,为了将GitHub API URL
地址组合在一起,我需要:owner
、:repo
和:pull_number
。
我试过:
curl https://api.github.com/repos/mycompany/MyRepoName/issues/3/comments -v
但是它返回一个Not Found
错误。
发出API请求的正确URL是什么?
发布于 2020-05-04 22:44:47
通过Github,我们获得了许多不同的API URL,我们都可以通过用户名/密码组合进行身份验证:
curl -i https://github.mycompany.com/api/v3 -u my_git_username:@my_password
或者用Github令牌:
curl -H "Authorization: token 123a42s67f38g45hh67aj89a014sd11fhh444ee1" https://github.mycompany.com/api/v3
无论您选择哪种auth方法,curl
查询的输出都是相同的,它在下面被复制/粘贴:
{
"current_user_url": "https://github.mycompany.com/api/v3/user",
"current_user_authorizations_html_url": "https://github.mycompany.com/settings/connections/applications{/client_id}",
"authorizations_url": "https://github.mycompany.com/api/v3/authorizations",
"code_search_url": "https://github.mycompany.com/api/v3/search/code?q={query}{&page,per_page,sort,order}",
"commit_search_url": "https://github.mycompany.com/api/v3/search/commits?q={query}{&page,per_page,sort,order}",
"emails_url": "https://github.mycompany.com/api/v3/user/emails",
"emojis_url": "https://github.mycompany.com/api/v3/emojis",
"events_url": "https://github.mycompany.com/api/v3/events",
"feeds_url": "https://github.mycompany.com/api/v3/feeds",
"followers_url": "https://github.mycompany.com/api/v3/user/followers",
"following_url": "https://github.mycompany.com/api/v3/user/following{/target}",
"gists_url": "https://github.mycompany.com/api/v3/gists{/gist_id}",
"hub_url": "https://github.mycompany.com/api/v3/hub",
"issue_search_url": "https://github.mycompany.com/api/v3/search/issues?q={query}{&page,per_page,sort,order}",
"issues_url": "https://github.mycompany.com/api/v3/issues",
"keys_url": "https://github.mycompany.com/api/v3/user/keys",
"notifications_url": "https://github.mycompany.com/api/v3/notifications",
"organization_repositories_url": "https://github.mycompany.com/api/v3/orgs/{org}/repos{?type,page,per_page,sort}",
"organization_url": "https://github.mycompany.com/api/v3/orgs/{org}",
"public_gists_url": "https://github.mycompany.com/api/v3/gists/public",
"rate_limit_url": "https://github.mycompany.com/api/v3/rate_limit",
"repository_url": "https://github.mycompany.com/api/v3/repos/{owner}/{repo}",
"repository_search_url": "https://github.mycompany.com/api/v3/search/repositories?q={query}{&page,per_page,sort,order}",
"current_user_repositories_url": "https://github.mycompany.com/api/v3/user/repos{?type,page,per_page,sort}",
"starred_url": "https://github.mycompany.com/api/v3/user/starred{/owner}{/repo}",
"starred_gists_url": "https://github.mycompany.com/api/v3/gists/starred",
"team_url": "https://github.mycompany.com/api/v3/teams",
"user_url": "https://github.mycompany.com/api/v3/users/{user}",
"user_organizations_url": "https://github.mycompany.com/api/v3/user/orgs",
"user_repositories_url": "https://github.mycompany.com/api/v3/users/{user}/repos{?type,page,per_page,sort}",
"user_search_url": "https://github.mycompany.com/api/v3/search/users?q={query}{&page,per_page,sort,order}"
}
`
要查询拉请求,请向curl
查询提供包含拉请求号(:number
)、存储库名称(:repo
)和MyTeamName (:owner
)的URL:
curl -u my_git_username:@my_password -H "Accept: application/vnd.github.shadow-cat-preview+json" https://github.mycompany.com/api/v3/repos/MyTeamName/MyRepoName/pulls/3
或者使用Github令牌:
curl -H "Authorization: token 123a42s67f38g45hh67aj89a014sd11fhh444ee1" -H "Accept: application/vnd.github.shadow-cat-preview+json" https://github.mycompany.com/api/v3/repos/MyTeamName/MyRepoName/pulls/3
https://stackoverflow.com/questions/61594636
复制相似问题