66 "strings"
77
88 gogithub "github.com/google/go-github/v68/github"
9+
10+ "github.com/omarkohl/jip/internal/retry"
911)
1012
1113// Service defines the GitHub operations needed by the send pipeline.
@@ -75,12 +77,17 @@ type UpdatePROpts struct {
7577
7678// CreatePR creates a new pull request and returns its info.
7779func (c * Client ) CreatePR (head , base , title , body string , draft bool ) (* PRInfo , error ) {
78- pr , _ , err := c .gh .PullRequests .Create (context .Background (), c .owner , c .repo , & gogithub.NewPullRequest {
79- Title : & title ,
80- Head : & head ,
81- Base : & base ,
82- Body : & body ,
83- Draft : & draft ,
80+ var pr * gogithub.PullRequest
81+ err := retry .Do (func () error {
82+ var apiErr error
83+ pr , _ , apiErr = c .gh .PullRequests .Create (context .Background (), c .owner , c .repo , & gogithub.NewPullRequest {
84+ Title : & title ,
85+ Head : & head ,
86+ Base : & base ,
87+ Body : & body ,
88+ Draft : & draft ,
89+ })
90+ return apiErr
8491 })
8592 if err != nil {
8693 return nil , fmt .Errorf ("creating PR: %w" , err )
@@ -109,7 +116,10 @@ func (c *Client) UpdatePR(number int, opts UpdatePROpts) error {
109116 if opts .Base != nil {
110117 update .Base = & gogithub.PullRequestBranch {Ref : opts .Base }
111118 }
112- _ , _ , err := c .gh .PullRequests .Edit (context .Background (), c .owner , c .repo , number , update )
119+ err := retry .Do (func () error {
120+ _ , _ , apiErr := c .gh .PullRequests .Edit (context .Background (), c .owner , c .repo , number , update )
121+ return apiErr
122+ })
113123 if err != nil {
114124 return fmt .Errorf ("updating PR #%d: %w" , number , err )
115125 }
@@ -118,8 +128,11 @@ func (c *Client) UpdatePR(number int, opts UpdatePROpts) error {
118128
119129// CommentOnPR posts a comment on a pull request.
120130func (c * Client ) CommentOnPR (number int , body string ) error {
121- _ , _ , err := c .gh .Issues .CreateComment (context .Background (), c .owner , c .repo , number , & gogithub.IssueComment {
122- Body : & body ,
131+ err := retry .Do (func () error {
132+ _ , _ , apiErr := c .gh .Issues .CreateComment (context .Background (), c .owner , c .repo , number , & gogithub.IssueComment {
133+ Body : & body ,
134+ })
135+ return apiErr
123136 })
124137 if err != nil {
125138 return fmt .Errorf ("commenting on PR #%d: %w" , number , err )
@@ -129,7 +142,12 @@ func (c *Client) CommentOnPR(number int, body string) error {
129142
130143// GetAuthenticatedUser returns the login of the authenticated user.
131144func (c * Client ) GetAuthenticatedUser () (string , error ) {
132- user , _ , err := c .gh .Users .Get (context .Background (), "" )
145+ var user * gogithub.User
146+ err := retry .Do (func () error {
147+ var apiErr error
148+ user , _ , apiErr = c .gh .Users .Get (context .Background (), "" )
149+ return apiErr
150+ })
133151 if err != nil {
134152 return "" , fmt .Errorf ("getting authenticated user: %w" , err )
135153 }
@@ -138,8 +156,11 @@ func (c *Client) GetAuthenticatedUser() (string, error) {
138156
139157// RequestReviewers adds reviewers to a pull request.
140158func (c * Client ) RequestReviewers (number int , reviewers []string ) error {
141- _ , _ , err := c .gh .PullRequests .RequestReviewers (context .Background (), c .owner , c .repo , number , gogithub.ReviewersRequest {
142- Reviewers : reviewers ,
159+ err := retry .Do (func () error {
160+ _ , _ , apiErr := c .gh .PullRequests .RequestReviewers (context .Background (), c .owner , c .repo , number , gogithub.ReviewersRequest {
161+ Reviewers : reviewers ,
162+ })
163+ return apiErr
143164 })
144165 if err != nil {
145166 return fmt .Errorf ("requesting reviewers on PR #%d: %w" , number , err )
0 commit comments