-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
ci_status.feature
202 lines (187 loc) · 8.37 KB
/
ci_status.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
Feature: hub ci-status
Background:
Given I am in "git://github.com/michiels/pencilbox.git" git repo
And I am "michiels" on github.com with OAuth token "OTOKEN"
Scenario: Fetch commit SHA
Given there is a commit named "the_sha"
Given the remote commit state of "michiels/pencilbox" "the_sha" is "success"
When I run `hub ci-status the_sha`
Then the output should contain exactly "success\n"
And the exit status should be 0
Scenario: Fetch commit SHA with URL
Given there is a commit named "the_sha"
Given the remote commit state of "michiels/pencilbox" "the_sha" is "success"
When I run `hub ci-status the_sha -v`
Then the output should contain exactly:
"""
✔︎ continuous-integration/travis-ci/push https://travis-ci.org/michiels/pencilbox/builds/1234567\n
"""
And the exit status should be 0
Scenario: Multiple statuses with verbose output
Given there is a commit named "the_sha"
Given the remote commit states of "michiels/pencilbox" "the_sha" are:
"""
{ :state => "error",
:statuses => [
{ :state => "success",
:context => "continuous-integration/travis-ci/push",
:target_url => "https://travis-ci.org/michiels/pencilbox/builds/1234567" },
{ :state => "success",
:context => "continuous-integration/travis-ci/ants",
:target_url => "https://travis-ci.org/michiels/pencilbox/builds/1234568" },
{ :state => "pending",
:context => "continuous-integration/travis-ci/merge",
:target_url => nil },
{ :state => "error",
:context => "whatevs!" },
{ :state => "failure",
:context => "GitHub CLA",
:target_url => "https://cla.github.com/michiels/pencilbox/accept/mislav" },
]
}
"""
When I run `hub ci-status -v the_sha`
Then the output should contain exactly:
"""
✖︎ GitHub CLA https://cla.github.com/michiels/pencilbox/accept/mislav
✖︎ whatevs!
● continuous-integration/travis-ci/merge
✔︎ continuous-integration/travis-ci/ants https://travis-ci.org/michiels/pencilbox/builds/1234568
✔︎ continuous-integration/travis-ci/push https://travis-ci.org/michiels/pencilbox/builds/1234567\n
"""
And the exit status should be 1
Scenario: Multiple statuses with format string
Given there is a commit named "the_sha"
Given the remote commit states of "michiels/pencilbox" "the_sha" are:
"""
{ :state => "error",
:statuses => [
{ :state => "success",
:context => "continuous-integration/travis-ci/push",
:target_url => "https://travis-ci.org/michiels/pencilbox/builds/1234567" },
{ :state => "success",
:context => "continuous-integration/travis-ci/ants",
:target_url => "https://travis-ci.org/michiels/pencilbox/builds/1234568" },
{ :state => "pending",
:context => "continuous-integration/travis-ci/merge",
:target_url => nil },
{ :state => "error",
:context => "whatevs!" },
{ :state => "failure",
:context => "GitHub CLA",
:target_url => "https://cla.github.com/michiels/pencilbox/accept/mislav" },
]
}
"""
When I run `hub ci-status the_sha --format '%S: %t (%U)%n'`
Then the output should contain exactly:
"""
failure: GitHub CLA (https://cla.github.com/michiels/pencilbox/accept/mislav)
error: whatevs! ()
pending: continuous-integration/travis-ci/merge ()
success: continuous-integration/travis-ci/ants (https://travis-ci.org/michiels/pencilbox/builds/1234568)
success: continuous-integration/travis-ci/push (https://travis-ci.org/michiels/pencilbox/builds/1234567)\n
"""
And the exit status should be 1
Scenario: Exit status 1 for 'error' and 'failure'
Given the remote commit state of "michiels/pencilbox" "HEAD" is "error"
When I run `hub ci-status`
Then the exit status should be 1
And the output should contain exactly "error\n"
Scenario: Use HEAD when no sha given
Given the remote commit state of "michiels/pencilbox" "HEAD" is "pending"
When I run `hub ci-status`
Then the exit status should be 2
And the output should contain exactly "pending\n"
Scenario: Exit status 3 for no statuses available
Given there is a commit named "the_sha"
Given the remote commit state of "michiels/pencilbox" "the_sha" is nil
When I run `hub ci-status the_sha`
Then the output should contain exactly "no status\n"
And the exit status should be 3
Scenario: Exit status 3 for no statuses available without URL
Given there is a commit named "the_sha"
Given the remote commit state of "michiels/pencilbox" "the_sha" is nil
When I run `hub ci-status -v the_sha`
Then the output should contain exactly "no status\n"
And the exit status should be 3
Scenario: Abort with message when invalid ref given
When I run `hub ci-status this-is-an-invalid-ref`
Then the exit status should be 1
And the output should contain exactly "Aborted: no revision could be determined from 'this-is-an-invalid-ref'\n"
Scenario: Non-GitHub repo
Given the "origin" remote has url "mygh:Manganeez/repo.git"
When I run `hub ci-status`
Then the stderr should contain exactly:
"""
Aborted: could not find any git remote pointing to a GitHub repository\n
"""
And the exit status should be 1
Scenario: Enterprise CI statuses
Given the "origin" remote has url "[email protected]:michiels/pencilbox.git"
And I am "michiels" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
Given there is a commit named "the_sha"
Given the remote commit state of "git.my.org/michiels/pencilbox" "the_sha" is "success"
When I successfully run `hub ci-status the_sha`
Then the output should contain exactly "success\n"
Scenario: If alias named ci-status exists, it should not be expanded.
Given there is a commit named "the_sha"
Given the remote commit state of "michiels/pencilbox" "the_sha" is "success"
When I successfully run `git config --global alias.ci-status "ci-status -v"`
And I successfully run `hub ci-status the_sha`
Then the output should contain exactly "success\n"
Scenario: Has Checks
Given there is a commit named "the_sha"
And the GitHub API server:
"""
get('/repos/michiels/pencilbox/commits/:sha/status') {
json({ :state => "success",
:statuses => [
{ :state => "success",
:context => "travis-ci",
:target_url => "the://url"}
]
})
}
get('/repos/michiels/pencilbox/commits/:sha/check-runs') {
json({ :check_runs => [
{ :status => "completed",
:conclusion => "action_required",
:name => "check 1",
:html_url => "the://url" },
{ :status => "queued",
:conclusion => "",
:name => "check 2",
:html_url => "the://url" },
]
})
}
"""
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 "[email protected]: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"