Merge pull request #662 from tfheen/master

Include directory in slack webhook message
This commit is contained in:
Luke Kysow
2019-06-05 11:30:40 +01:00
committed by GitHub
4 changed files with 23 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,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,
@@ -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}

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.