Skip to content

Commit 1fe94c5

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

File tree

4 files changed

+5
-22
lines changed

4 files changed

+5
-22
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535

3636
require (
3737
github.com/agnivade/levenshtein v1.1.1 // indirect
38+
github.com/aquilax/truncate v1.0.0 // indirect
3839
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
3940
github.com/bahlo/generic-list-go v0.2.0 // indirect
4041
github.com/buger/jsonparser v1.1.1 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB
44
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
55
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
66
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
7+
github.com/aquilax/truncate v1.0.0 h1:UgIGS8U/aZ4JyOJ2h3xcF5cSQ06+gGBnjxH2RUHJe0U=
8+
github.com/aquilax/truncate v1.0.0/go.mod h1:BeMESIDMlvlS3bmg4BVvBbbZUNwWtS8uzYPAKXwwhLw=
79
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
810
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
911
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=

pkg/scm/gitlab/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"time"
1313

14+
"github.com/aquilax/truncate"
1415
"github.com/hasura/go-graphql-client"
1516
"github.com/jippi/scm-engine/pkg/scm"
1617
"github.com/jippi/scm-engine/pkg/state"
@@ -214,7 +215,7 @@ func (client *Client) Stop(ctx context.Context, evalError error, allowPipelineFa
214215
status = go_gitlab.Failed
215216
}
216217

217-
description = scm.TruncateText(evalError.Error(), 250)
218+
description = truncate.Truncate(evalError.Error(), 250, "...", truncate.PositionEnd)
218219
}
219220

220221
_, response, err := client.wrapped.Commits.SetCommitStatus(state.ProjectID(ctx), state.CommitSHA(ctx), &go_gitlab.SetCommitStatusOptions{

pkg/scm/helpers.go

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

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

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-
9877
// buildPatternRegex compiles a new regexp object from a gitignore-style pattern string
9978
func buildPatternRegex(pattern string) (*regexp.Regexp, error) {
10079
// Handle specific edge cases first

0 commit comments

Comments
 (0)