Skip to content

Commit 7e12fd1

Browse files
committed
fix: limit the length of the pipeline description
1 parent a0f82a4 commit 7e12fd1

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

pkg/scm/gitlab/client.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,22 @@ func (client *Client) Stop(ctx context.Context, evalError error, allowPipelineFa
205205
}
206206

207207
var (
208-
status = go_gitlab.Success
209-
message = "OK"
208+
status = go_gitlab.Success
209+
description = "OK"
210210
)
211211

212212
if evalError != nil {
213213
if allowPipelineFailure {
214214
status = go_gitlab.Failed
215215
}
216216

217-
message = evalError.Error()
217+
description = scm.TruncateText(evalError.Error(), 250)
218218
}
219219

220220
_, response, err := client.wrapped.Commits.SetCommitStatus(state.ProjectID(ctx), state.CommitSHA(ctx), &go_gitlab.SetCommitStatusOptions{
221221
State: status,
222222
Context: pipelineName,
223-
Description: scm.Ptr(message),
223+
Description: scm.Ptr(description),
224224
TargetURL: targetURL,
225225
})
226226

pkg/scm/helpers.go

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"path/filepath"
66
"regexp"
77
"strings"
8+
"unicode"
89
)
910

1011
// Ptr is a helper that returns a pointer to v.
@@ -74,6 +75,26 @@ func FindModifiedFiles(files []string, patterns ...string) []string {
7475
return output
7576
}
7677

78+
func TruncateText(text string, maxLen int) string {
79+
lastSpaceIx := maxLen
80+
curLen := 0
81+
82+
for i, r := range text {
83+
if unicode.IsSpace(r) {
84+
lastSpaceIx = i
85+
}
86+
87+
curLen++
88+
89+
if curLen > maxLen {
90+
return text[:lastSpaceIx] + "..."
91+
}
92+
}
93+
94+
// If here, string is shorter or equal to maxLen
95+
return text
96+
}
97+
7798
// buildPatternRegex compiles a new regexp object from a gitignore-style pattern string
7899
func buildPatternRegex(pattern string) (*regexp.Regexp, error) {
79100
// Handle specific edge cases first

0 commit comments

Comments
 (0)