| 40 | var missingWorkflowScopeErr = errors.New("Upstream commits contain workflow changes, which require the `workflow` scope or permission to merge. To request it, run: gh auth refresh -s workflow") |
| 41 | |
| 42 | func triggerUpstreamMerge(client *api.Client, repo ghrepo.Interface, branch string) (string, error) { |
| 43 | var payload bytes.Buffer |
| 44 | if err := json.NewEncoder(&payload).Encode(map[string]interface{}{ |
| 45 | "branch": branch, |
| 46 | }); err != nil { |
| 47 | return "", err |
| 48 | } |
| 49 | |
| 50 | var response struct { |
| 51 | Message string `json:"message"` |
| 52 | MergeType string `json:"merge_type"` |
| 53 | BaseBranch string `json:"base_branch"` |
| 54 | } |
| 55 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "merge-upstream") |
| 56 | if err != nil { |
| 57 | return "", err |
| 58 | } |
| 59 | var httpErr api.HTTPError |
| 60 | if err := client.REST(repo.RepoHost(), "POST", path.String(), &payload, &response); err != nil { |
| 61 | if errors.As(err, &httpErr) { |
| 62 | switch httpErr.StatusCode { |
| 63 | case http.StatusUnprocessableEntity, http.StatusConflict: |
| 64 | if missingWorkflowScopeRE.MatchString(httpErr.Message) { |
| 65 | return "", missingWorkflowScopeErr |
| 66 | } |
| 67 | return "", upstreamMergeErr{errors.New(httpErr.Message)} |
| 68 | } |
| 69 | } |
| 70 | return "", err |
| 71 | } |
| 72 | return response.BaseBranch, nil |
| 73 | } |
| 74 | |
| 75 | func syncFork(client *api.Client, repo ghrepo.Interface, branch, SHA string, force bool) error { |
| 76 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "git", "refs", fmt.Sprintf("heads/%s", branch)) |