Skip to content

Commit

Permalink
Merge pull request #662 from tfheen/master
Browse files Browse the repository at this point in the history
Include directory in slack webhook message
  • Loading branch information
lkysow committed Jun 5, 2019
2 parents 1fa621d + 4944ee1 commit 708fa0c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/events/project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext)
Repo: ctx.BaseRepo,
Pull: ctx.Pull,
Success: err == nil,
Directory: ctx.RepoRelDir,
})
if err != nil {
return "", "", fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n"))
Expand Down
11 changes: 11 additions & 0 deletions server/events/webhooks/slack_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func (d *DefaultSlackClient) createAttachments(applyResult ApplyResult) []slack.
}

text := fmt.Sprintf("Apply %s for <%s|%s>", successWord, applyResult.Pull.URL, applyResult.Repo.FullName)
directory := applyResult.Directory
// Since "." looks weird, replace it with "/" to make it clear this is the root.
if directory == "." {
directory = "/"
}

attachment := slack.Attachment{
Color: colour,
Text: text,
Expand All @@ -112,6 +118,11 @@ func (d *DefaultSlackClient) createAttachments(applyResult ApplyResult) []slack.
Value: applyResult.User.Username,
Short: true,
},
{
Title: "Directory",
Value: directory,
Short: true,
},
},
}
return []slack.Attachment{attachment}
Expand Down
10 changes: 10 additions & 0 deletions server/events/webhooks/slack_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func TestPostMessage_Success(t *testing.T) {
Value: result.User.Username,
Short: true,
},
{
Title: "Directory",
Value: result.Directory,
Short: true,
},
},
}}
expParams.AsUser = false
Expand Down Expand Up @@ -148,6 +153,11 @@ func TestPostMessage_Error(t *testing.T) {
Value: result.User.Username,
Short: true,
},
{
Title: "Directory",
Value: result.Directory,
Short: true,
},
},
}}
expParams.AsUser = false
Expand Down
1 change: 1 addition & 0 deletions server/events/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ApplyResult struct {
Pull models.PullRequest
User models.User
Success bool
Directory string
}

// MultiWebhookSender sends multiple webhooks for each one it's configured for.
Expand Down

0 comments on commit 708fa0c

Please sign in to comment.