Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
0267cb89
Unverified
Commit
0267cb89
authored
Oct 26, 2021
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf(changelog): use regex-match instead of `sed` to parse commit subjects
parent
140bfa84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
changelog.sh
tools/changelog.sh
+20
-10
No files found.
tools/changelog.sh
View file @
0267cb89
...
...
@@ -52,10 +52,15 @@ function parse-commit {
# make a breaking change
function
commit:type
{
local type
=
"
$(
sed
-E
's/^([a-zA-Z_\-]+)(\(.+\))?!?: .+$/\1/'
<<<
"
$1
"
)
"
local type
# Parse commit type from the subject
if
[[
"
$1
"
=
~
'^([a-zA-Z_\-]+)(\(.+\))?!?: .+$'
]]
;
then
type
=
"
${
match
[1]
}
"
fi
# If $type doesn't appear in $TYPES array mark it as 'other'
if
[[
-n
"
${
(k)TYPES[(i)
$type
]
}
"
]]
;
then
if
[[
-n
"
$
type
"
&&
-n
"
$
{
(k)TYPES[(i)
$type
]
}
"
]]
;
then
echo
$type
else
echo
other
...
...
@@ -66,17 +71,18 @@ function parse-commit {
local
scope
# Try to find scope in "type(<scope>):" format
scope
=
$(
sed
-nE
's/^[a-zA-Z_\-]+\((.+)\)!?: .+$/\1/p'
<<<
"
$1
"
)
if
[[
-n
"
$scope
"
]]
;
then
echo
"
$scope
"
if
[[
"
$1
"
=
~
'^[a-zA-Z_\-]+\((.+)\)!?: .+$'
]]
;
then
echo
"
${
match
[1]
}
"
return
fi
# If no scope found, try to find it in "<scope>:" format
# Make sure it's not a type before printing it
scope
=
$(
sed
-nE
's/^([a-zA-Z_\-]+): .+$/\1/p'
<<<
"
$1
"
)
if
[[
-z
"
${
(k)TYPES[(i)
$scope
]
}
"
]]
;
then
echo
"
$scope
"
if
[[
"
$1
"
=
~
'^([a-zA-Z_\-]+): .+$'
]]
;
then
scope
=
"
${
match
[1]
}
"
# Make sure it's not a type before printing it
if
[[
-z
"
${
(k)TYPES[(i)
$scope
]
}
"
]]
;
then
echo
"
$scope
"
fi
fi
}
...
...
@@ -84,7 +90,11 @@ function parse-commit {
# Only display the relevant part of the commit, i.e. if it has the format
# type[(scope)!]: subject, where the part between [] is optional, only
# displays subject. If it doesn't match the format, returns the whole string.
sed
-E
's/^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$/\2/'
<<<
"
$1
"
if
[[
"
$1
"
=
~
'^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$'
]]
;
then
echo
"
${
match
[2]
}
"
else
echo
"
$1
"
fi
}
# Return subject if the body or subject match the breaking change format
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment