根据GitHub REST API,要列出在GitHub Pull Request上发布的评论,我们需要将URL地址放在一起:
/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
让我们细分此URL ...
: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是什么?
答案 0 :(得分:0)
通过Github Enterprise,我们提供了许多不同的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
无论您选择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
查询提供URL,该URL包含请求请求编号(:number
),存储库名称(:repo
)和MyTeamName({{1} }):
:owner
或使用Github身份验证令牌:
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