diff --git a/notifier/github/commits.go b/notifier/github/commits.go index c8c2fad..13bdc29 100644 --- a/notifier/github/commits.go +++ b/notifier/github/commits.go @@ -37,8 +37,8 @@ func (g *CommitsService) lastOne(commits []string, revision string) (string, err if revision == "" { return "", errors.New("no revision specified") } - if len(commits) == 0 { - return "", errors.New("no commits") + if len(commits) < 2 { + return "", errors.New("not enough commits") } // e.g. // a0ce5bf 2018/04/05 20:50:01 (HEAD -> master, origin/master) diff --git a/notifier/github/commits_test.go b/notifier/github/commits_test.go index 7035367..87455a8 100644 --- a/notifier/github/commits_test.go +++ b/notifier/github/commits_test.go @@ -70,6 +70,15 @@ func TestCommitsLastOne(t *testing.T) { lastRev: "", ok: false, }, + { + // one commit + commits: []string{ + "04e0917e448b662c2b16330fad50e97af16ff27a", + }, + revision: "04e0917e448b662c2b16330fad50e97af16ff27a", + lastRev: "", + ok: false, + }, } for _, testCase := range testCases { diff --git a/notifier/gitlab/commits.go b/notifier/gitlab/commits.go index 41476f0..bf33d77 100644 --- a/notifier/gitlab/commits.go +++ b/notifier/gitlab/commits.go @@ -33,8 +33,8 @@ func (g *CommitsService) lastOne(commits []string, revision string) (string, err if revision == "" { return "", errors.New("no revision specified") } - if len(commits) == 0 { - return "", errors.New("no commits") + if len(commits) < 2 { + return "", errors.New("not enough commits") } return commits[1], nil diff --git a/notifier/gitlab/commits_test.go b/notifier/gitlab/commits_test.go index 7395004..0cbe947 100644 --- a/notifier/gitlab/commits_test.go +++ b/notifier/gitlab/commits_test.go @@ -70,6 +70,15 @@ func TestCommitsLastOne(t *testing.T) { lastRev: "", ok: false, }, + { + // one commit + commits: []string{ + "04e0917e448b662c2b16330fad50e97af16ff27a", + }, + revision: "04e0917e448b662c2b16330fad50e97af16ff27a", + lastRev: "", + ok: false, + }, } for _, testCase := range testCases {