Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
shift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eduardo Trujillo
shift
Commits
b1a297e5
Commit
b1a297e5
authored
4 years ago
by
Eduardo Trujillo
Browse files
Options
Downloads
Patches
Plain Diff
feat(Parsers): Improve handling of Breaking Changes blocks
parent
f46c4a52
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Shift/Parsers.hs
+7
-3
7 additions, 3 deletions
src/Shift/Parsers.hs
src/Shift/Types.hs
+6
-6
6 additions, 6 deletions
src/Shift/Types.hs
test/Test/Shift/ParsersSpec.hs
+84
-2
84 additions, 2 deletions
test/Test/Shift/ParsersSpec.hs
with
97 additions
and
11 deletions
src/Shift/Parsers.hs
+
7
−
3
View file @
b1a297e5
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE ApplicativeDo #-}
module
Shift.Parsers
where
...
...
@@ -34,6 +35,7 @@ import Text.Megaparsec
(
<|>
),
)
import
Text.Megaparsec.Char
(
char
,
eol
,
spaceChar
,
string
)
import
Control.Applicative
(
optional
)
type
Parser
=
Parsec
Void
Text
...
...
@@ -113,9 +115,11 @@ breakingChange :: Parser BreakingChange
breakingChange
=
do
void
.
spaced
.
string
$
"BREAKING CHANGE: "
BreakingChange
<$>
(
cs
<$>
manyCharsTill
eol
)
<*>
(
cs
<$>
manyCharsTill
(
spaced
eof
<|>
(
skipSome
ticketChange
*>
eof
)))
do
shortDescription
<-
cs
<$>
manyCharsTill
eol
body
<-
optional
(
cs
<$>
(
void
eol
*>
someCharsTill
(
try
(
spaced
eof
<|>
(
skipSome
ticketChange
*>
eof
)))))
return
$
BreakingChange
shortDescription
body
ticketChange
::
Parser
(
HashSet
TicketChange
)
ticketChange
=
do
...
...
This diff is collapsed.
Click to expand it.
src/Shift/Types.hs
+
6
−
6
View file @
b1a297e5
...
...
@@ -76,9 +76,9 @@ instance Exception ShiftException
type
TicketChange
=
(
Text
,
Text
)
data
MergeCommit
=
MergeCommit
Text
deriving
(
Show
)
data
MergeCommit
=
MergeCommit
Text
deriving
(
Show
,
Eq
)
data
MiscCommit
=
MiscCommit
Text
deriving
(
Show
)
data
MiscCommit
=
MiscCommit
Text
deriving
(
Show
,
Eq
)
data
CommitType
=
CTFeature
...
...
@@ -92,9 +92,9 @@ data CommitType
data
BreakingChange
=
BreakingChange
{
_bcSubject
::
Text
,
_bcBody
::
Text
_bcBody
::
Maybe
Text
}
deriving
(
Show
)
deriving
(
Show
,
Eq
)
data
ConventionalCommit
=
ConventionalCommit
{
_ccType
::
CommitType
,
...
...
@@ -104,7 +104,7 @@ data ConventionalCommit = ConventionalCommit
_ccBreakingChanges
::
[
BreakingChange
],
_ccAffectedTickets
::
[
HashSet
TicketChange
]
}
deriving
(
Show
)
deriving
(
Show
,
Eq
)
data
TagRef
=
TagRef
{
_tRef
::
RefName
,
...
...
@@ -119,7 +119,7 @@ data ParsedCommit
=
PCConventional
ConventionalCommit
|
PCMerge
MergeCommit
|
PCMisc
MiscCommit
deriving
(
Show
)
deriving
(
Show
,
Eq
)
type
ParsedGroup
hash
=
(
Ref
hash
,
Commit
hash
,
ParsedCommit
)
...
...
This diff is collapsed.
Click to expand it.
test/Test/Shift/ParsersSpec.hs
+
84
−
2
View file @
b1a297e5
...
...
@@ -2,16 +2,98 @@
module
Test.Shift.ParsersSpec
where
import
Shift.Parsers
(
commitType
)
import
Shift.Types
(
CommitType
(
CTFeature
))
import
Shift
(
BreakingChange
(
BreakingChange
))
import
Shift.Parsers
(
breakingChange
,
commit
,
commitType
,
manyCharsTill
,
someCharsTill
,
spaced
)
import
Shift.Types
(
CommitType
(
CTFeature
),
ConventionalCommit
(
ConventionalCommit
,
_ccAffectedTickets
,
_ccBody
,
_ccBreakingChanges
,
_ccScope
,
_ccSubject
,
_ccType
),
ParsedCommit
(
PCConventional
))
import
Test.Hspec
(
Spec
,
describe
,
it
)
import
Test.Hspec.Megaparsec
(
shouldFailOn
,
shouldParse
)
import
Text.Megaparsec
(
parse
)
import
Text.Megaparsec.Char
(
eol
,
string
)
spec
::
Spec
spec
=
do
-- spaced
describe
"spaced"
$
do
it
"parses using the inner parser"
$
do
parse
(
spaced
$
string
"hello"
)
""
"hello"
`
shouldParse
`
"hello"
it
"parses using the inner parser (with whitespace)"
$
do
parse
(
spaced
$
string
"hello"
)
""
" hello"
`
shouldParse
`
"hello"
it
"parses using the inner parser (with newlines)"
$
do
parse
(
spaced
$
string
"hello"
)
""
"
\n\n\n
hello"
`
shouldParse
`
"hello"
it
"parses using the inner parser (with newlines and whitespace)"
$
do
parse
(
spaced
$
string
"hello"
)
""
"
\n
\n
\n
hello"
`
shouldParse
`
"hello"
-- manyCharsTill
describe
"manyCharsTill"
$
do
it
"parses empty strings (with EOL)"
$
do
parse
(
manyCharsTill
eol
)
""
"
\n
"
`
shouldParse
`
""
it
"parses strings (with EOL)"
$
do
parse
(
manyCharsTill
eol
)
""
"hello
\n
"
`
shouldParse
`
"hello"
it
"fails on empty strings (without EOL)"
$
do
parse
(
manyCharsTill
eol
)
""
`
shouldFailOn
`
""
-- someCharsTill
describe
"someCharsTill"
$
do
it
"fails on empty strings (with EOL)"
$
do
parse
(
someCharsTill
eol
)
""
`
shouldFailOn
`
"
\n
"
it
"parses strings (with EOL)"
$
do
parse
(
someCharsTill
eol
)
""
"hello
\n
"
`
shouldParse
`
"hello"
it
"fails on empty strings (without EOL)"
$
do
parse
(
someCharsTill
eol
)
""
`
shouldFailOn
`
""
-- commitType
describe
"commitType"
$
do
it
"parses a commit type"
$
do
parse
commitType
""
"feat"
`
shouldParse
`
CTFeature
it
"should fail if the commit type is unknown"
$
do
parse
commitType
""
`
shouldFailOn
`
"omg"
-- breakingChange
describe
"breakingChange"
$
do
it
"parses a breaking change without a body"
$
do
parse
breakingChange
""
"BREAKING CHANGE: This will require a new OS upgrade.
\n
"
`
shouldParse
`
BreakingChange
"This will require a new OS upgrade."
Nothing
it
"parses a breaking change with a body"
$
do
parse
breakingChange
""
"BREAKING CHANGE: This will require a new OS upgrade.
\n\
\\n\
\
Go to example.org to download a new OS."
`
shouldParse
`
BreakingChange
"This will require a new OS upgrade."
(
Just
"Go to example.org to download a new OS."
)
-- commit
describe
"commit"
$
do
it
"parses a regular commit"
$
do
parse
commit
""
"feat(src): Add README file"
`
shouldParse
`
(
PCConventional
$
ConventionalCommit
{
_ccType
=
CTFeature
,
_ccScope
=
"src"
,
_ccSubject
=
"Add README file"
,
_ccBody
=
""
,
_ccBreakingChanges
=
[]
,
_ccAffectedTickets
=
[]
}
)
it
"parses a regular commit with breaking changes and a body"
$
do
parse
commit
""
"feat(src): Add README file
\n\
\\n\
\
This is an example commit body.
\n\
\\n\
\
BREAKING CHANGE: This will require a new OS upgrade.
\n\
\\n\
\
Go to example.org to download a new OS.
\n
"
`
shouldParse
`
(
PCConventional
$
ConventionalCommit
{
_ccType
=
CTFeature
,
_ccScope
=
"src"
,
_ccSubject
=
"Add README file"
,
_ccBody
=
"This is an example commit body."
,
_ccBreakingChanges
=
[
BreakingChange
"This will require a new OS upgrade."
(
Just
"Go to example.org to download a new OS."
)],
_ccAffectedTickets
=
[]
}
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment