-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#809] Parse commit message events on tags rather than full header
To support VCS that don't manage emojies - extract CommitMessage, functions, and tests to their own files - spot commit message status on string containing tag rather than matching full header - add test for this new tag matching - refactoring and code cleanup
- Loading branch information
Showing
5 changed files
with
192 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright (c) 2024 Murex | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
package engine | ||
|
||
import "fmt" | ||
|
||
// CommitMessage is a struct that holds information of the commit message | ||
type CommitMessage struct { | ||
Emoji rune | ||
Tag string | ||
Description string | ||
} | ||
|
||
var ( | ||
messagePassed = CommitMessage{Emoji: '✅', Tag: "[TCR - PASSED]", Description: "tests passing"} | ||
messageFailed = CommitMessage{Emoji: '❌', Tag: "[TCR - FAILED]", Description: "tests failing"} | ||
messageReverted = CommitMessage{Emoji: '⏪', Tag: "[TCR - REVERTED]", Description: "revert changes"} | ||
) | ||
|
||
func (cm CommitMessage) toString(withEmoji bool) string { | ||
textOnly := fmt.Sprintf("%s %s", cm.Tag, cm.Description) | ||
if withEmoji { | ||
return fmt.Sprintf("%c %s", cm.Emoji, textOnly) | ||
} | ||
return textOnly | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright (c) 2024 Murex | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
package engine | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_building_commit_messages(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
commitMessage CommitMessage | ||
withEmoji bool | ||
expected string | ||
}{ | ||
{ | ||
"Passing Message", | ||
CommitMessage{ | ||
Emoji: '✅', | ||
Tag: "[TCR - PASSED]", | ||
Description: "tests passing", | ||
}, | ||
true, | ||
passedCommitMessage, | ||
}, { | ||
"Failing Message", | ||
CommitMessage{ | ||
Emoji: '❌', | ||
Tag: "[TCR - FAILED]", | ||
Description: "tests failing", | ||
}, | ||
true, | ||
failedCommitMessage, | ||
}, { | ||
"Reverting Message", | ||
CommitMessage{ | ||
Emoji: '⏪', | ||
Tag: "[TCR - REVERTED]", | ||
Description: "revert changes", | ||
}, | ||
true, | ||
revertedCommitMessage, | ||
}, { | ||
"Passing Message without Emoji", | ||
CommitMessage{ | ||
Emoji: '✅', | ||
Tag: "[TCR - PASSED]", | ||
Description: "tests passing", | ||
}, | ||
false, | ||
"[TCR - PASSED] tests passing", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.desc, func(t *testing.T) { | ||
assert.Equal(t, test.expected, test.commitMessage.toString(test.withEmoji)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters