diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..5d7e27b --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,34 @@ +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + types: + - opened + - synchronize + - reopened + - review_requested + pull_request_review: + types: + - submitted + workflow_dispatch: + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/lexer_state.go b/lexer_state.go index b0b4d54..76c29f1 100644 --- a/lexer_state.go +++ b/lexer_state.go @@ -111,12 +111,13 @@ func descriptionDelimiterState(l *lexer) stateFunc { l.Emit(breakingChangeToken) } - l.Take(": ") + l.Next() - if l.Current() != ": " { + if l.Current() != ":" || l.Peek() != ' ' { l.Error(errDescMissingDelimiter) return nil } + l.Next() l.Emit(descDelimiterToken) diff --git a/parser.go b/parser.go index d213147..82484b7 100644 --- a/parser.go +++ b/parser.go @@ -47,8 +47,8 @@ func (p *Parser) parse(input string) (*Commit, error) { c.scope = t.Value case descriptionToken: c.description = t.Value + c.header = strings.TrimSpace(lex.Get(0, t.End)) case bodyToken: - c.header = strings.TrimSpace(lex.Get(0, t.Start)) c.body = strings.TrimSpace(t.Value) case footerKeyToken: if footerStartPos == 0 { diff --git a/parser_header_test.go b/parser_header_test.go index cc9c263..71757cf 100644 --- a/parser_header_test.go +++ b/parser_header_test.go @@ -17,6 +17,24 @@ func TestParseHeaderValid(t *testing.T) { "feat: description with body 1, \n\n2, 3 and 4?", "feat1234(@scope/scope1,scope2): description, \n\n body 1 2, 3 and 4?", "1245#feat1234(@scope/scope1,scope2): description, \n\n body 1 2, 3 and 4?", + "feat: description with colon at the end: mid:dle and :start of words", + "feat: description with gitmoji at the end :hammer:", + "feat: description with gitmoji in :hammer: the middle", + "feat: :hammer: description with gitmoji at the start", + "feat(scope): description with colon at the end: mid:dle and :start of words", + "feat(scope): description with gitmoji at the end :hammer:", + "feat(scope): description with gitmoji in :hammer: the middle", + "feat(scope): :hammer: description with gitmoji at the start", + "feat!: description with colon at the end: mid:dle and :start of words", + "feat!: description with gitmoji at the end :hammer:", + "feat!: description with gitmoji in :hammer: the middle", + "feat!: :hammer: description with gitmoji at the start", + "feat(scope)!: description with colon at the end: mid:dle and :start of words", + "feat(scope)!: description with gitmoji at the end :hammer:", + "feat(scope)!: description with gitmoji in :hammer: the middle", + "feat(scope)!: :hammer: description with gitmoji at the start", + `feat: : : A description`, + `feat: :: A description ::`, } p := New() @@ -52,6 +70,8 @@ func TestParseHeaderInvalid(t *testing.T) { `feat((`, `feat():`, `feat):`, + `feat:: A description`, + `feat:::: A description`, } p := New()