Skip to content

Commit

Permalink
Merge pull request #60 from rtCamp/add/commit-details
Browse files Browse the repository at this point in the history
Add commit details to the slack notification
  • Loading branch information
mrrobot47 authored Dec 8, 2020
2 parents 1304fe5 + c2b6410 commit afda1f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SLACK_COLOR | `good` (green) | You
SLACK_MESSAGE | Generated from git commit message. | The main Slack message in attachment. It is advised not to override this.
SLACK_TITLE | Message | Title to use before main Slack message.
SLACK_FOOTER | Powered By rtCamp's GitHub Actions Library | Slack message footer.
MSG_MINIMAL | - | If set to `true`, removes: `Ref`, `Event` and `Actions URL` from the message. You can optionally whitelist any of these 3 removed values by passing it comma separated to the variable instead of `true`. (ex: `MSG_MINIMAL: event` or `MSG_MINIMAL: ref,actions url`, etc.)
MSG_MINIMAL | - | If set to `true`, removes: `Ref`, `Event`, `Actions URL` and `Commit` from the message. You can optionally whitelist any of these 4 removed values by passing it comma separated to the variable instead of `true`. (ex: `MSG_MINIMAL: event` or `MSG_MINIMAL: ref,actions url`, etc.)

You can see the action block with all variables as below:

Expand Down
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func main() {
os.Setenv("GITHUB_WORKFLOW", "Link to action run")
}

long_sha := os.Getenv("GITHUB_SHA")
commit_sha := long_sha[0:6]

minimal := os.Getenv(EnvMinimal)
fields := []Field{}
if minimal == "true" {
Expand All @@ -87,7 +90,7 @@ func main() {
Short: false,
},
}
for _,requiredField := range requiredFields {
for _, requiredField := range requiredFields {
switch strings.ToLower(requiredField) {
case "ref":
field := []Field{
Expand All @@ -112,7 +115,16 @@ func main() {
{
Title: "Actions URL",
Value: "<https://github.com/" + os.Getenv("GITHUB_REPOSITORY") + "/commit/" + os.Getenv("GITHUB_SHA") + "/checks|" + os.Getenv("GITHUB_WORKFLOW") + ">",
Short: false,
Short: true,
},
}
mainFields = append(field, mainFields...)
case "commit":
field := []Field{
{
Title: "Commit",
Value: "<https://github.com/" + os.Getenv("GITHUB_REPOSITORY") + "/commit/" + os.Getenv("GITHUB_SHA") + "|" + commit_sha + ">",
Short: true,
},
}
mainFields = append(field, mainFields...)
Expand All @@ -133,7 +145,12 @@ func main() {
{
Title: "Actions URL",
Value: "<https://github.com/" + os.Getenv("GITHUB_REPOSITORY") + "/commit/" + os.Getenv("GITHUB_SHA") + "/checks|" + os.Getenv("GITHUB_WORKFLOW") + ">",
Short: false,
Short: true,
},
{
Title: "Commit",
Value: "<https://github.com/" + os.Getenv("GITHUB_REPOSITORY") + "/commit/" + os.Getenv("GITHUB_SHA") + "|" + commit_sha + ">",
Short: true,
},
{
Title: os.Getenv(EnvSlackTitle),
Expand Down

0 comments on commit afda1f7

Please sign in to comment.