Skip to content

Commit

Permalink
fix: limit the length of the pipeline description
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Sep 11, 2024
1 parent 7e12fd1 commit 1fe94c5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (

require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/aquilax/truncate v1.0.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/aquilax/truncate v1.0.0 h1:UgIGS8U/aZ4JyOJ2h3xcF5cSQ06+gGBnjxH2RUHJe0U=
github.com/aquilax/truncate v1.0.0/go.mod h1:BeMESIDMlvlS3bmg4BVvBbbZUNwWtS8uzYPAKXwwhLw=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down
3 changes: 2 additions & 1 deletion pkg/scm/gitlab/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

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

description = scm.TruncateText(evalError.Error(), 250)
description = truncate.Truncate(evalError.Error(), 250, "...", truncate.PositionEnd)
}

_, response, err := client.wrapped.Commits.SetCommitStatus(state.ProjectID(ctx), state.CommitSHA(ctx), &go_gitlab.SetCommitStatusOptions{
Expand Down
21 changes: 0 additions & 21 deletions pkg/scm/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"
"regexp"
"strings"
"unicode"
)

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

func TruncateText(text string, maxLen int) string {
lastSpaceIx := maxLen
curLen := 0

for i, r := range text {
if unicode.IsSpace(r) {
lastSpaceIx = i
}

curLen++

if curLen > maxLen {
return text[:lastSpaceIx] + "..."
}
}

// If here, string is shorter or equal to maxLen
return text
}

// buildPatternRegex compiles a new regexp object from a gitignore-style pattern string
func buildPatternRegex(pattern string) (*regexp.Regexp, error) {
// Handle specific edge cases first
Expand Down

0 comments on commit 1fe94c5

Please sign in to comment.