Skip to content

Commit

Permalink
Add automatic status to color parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-mitka committed Jan 12, 2021
1 parent ae42232 commit 7fe5434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SLACK_USERNAME | `rtBot` | Cust
SLACK_MSG_AUTHOR | `$GITHUB_ACTOR` (The person who triggered action). | GitHub username of the person who has triggered the action. In case you want to modify it, please specify corrent GitHub username.
SLACK_ICON | ![rtBot Avatar](https://github.com/rtBot.png?size=32) | User/Bot icon shown with Slack message. It uses the URL supplied to this env variable to display the icon in slack message.
SLACK_ICON_EMOJI | - | User/Bot icon shown with Slack message, in case you do not wish to add a URL for slack icon as above, you can set slack emoji in this env variable. Example value: `:bell:` or any other valid slack emoji.
SLACK_COLOR | `good` (green) | You can pass an RGB value like `#efefef` which would change color on left side vertical line of Slack message.
SLACK_COLOR | `good` (green) | You can pass ${{job.status}} for automatic coloring or an RGB value like `#efefef` which would change color on left side vertical line of Slack message.
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.
Expand All @@ -61,7 +61,7 @@ You can see the action block with all variables as below:
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: general
SLACK_COLOR: '#3278BD'
SLACK_COLOR: ${{ job.status }}
SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_MESSAGE: 'Post Content :rocket:'
SLACK_TITLE: Post Title
Expand All @@ -77,7 +77,7 @@ The `Site` and `SSH Host` details are only available if this action is run after

## Hashicorp Vault (Optional)

This GitHub action supports [Hashicorp Vault](https://www.vaultproject.io/).
This GitHub action supports [Hashicorp Vault](https://www.vaultproject.io/).

To enable Hashicorp Vault support, please define following GitHub secrets:

Expand Down
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ func main() {
fields = append(newfields, fields...)
}

color := ""
switch os.Getenv(EnvSlackColor) {
case "success":
color = "good"
case "cancelled":
color = "#808080"
case "failure":
color = "danger"
default:
color = envOr(EnvSlackColor, "good")
}

msg := Webhook{
UserName: os.Getenv(EnvSlackUserName),
IconURL: os.Getenv(EnvSlackIcon),
Expand All @@ -186,7 +198,7 @@ func main() {
Attachments: []Attachment{
{
Fallback: envOr(EnvSlackMessage, "GITHUB_ACTION="+os.Getenv("GITHUB_ACTION")+" \n GITHUB_ACTOR="+os.Getenv("GITHUB_ACTOR")+" \n GITHUB_EVENT_NAME="+os.Getenv("GITHUB_EVENT_NAME")+" \n GITHUB_REF="+os.Getenv("GITHUB_REF")+" \n GITHUB_REPOSITORY="+os.Getenv("GITHUB_REPOSITORY")+" \n GITHUB_WORKFLOW="+os.Getenv("GITHUB_WORKFLOW")),
Color: envOr(EnvSlackColor, "good"),
Color: color,
AuthorName: envOr(EnvGithubActor, ""),
AuthorLink: "http://github.com/" + os.Getenv(EnvGithubActor),
AuthorIcon: "http://github.com/" + os.Getenv(EnvGithubActor) + ".png?size=32",
Expand Down

0 comments on commit 7fe5434

Please sign in to comment.