提交 661d2e2a 编写于 作者: M Mislav Marohnić

`ci-status`: handle more cases when Checks API is unavailable

Older Enterprise hosts won't have Checks API, but we still want `hub
ci-status` to work with them. It seems like a HTTP 403 is returned in
that case, so we can safely ignore it. Also ignore HTTP 404 just in case.

Fixes #1821
上级 b3ef319b
......@@ -134,3 +134,28 @@ Feature: hub ci-status
When I run `hub ci-status the_sha`
Then the output should contain exactly "action_required\n"
And the exit status should be 1
Scenario: Older Enterprise version doesn't have Checks
Given the "origin" remote has url "git@git.my.org:michiels/pencilbox.git"
And I am "michiels" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
And there is a commit named "the_sha"
And the GitHub API server:
"""
get('/api/v3/repos/michiels/pencilbox/commits/:sha/status', :host_name => 'git.my.org') {
json({ :state => "success",
:statuses => [
{ :state => "success",
:context => "travis-ci",
:target_url => "the://url"}
]
})
}
get('/api/v3/repos/michiels/pencilbox/commits/:sha/check-runs', :host_name => 'git.my.org') {
status 403
json :message => "Must have admin rights to Repository.",
:documentation_url => "https://developer.github.com/enterprise/2.13/v3/"
}
"""
When I successfully run `hub ci-status the_sha`
Then the output should contain exactly "success\n"
......@@ -468,7 +468,7 @@ func (client *Client) FetchCIStatus(project *Project, sha string) (status *CISta
}
res, err = api.GetFile(fmt.Sprintf("repos/%s/%s/commits/%s/check-runs", project.Owner, project.Name, sha), checksType)
if err == nil && res.StatusCode == 422 {
if err == nil && (res.StatusCode == 403 || res.StatusCode == 404 || res.StatusCode == 422) {
return
}
if err = checkStatus(200, "fetching checks", res, err); err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册