Skip to content

Commit 0330993

Browse files
irzhywaumislav
authored andcommitted
add message on pr checks returns no CI with non-empty PR
1 parent c77e6af commit 0330993

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

pkg/cmd/pr/checks/checks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func checksRun(opts *ChecksOptions) error {
7676
}
7777

7878
if len(pr.Commits.Nodes) == 0 {
79-
return nil
79+
return fmt.Errorf("no commit found on the pull request")
8080
}
8181

8282
rollup := pr.Commits.Nodes[0].Commit.StatusCheckRollup.Contexts.Nodes
8383
if len(rollup) == 0 {
84-
return nil
84+
return fmt.Errorf("no checks reported on the '%s' branch", pr.BaseRefName)
8585
}
8686

8787
passing := 0

pkg/cmd/pr/checks/checks_test.go

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ func TestNewCmdChecks(t *testing.T) {
6363

6464
func Test_checksRun(t *testing.T) {
6565
tests := []struct {
66-
name string
67-
fixture string
68-
stubs func(*httpmock.Registry)
69-
wantOut string
70-
nontty bool
71-
wantErr bool
66+
name string
67+
fixture string
68+
stubs func(*httpmock.Registry)
69+
wantOut string
70+
nontty bool
71+
unsuccessfulChecks bool
72+
wantErr bool
7273
}{
7374
{
7475
name: "no commits",
@@ -82,39 +83,45 @@ func Test_checksRun(t *testing.T) {
8283
} } }
8384
`)))
8485
},
86+
unsuccessfulChecks: true,
87+
wantErr: true,
88+
wantOut: "no commit found on the pull request",
8589
},
8690
{
8791
name: "no checks",
8892
stubs: func(reg *httpmock.Registry) {
8993
reg.StubResponse(200, bytes.NewBufferString(`
9094
{ "data": { "repository": {
91-
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]} }
95+
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]}, "baseRefName": "master" }
9296
} } }
9397
`))
9498
},
99+
unsuccessfulChecks: true,
100+
wantErr: true,
101+
wantOut: "no checks reported on the 'master' branch",
95102
},
96103
{
97-
name: "some failing",
98-
fixture: "./fixtures/someFailing.json",
99-
wantOut: "Some checks were not successful\n1 failing, 1 successful, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n- slow tests 1m26s sweet link\n",
100-
wantErr: true,
104+
name: "some failing",
105+
fixture: "./fixtures/someFailing.json",
106+
wantOut: "Some checks were not successful\n1 failing, 1 successful, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n- slow tests 1m26s sweet link\n",
107+
unsuccessfulChecks: true,
101108
},
102109
{
103-
name: "some pending",
104-
fixture: "./fixtures/somePending.json",
105-
wantOut: "Some checks are still pending\n0 failing, 2 successful, and 1 pending checks\n\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n- slow tests 1m26s sweet link\n",
106-
wantErr: true,
110+
name: "some pending",
111+
fixture: "./fixtures/somePending.json",
112+
wantOut: "Some checks are still pending\n0 failing, 2 successful, and 1 pending checks\n\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n- slow tests 1m26s sweet link\n",
113+
unsuccessfulChecks: true,
107114
},
108115
{
109116
name: "all passing",
110117
fixture: "./fixtures/allPassing.json",
111118
wantOut: "All checks were successful\n0 failing, 3 successful, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n",
112119
},
113120
{
114-
name: "with statuses",
115-
fixture: "./fixtures/withStatuses.json",
116-
wantOut: "Some checks were not successful\n1 failing, 2 successful, and 0 pending checks\n\nX a status sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n",
117-
wantErr: true,
121+
name: "with statuses",
122+
fixture: "./fixtures/withStatuses.json",
123+
wantOut: "Some checks were not successful\n1 failing, 2 successful, and 0 pending checks\n\nX a status sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n",
124+
unsuccessfulChecks: true,
118125
},
119126
{
120127
name: "no commits",
@@ -129,31 +136,37 @@ func Test_checksRun(t *testing.T) {
129136
} } }
130137
`)))
131138
},
139+
unsuccessfulChecks: true,
140+
wantErr: true,
141+
wantOut: "no commit found on the pull request",
132142
},
133143
{
134144
name: "no checks",
135145
nontty: true,
136146
stubs: func(reg *httpmock.Registry) {
137147
reg.StubResponse(200, bytes.NewBufferString(`
138148
{ "data": { "repository": {
139-
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]} }
149+
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]}, "baseRefName": "master" }
140150
} } }
141151
`))
142152
},
153+
unsuccessfulChecks: true,
154+
wantErr: true,
155+
wantOut: "no checks reported on the 'master' branch",
143156
},
144157
{
145-
name: "some failing",
146-
nontty: true,
147-
fixture: "./fixtures/someFailing.json",
148-
wantOut: "sad tests\tfail\t1m26s\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
149-
wantErr: true,
158+
name: "some failing",
159+
nontty: true,
160+
fixture: "./fixtures/someFailing.json",
161+
wantOut: "sad tests\tfail\t1m26s\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
162+
unsuccessfulChecks: true,
150163
},
151164
{
152-
name: "some pending",
153-
nontty: true,
154-
fixture: "./fixtures/somePending.json",
155-
wantOut: "cool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
156-
wantErr: true,
165+
name: "some pending",
166+
nontty: true,
167+
fixture: "./fixtures/somePending.json",
168+
wantOut: "cool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
169+
unsuccessfulChecks: true,
157170
},
158171
{
159172
name: "all passing",
@@ -162,11 +175,11 @@ func Test_checksRun(t *testing.T) {
162175
wantOut: "awesome tests\tpass\t1m26s\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\n",
163176
},
164177
{
165-
name: "with statuses",
166-
nontty: true,
167-
fixture: "./fixtures/withStatuses.json",
168-
wantOut: "a status\tfail\t0\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\n",
169-
wantErr: true,
178+
name: "with statuses",
179+
nontty: true,
180+
fixture: "./fixtures/withStatuses.json",
181+
wantOut: "a status\tfail\t0\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\n",
182+
unsuccessfulChecks: true,
170183
},
171184
}
172185

@@ -184,6 +197,8 @@ func Test_checksRun(t *testing.T) {
184197
}
185198

186199
reg := &httpmock.Registry{}
200+
defer reg.Verify(t)
201+
187202
if tt.stubs != nil {
188203
tt.stubs(reg)
189204
} else if tt.fixture != "" {
@@ -198,14 +213,18 @@ func Test_checksRun(t *testing.T) {
198213
}
199214

200215
err := checksRun(opts)
201-
if tt.wantErr {
216+
if err != nil && tt.wantErr {
217+
assert.Equal(t, tt.wantOut, err.Error())
218+
return
219+
}
220+
221+
if tt.unsuccessfulChecks {
202222
assert.Equal(t, "SilentError", err.Error())
203223
} else {
204224
assert.NoError(t, err)
205225
}
206226

207227
assert.Equal(t, tt.wantOut, stdout.String())
208-
reg.Verify(t)
209228
})
210229
}
211230
}

0 commit comments

Comments
 (0)