Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include directory in slack webhook message #662

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == "." {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if 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