@@ -242,6 +242,49 @@ func (s *PullRequestsService) Create(ctx context.Context, owner string, repo str
242242 return p , resp , nil
243243}
244244
245+ // PullReqestBranchUpdateOptions specifies the optional parameters to the
246+ // PullRequestsService.UpdateBranch method.
247+ type PullReqestBranchUpdateOptions struct {
248+ // ExpectedHeadSHA specifies the most recent commit on the pull request's branch.
249+ // Default value is the SHA of the pull request's current HEAD ref.
250+ ExpectedHeadSHA * string `json:"expected_head_sha,omitempty"`
251+ }
252+
253+ // PullRequestBranchUpdateResponse specifies the response of pull request branch update.
254+ type PullRequestBranchUpdateResponse struct {
255+ Message * string `json:"message,omitempty"`
256+ URL * string `json:"url,omitempty"`
257+ }
258+
259+ // UpdateBranch updates the pull request branch with latest upstream changes.
260+ //
261+ // This method might return an AcceptedError and a status code of
262+ // 202. This is because this is the status that GitHub returns to signify that
263+ // it has now scheduled the update of the pull request branch in a background task.
264+ // A follow up request, after a delay of a second or so, should result
265+ // in a successful request.
266+ //
267+ // GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request-branch
268+ func (s * PullRequestsService ) UpdateBranch (ctx context.Context , owner , repo string , number int , opts * PullReqestBranchUpdateOptions ) (* PullRequestBranchUpdateResponse , * Response , error ) {
269+ u := fmt .Sprintf ("repos/%v/%v/pulls/%d/update-branch" , owner , repo , number )
270+
271+ req , err := s .client .NewRequest ("PUT" , u , opts )
272+ if err != nil {
273+ return nil , nil , err
274+ }
275+
276+ // TODO: remove custom Accept header when this API fully launches.
277+ req .Header .Set ("Accept" , mediaTypeUpdatePullRequestBranchPreview )
278+
279+ p := new (PullRequestBranchUpdateResponse )
280+ resp , err := s .client .Do (ctx , req , p )
281+ if err != nil {
282+ return nil , resp , err
283+ }
284+
285+ return p , resp , nil
286+ }
287+
245288type pullRequestUpdate struct {
246289 Title * string `json:"title,omitempty"`
247290 Body * string `json:"body,omitempty"`
0 commit comments