Skip to content

Commit bf447c8

Browse files
authored
Fix ParseCommitMessage: wrong hash (#61)
1 parent 9bc457f commit bf447c8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

internal/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ParseCommitMessage(message string) (projectID int, hash string, _ error) {
3333
}
3434

3535
projectID = id
36-
hash = messageParts[2]
36+
hash = messageParts[3]
3737

3838
return projectID, hash, nil
3939
}

internal/commit_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package app_test
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
10+
app "github.com/alexandear/import-gitlab-commits/internal"
11+
)
12+
13+
func TestNewCommit(t *testing.T) {
14+
committedAt, err := time.Parse(time.RFC3339, "2021-08-01T12:00:00Z")
15+
if err != nil {
16+
t.Fatal(err)
17+
}
18+
19+
projectID := 2323
20+
hash := "9bc457f81c86307f28662b40a164105f14df64e3"
21+
22+
commit := app.NewCommit(committedAt, projectID, hash)
23+
24+
assert.Equal(t, &app.Commit{
25+
CommittedAt: committedAt,
26+
Message: "Project: 2323 commit: 9bc457f81c86307f28662b40a164105f14df64e3",
27+
}, commit)
28+
}
29+
30+
func TestParseCommitMessage(t *testing.T) {
31+
t.Run("valid", func(t *testing.T) {
32+
msg := "Project: 2323 commit: 9bc457f81c86307f28662b40a164105f14df64e3"
33+
projectID, hash, err := app.ParseCommitMessage(msg)
34+
35+
require.NoError(t, err)
36+
assert.Equal(t, 2323, projectID)
37+
assert.Equal(t, "9bc457f81c86307f28662b40a164105f14df64e3", hash)
38+
})
39+
40+
t.Run("wrong project id", func(t *testing.T) {
41+
msg := "Project: PROJ commit: 9bc457f81c86307f28662b40a164105f14df64e3"
42+
_, _, err := app.ParseCommitMessage(msg)
43+
44+
assert.Error(t, err)
45+
})
46+
}

0 commit comments

Comments
 (0)