Skip to content

Commit 6e92359

Browse files
committed
Add pilot review
Signed-off-by: Mmadu Manasseh <manasseh.mmadu@zapier.com>
1 parent 251ab64 commit 6e92359

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

pkg/msg/message.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func (m *Message) BuildComment(
226226
comments = append(comments, sb.String())
227227
sb.Reset()
228228
sb.WriteString(header)
229+
// continuedHeader contains both the header and the comment about the continued fromprevious comment
230+
// header is written here but the rest of the content is written from the vcs PostMessage/UpdateMessage function
231+
// that's why we're setting the contentLength to the length of the continuedHeader
229232
contentLength = len(continuedHeader)
230233

231234
}

pkg/vcs/github_client/backoff.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package github_client
2+
3+
import (
4+
"time"
5+
6+
"github.com/cenkalti/backoff/v4"
7+
)
8+
9+
// getBackOff returns a backoff pointer to use to retry requests
10+
func getBackOff() *backoff.ExponentialBackOff {
11+
12+
// Lets setup backoff logic to retry this request for 1 minute
13+
bOff := backoff.NewExponentialBackOff()
14+
bOff.InitialInterval = 60 * time.Second
15+
bOff.MaxInterval = 10 * time.Second
16+
bOff.RandomizationFactor = 0
17+
bOff.MaxElapsedTime = 180 * time.Second
18+
19+
return bOff
20+
}

pkg/vcs/github_client/message.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"strings"
7-
"time"
87

98
"github.com/cenkalti/backoff/v5"
109
"github.com/google/go-github/v62/github"
@@ -26,10 +25,8 @@ func (c *Client) PostMessage(ctx context.Context, pr vcs.PullRequest, message st
2625

2726
log.Debug().Msgf("Posting message to PR %d in repo %s", pr.CheckID, pr.FullName)
2827

29-
exponentialBackOff := backoff.NewExponentialBackOff()
30-
exponentialBackOff.InitialInterval = 1 * time.Second
31-
exponentialBackOff.Multiplier = 2
32-
comment, err := backoff.Retry(context.TODO(), func() (*github.IssueComment, error) {
28+
exponentialBackOff := getBackOff()
29+
comment, err := backoff.Retry(ctx, func() (*github.IssueComment, error) {
3330
cm, _, err := c.googleClient.Issues.CreateComment(
3431
ctx,
3532
pr.Owner,
@@ -61,10 +58,8 @@ func (c *Client) UpdateMessage(ctx context.Context, pr vcs.PullRequest, m *msg.M
6158
var err error
6259

6360
repoNameComponents := strings.Split(m.Name, "/")
64-
exponentialBackOff := backoff.NewExponentialBackOff()
65-
exponentialBackOff.InitialInterval = 1 * time.Second
66-
exponentialBackOff.Multiplier = 2
67-
resp, err = backoff.Retry(context.TODO(), func() (*github.Response, error) {
61+
exponentialBackOff := getBackOff()
62+
resp, err = backoff.Retry(ctx, func() (*github.Response, error) {
6863
comment, resp, err = c.googleClient.Issues.EditComment(
6964
ctx,
7065
repoNameComponents[0],

pkg/vcs/gitlab_client/message.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"strings"
7-
"time"
87

98
"github.com/cenkalti/backoff/v5"
109
"github.com/pkg/errors"
@@ -23,11 +22,9 @@ func (c *Client) PostMessage(ctx context.Context, pr vcs.PullRequest, message st
2322
_, span := tracer.Start(ctx, "PostMessage")
2423
defer span.End()
2524

26-
exponentialBackOff := backoff.NewExponentialBackOff()
27-
exponentialBackOff.InitialInterval = 1 * time.Second
28-
exponentialBackOff.Multiplier = 2
25+
exponentialBackOff := getBackOff()
2926

30-
n, err := backoff.Retry(context.TODO(), func() (*gitlab.Note, error) {
27+
n, err := backoff.Retry(ctx, func() (*gitlab.Note, error) {
3128
n, _, err := c.c.Notes.CreateMergeRequestNote(
3229
pr.FullName, pr.CheckID,
3330
&gitlab.CreateMergeRequestNoteOptions{
@@ -91,11 +88,9 @@ func (c *Client) UpdateMessage(ctx context.Context, pr vcs.PullRequest, m *msg.M
9188

9289
for i, msg := range messages {
9390
if i == 0 {
94-
exponentialBackOff := backoff.NewExponentialBackOff()
95-
exponentialBackOff.InitialInterval = 1 * time.Second
96-
exponentialBackOff.Multiplier = 2
91+
exponentialBackOff := getBackOff()
9792

98-
n, err := backoff.Retry(context.TODO(), func() (*gitlab.Note, error) {
93+
n, err := backoff.Retry(ctx, func() (*gitlab.Note, error) {
9994
n, _, err := c.c.Notes.UpdateMergeRequestNote(m.Name, m.CheckID, m.NoteID, &gitlab.UpdateMergeRequestNoteOptions{
10095
Body: pkg.Pointer(msg),
10196
})

0 commit comments

Comments
 (0)