Skip to content

Commit cfb32ba

Browse files
authored
add a message to show how much work was done in each MR (#397)
1 parent 921e351 commit cfb32ba

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

pkg/events/check.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ func (ce *CheckEvent) Process(ctx context.Context) error {
325325

326326
ce.logger.Info().Msg("Finished")
327327

328-
comment := ce.vcsNote.BuildComment(ctx, start, ce.pullRequest.SHA, ce.ctr.Config.LabelFilter, ce.ctr.Config.ShowDebugInfo, ce.ctr.Config.Identifier)
328+
comment := ce.vcsNote.BuildComment(
329+
ctx, start, ce.pullRequest.SHA, ce.ctr.Config.LabelFilter,
330+
ce.ctr.Config.ShowDebugInfo, ce.ctr.Config.Identifier,
331+
len(ce.addedAppsSet), int(ce.appsSent),
332+
)
329333

330334
if err = ce.ctr.VcsClient.UpdateMessage(ctx, ce.vcsNote, comment); err != nil {
331335
return errors.Wrap(err, "failed to push comment")

pkg/msg/message.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ func init() {
127127
hostname, _ = os.Hostname()
128128
}
129129

130-
func (m *Message) buildFooter(start time.Time, commitSHA, labelFilter string, showDebugInfo bool) string {
130+
func (m *Message) buildFooter(
131+
start time.Time, commitSHA, labelFilter string, showDebugInfo bool,
132+
appsChecked, totalChecked int,
133+
) string {
131134
if !showDebugInfo {
132135
return fmt.Sprintf("<small> _Done. CommitSHA: %s_ <small>\n", commitSHA)
133136
}
@@ -138,11 +141,15 @@ func (m *Message) buildFooter(start time.Time, commitSHA, labelFilter string, sh
138141
}
139142
duration := time.Since(start)
140143

141-
return fmt.Sprintf("<small> _Done: Pod: %s, Dur: %v, SHA: %s%s_ <small>\n", hostname, duration, pkg.GitCommit, envStr)
144+
return fmt.Sprintf("<small> _Done: Pod: %s, Dur: %v, SHA: %s%s_ <small>, Apps Checked: %d, Total Checks: %d\n",
145+
hostname, duration.Round(time.Second), pkg.GitCommit, envStr, appsChecked, totalChecked)
142146
}
143147

144148
// BuildComment iterates the map of all apps in this message, building a final comment from their current state
145-
func (m *Message) BuildComment(ctx context.Context, start time.Time, commitSHA, labelFilter string, showDebugInfo bool, identifier string) string {
149+
func (m *Message) BuildComment(
150+
ctx context.Context, start time.Time, commitSHA, labelFilter string, showDebugInfo bool, identifier string,
151+
appsChecked, totalChecked int,
152+
) string {
146153
_, span := tracer.Start(ctx, "buildComment")
147154
defer span.End()
148155

@@ -203,7 +210,7 @@ func (m *Message) BuildComment(ctx context.Context, start time.Time, commitSHA,
203210
sb.WriteString("No changes")
204211
}
205212

206-
footer := m.buildFooter(start, commitSHA, labelFilter, showDebugInfo)
213+
footer := m.buildFooter(start, commitSHA, labelFilter, showDebugInfo, appsChecked, totalChecked)
207214
sb.WriteString(fmt.Sprintf("\n\n%s", footer))
208215

209216
return sb.String()

pkg/msg/message_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestBuildComment(t *testing.T) {
3131
}
3232
m := NewMessage("message", 1, 2, fakeEmojiable{":test:"})
3333
m.apps = appResults
34-
comment := m.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier")
34+
comment := m.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier", 1, 2)
3535
assert.Equal(t, `# Kubechecks test-identifier Report
3636
<details>
3737
<summary>
@@ -79,7 +79,7 @@ func TestBuildComment_SkipUnchanged(t *testing.T) {
7979

8080
m := NewMessage("message", 1, 2, fakeEmojiable{":test:"})
8181
m.apps = appResults
82-
comment := m.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier")
82+
comment := m.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier", 1, 2)
8383
assert.Equal(t, `# Kubechecks test-identifier Report
8484
<details>
8585
<summary>
@@ -183,7 +183,7 @@ func TestMultipleItemsWithNewlines(t *testing.T) {
183183
Summary: "summary-2",
184184
Details: "detail-2",
185185
})
186-
result := message.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier")
186+
result := message.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier", 1, 2)
187187

188188
// header rows need double newlines before and after
189189
index := 0

0 commit comments

Comments
 (0)