From c3309269e5c99c6bad33121add941de946fd47bb Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Tue, 1 Feb 2022 13:02:50 -0800 Subject: [PATCH 1/2] fix(bitbucketcloud): Ensure status key has at most 40 characters --- server/events/vcs/bitbucketcloud/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/events/vcs/bitbucketcloud/client.go b/server/events/vcs/bitbucketcloud/client.go index b926c8cf4a..f84c99d1e3 100644 --- a/server/events/vcs/bitbucketcloud/client.go +++ b/server/events/vcs/bitbucketcloud/client.go @@ -179,6 +179,11 @@ func (b *Client) UpdateStatus(repo models.Repo, pull models.PullRequest, status url = b.AtlantisURL } + // Ensure key has at most 40 characters + if len(src) > 37 { + src = src[:37] + "..." + } + bodyBytes, err := json.Marshal(map[string]string{ "key": src, "url": url, From 0d0458fa0b53b8649c2d019914e0bfa8ba153e23 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Tue, 1 Feb 2022 13:47:43 -0800 Subject: [PATCH 2/2] Use fmt.Sprintf() --- server/events/vcs/bitbucketcloud/client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/events/vcs/bitbucketcloud/client.go b/server/events/vcs/bitbucketcloud/client.go index f84c99d1e3..598bce5df6 100644 --- a/server/events/vcs/bitbucketcloud/client.go +++ b/server/events/vcs/bitbucketcloud/client.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "unicode/utf8" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/models" @@ -180,8 +181,8 @@ func (b *Client) UpdateStatus(repo models.Repo, pull models.PullRequest, status } // Ensure key has at most 40 characters - if len(src) > 37 { - src = src[:37] + "..." + if utf8.RuneCountInString(src) > 40 { + src = fmt.Sprintf("%.37s...", src) } bodyBytes, err := json.Marshal(map[string]string{