Skip to content

Commit 926d83e

Browse files
authored
return the branch, tag, or no value (#130)
1 parent 74f9d87 commit 926d83e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

googlechat/main.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -170,31 +170,43 @@ func (g *googlechatNotifier) writeMessage(build *cbpb.Build) (*chat.Message, err
170170

171171
repo_name := build.Substitutions["REPO_NAME"]
172172
trigger_name := build.Substitutions["TRIGGER_NAME"]
173-
branch_name := build.Substitutions["BRANCH_NAME"]
174173
commit := build.Substitutions["SHORT_SHA"]
175174

175+
// Branch, Tag, or None.
176+
branch_tag_label := "Branch"
177+
branch_tag_value := build.Substitutions["BRANCH_NAME"]
178+
179+
if branch_tag_value == "" {
180+
branch_tag_label = "Tag"
181+
branch_tag_value = build.Substitutions["TAG_NAME"]
182+
183+
if branch_tag_value == "" {
184+
branch_tag_label = "Branch/Tag"
185+
branch_tag_value = "[no branch or tag]"
186+
}
187+
}
188+
176189
card.Header.Subtitle = fmt.Sprintf("%s on %s", trigger_name, build.ProjectId)
177190

178191
build_info := &chat.Section{
179192
Header: "Trigger information",
180193
Widgets: []*chat.WidgetMarkup{
181194
{
182-
183195
KeyValue: &chat.KeyValue{
184196
TopLabel: "Trigger",
185197
Content: trigger_name,
186198
},
187199
},
188200
{
189201
KeyValue: &chat.KeyValue{
190-
TopLabel: `Repo`,
202+
TopLabel: "Repo",
191203
Content: repo_name,
192204
},
193205
},
194206
{
195207
KeyValue: &chat.KeyValue{
196-
TopLabel: "Branch",
197-
Content: branch_name,
208+
TopLabel: branch_tag_label,
209+
Content: branch_tag_value,
198210
},
199211
},
200212
{

0 commit comments

Comments
 (0)