Include directory in slack webhook message

Fixes: https://github.com/runatlantis/atlantis/issues/660
This commit is contained in:
Tollef Fog Heen
2019-06-04 10:05:25 +02:00
committed by Tollef Fog Heen
parent 1fa621dc83
commit 8a3e342344
4 changed files with 22 additions and 0 deletions

View File

@@ -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"))

View File

@@ -98,6 +98,11 @@ 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
if directory == "." {
directory = "/"
}
attachment := slack.Attachment{
Color: colour,
Text: text,
@@ -112,6 +117,11 @@ func (d *DefaultSlackClient) createAttachments(applyResult ApplyResult) []slack.
Value: applyResult.User.Username,
Short: true,
},
{
Title: "Directory",
Value: directory,
Short: true,
},
},
}
return []slack.Attachment{attachment}

View File

@@ -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
@@ -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

View File

@@ -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.