add message on pr checks returns no CI with non-empty PR
This commit is contained in:
parent
c77e6afb03
commit
03309930f0
2 changed files with 58 additions and 39 deletions
|
|
@ -76,12 +76,12 @@ func checksRun(opts *ChecksOptions) error {
|
|||
}
|
||||
|
||||
if len(pr.Commits.Nodes) == 0 {
|
||||
return nil
|
||||
return fmt.Errorf("no commit found on the pull request")
|
||||
}
|
||||
|
||||
rollup := pr.Commits.Nodes[0].Commit.StatusCheckRollup.Contexts.Nodes
|
||||
if len(rollup) == 0 {
|
||||
return nil
|
||||
return fmt.Errorf("no checks reported on the '%s' branch", pr.BaseRefName)
|
||||
}
|
||||
|
||||
passing := 0
|
||||
|
|
|
|||
|
|
@ -63,12 +63,13 @@ func TestNewCmdChecks(t *testing.T) {
|
|||
|
||||
func Test_checksRun(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fixture string
|
||||
stubs func(*httpmock.Registry)
|
||||
wantOut string
|
||||
nontty bool
|
||||
wantErr bool
|
||||
name string
|
||||
fixture string
|
||||
stubs func(*httpmock.Registry)
|
||||
wantOut string
|
||||
nontty bool
|
||||
unsuccessfulChecks bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "no commits",
|
||||
|
|
@ -82,28 +83,34 @@ func Test_checksRun(t *testing.T) {
|
|||
} } }
|
||||
`)))
|
||||
},
|
||||
unsuccessfulChecks: true,
|
||||
wantErr: true,
|
||||
wantOut: "no commit found on the pull request",
|
||||
},
|
||||
{
|
||||
name: "no checks",
|
||||
stubs: func(reg *httpmock.Registry) {
|
||||
reg.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]} }
|
||||
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]}, "baseRefName": "master" }
|
||||
} } }
|
||||
`))
|
||||
},
|
||||
unsuccessfulChecks: true,
|
||||
wantErr: true,
|
||||
wantOut: "no checks reported on the 'master' branch",
|
||||
},
|
||||
{
|
||||
name: "some failing",
|
||||
fixture: "./fixtures/someFailing.json",
|
||||
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",
|
||||
wantErr: true,
|
||||
name: "some failing",
|
||||
fixture: "./fixtures/someFailing.json",
|
||||
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",
|
||||
unsuccessfulChecks: true,
|
||||
},
|
||||
{
|
||||
name: "some pending",
|
||||
fixture: "./fixtures/somePending.json",
|
||||
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",
|
||||
wantErr: true,
|
||||
name: "some pending",
|
||||
fixture: "./fixtures/somePending.json",
|
||||
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",
|
||||
unsuccessfulChecks: true,
|
||||
},
|
||||
{
|
||||
name: "all passing",
|
||||
|
|
@ -111,10 +118,10 @@ func Test_checksRun(t *testing.T) {
|
|||
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",
|
||||
},
|
||||
{
|
||||
name: "with statuses",
|
||||
fixture: "./fixtures/withStatuses.json",
|
||||
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",
|
||||
wantErr: true,
|
||||
name: "with statuses",
|
||||
fixture: "./fixtures/withStatuses.json",
|
||||
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",
|
||||
unsuccessfulChecks: true,
|
||||
},
|
||||
{
|
||||
name: "no commits",
|
||||
|
|
@ -129,6 +136,9 @@ func Test_checksRun(t *testing.T) {
|
|||
} } }
|
||||
`)))
|
||||
},
|
||||
unsuccessfulChecks: true,
|
||||
wantErr: true,
|
||||
wantOut: "no commit found on the pull request",
|
||||
},
|
||||
{
|
||||
name: "no checks",
|
||||
|
|
@ -136,24 +146,27 @@ func Test_checksRun(t *testing.T) {
|
|||
stubs: func(reg *httpmock.Registry) {
|
||||
reg.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]} }
|
||||
"pullRequest": { "number": 123, "commits": { "nodes": [{"commit": {"oid": "abc"}}]}, "baseRefName": "master" }
|
||||
} } }
|
||||
`))
|
||||
},
|
||||
unsuccessfulChecks: true,
|
||||
wantErr: true,
|
||||
wantOut: "no checks reported on the 'master' branch",
|
||||
},
|
||||
{
|
||||
name: "some failing",
|
||||
nontty: true,
|
||||
fixture: "./fixtures/someFailing.json",
|
||||
wantOut: "sad tests\tfail\t1m26s\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
|
||||
wantErr: true,
|
||||
name: "some failing",
|
||||
nontty: true,
|
||||
fixture: "./fixtures/someFailing.json",
|
||||
wantOut: "sad tests\tfail\t1m26s\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
|
||||
unsuccessfulChecks: true,
|
||||
},
|
||||
{
|
||||
name: "some pending",
|
||||
nontty: true,
|
||||
fixture: "./fixtures/somePending.json",
|
||||
wantOut: "cool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
|
||||
wantErr: true,
|
||||
name: "some pending",
|
||||
nontty: true,
|
||||
fixture: "./fixtures/somePending.json",
|
||||
wantOut: "cool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\nslow tests\tpending\t1m26s\tsweet link\n",
|
||||
unsuccessfulChecks: true,
|
||||
},
|
||||
{
|
||||
name: "all passing",
|
||||
|
|
@ -162,11 +175,11 @@ func Test_checksRun(t *testing.T) {
|
|||
wantOut: "awesome tests\tpass\t1m26s\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\n",
|
||||
},
|
||||
{
|
||||
name: "with statuses",
|
||||
nontty: true,
|
||||
fixture: "./fixtures/withStatuses.json",
|
||||
wantOut: "a status\tfail\t0\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\n",
|
||||
wantErr: true,
|
||||
name: "with statuses",
|
||||
nontty: true,
|
||||
fixture: "./fixtures/withStatuses.json",
|
||||
wantOut: "a status\tfail\t0\tsweet link\ncool tests\tpass\t1m26s\tsweet link\nrad tests\tpass\t1m26s\tsweet link\n",
|
||||
unsuccessfulChecks: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +197,8 @@ func Test_checksRun(t *testing.T) {
|
|||
}
|
||||
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
|
||||
if tt.stubs != nil {
|
||||
tt.stubs(reg)
|
||||
} else if tt.fixture != "" {
|
||||
|
|
@ -198,14 +213,18 @@ func Test_checksRun(t *testing.T) {
|
|||
}
|
||||
|
||||
err := checksRun(opts)
|
||||
if tt.wantErr {
|
||||
if err != nil && tt.wantErr {
|
||||
assert.Equal(t, tt.wantOut, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if tt.unsuccessfulChecks {
|
||||
assert.Equal(t, "SilentError", err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.wantOut, stdout.String())
|
||||
reg.Verify(t)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue