Skip to content

Commit

Permalink
chore: avoid listing all metapipeline sub steps as they are quite ver…
Browse files Browse the repository at this point in the history
…bose and not that interesting to be notified about
  • Loading branch information
rawlingsj committed Mar 18, 2020
1 parent 45b9b11 commit fc19f9a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
8 changes: 2 additions & 6 deletions build-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ VERSION=$1
make linux && docker build -t rawlingsj80/slack:$VERSION . && \
docker push rawlingsj80/slack:$VERSION

helm uninstall slack || true
cd charts/slack && helm install --set googleSecretsManager=true --set image.repository=rawlingsj80/slack --set image.tag=$VERSION slack .
# helm upgrade slack jx-labs/slack
helm upgrade --set googleSecretsManager=true --set image.repository=rawlingsj80/slack --set image.tag=$VERSION slack jx-labs/slack

#kubectl apply -f ~/.jx/localSecrets/slack.yaml

# hack until we watch for new SlackBot kinds being added
#kubectl scale deploy slack-slack --replicas 0
#kubectl scale deploy slack-slack --replicas 1

sleep 10

kubectl logs -f deploy/slack-slack
32 changes: 20 additions & 12 deletions pkg/slackbot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,16 +731,16 @@ func (o *SlackBotOptions) createAttachments(activity *jenkinsv1.PipelineActivity
stage := step.Stage
promote := step.Promote
if stage != nil {
return o.createStageAttachments(activity, step, stage)
return o.createStageAttachments(activity, stage)
} else if promote != nil {
return o.createPromoteAttachments(activity, step, promote)
return o.createPromoteAttachments(activity, promote)
}
return []slack.Attachment{}

}

func (o *SlackBotOptions) createStageAttachments(activity *jenkinsv1.PipelineActivity,
step *jenkinsv1.PipelineActivityStep, stage *jenkinsv1.StageActivityStep) []slack.Attachment {
stage *jenkinsv1.StageActivityStep) []slack.Attachment {
name := stage.Name
if name == "" {
name = "Stage"
Expand All @@ -751,16 +751,20 @@ func (o *SlackBotOptions) createStageAttachments(activity *jenkinsv1.PipelineAct
name = "release " + link(version, activity.Spec.ReleaseNotesURL)
}
}

attachments := []slack.Attachment{
o.createStepAttachment(&stage.CoreActivityStep, name, "", ""),
o.createStepAttachment(stage.CoreActivityStep, name, "", ""),
}
for _, step := range stage.Steps {
attachments = append(attachments, o.createStepAttachment(&step, "", "", ""))
if stage.CoreActivityStep.Name != "meta pipeline" {
for _, step := range stage.Steps {
attachments = append(attachments, o.createStepAttachment(step, "", "", ""))
}
}

return attachments
}

func (o *SlackBotOptions) createStepAttachment(step *jenkinsv1.CoreActivityStep, name string, description string,
func (o *SlackBotOptions) createStepAttachment(step jenkinsv1.CoreActivityStep, name string, description string,
iconUrl string) slack.Attachment {
text := step.Description
if description != "" {
Expand All @@ -774,6 +778,10 @@ func (o *SlackBotOptions) createStepAttachment(step *jenkinsv1.CoreActivityStep,
if textName == "" {
textName = step.Name
}
// wonder if we should have a map of stage text to slack friendly descriptions rather than this below?
if textName == "meta pipeline" {
textName = "Generating pipeline"
}
stepStatus := step.Status
textMessage := o.statusString(stepStatus) + " " + textName
if text != "" {
Expand All @@ -788,24 +796,24 @@ func (o *SlackBotOptions) createStepAttachment(step *jenkinsv1.CoreActivityStep,
}
}

func (o *SlackBotOptions) createPromoteAttachments(activity *jenkinsv1.PipelineActivity, step *jenkinsv1.PipelineActivityStep, parent *jenkinsv1.PromoteActivityStep) []slack.Attachment {
func (o *SlackBotOptions) createPromoteAttachments(activity *jenkinsv1.PipelineActivity, parent *jenkinsv1.PromoteActivityStep) []slack.Attachment {
envName := strings.Title(parent.Environment)
attachments := []slack.Attachment{
o.createStepAttachment(&parent.CoreActivityStep, "promote to *"+envName+"*", "", ""),
o.createStepAttachment(parent.CoreActivityStep, "promote to *"+envName+"*", "", ""),
}

pullRequest := parent.PullRequest
update := parent.Update
if pullRequest != nil {
iconUrl := pullRequestIcon(pullRequest)
attachments = append(attachments, o.createStepAttachment(&pullRequest.CoreActivityStep, "PR", describePromotePullRequest(activity, pullRequest), iconUrl))
attachments = append(attachments, o.createStepAttachment(pullRequest.CoreActivityStep, "PR", describePromotePullRequest(activity, pullRequest), iconUrl))
}
if update != nil {
attachments = append(attachments, o.createStepAttachment(&update.CoreActivityStep, "update", describePromoteUpdate(update), ""))
attachments = append(attachments, o.createStepAttachment(update.CoreActivityStep, "update", describePromoteUpdate(update), ""))
}
appURL := parent.ApplicationURL
if appURL != "" {
attachments = append(attachments, o.createStepAttachment(&update.CoreActivityStep, ":star: application now in "+link(envName, appURL), "", ""))
attachments = append(attachments, o.createStepAttachment(update.CoreActivityStep, ":star: application now in "+link(envName, appURL), "", ""))
}
return attachments
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/slackbot/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestSlackBotOptions_createAttachments(t *testing.T) {
wantNumberOfSteps int
want []slack.Attachment
}{
{name: "multi_step_stage", fields: struct{ filename string }{filename: "stage_multiple_steps.yaml"}, wantNumberOfSteps: 19, want: nil},
{name: "multi_step_stage", fields: struct{ filename string }{filename: "stage_multiple_steps.yaml"}, wantNumberOfSteps: 11, want: nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit fc19f9a

Please sign in to comment.