(client *api.Client, repo ghrepo.Interface, branch string)
| 36 | 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") |
| 37 | |
| 38 | func triggerUpstreamMerge(client *api.Client, repo ghrepo.Interface, branch string) (string, error) { |
| 39 | var payload bytes.Buffer |
| 40 | if err := json.NewEncoder(&payload).Encode(map[string]interface{}{ |
| 41 | "branch": branch, |
| 42 | }); err != nil { |
| 43 | return "", err |
| 44 | } |
| 45 | |
| 46 | var response struct { |
| 47 | Message string `json:"message"` |
| 48 | MergeType string `json:"merge_type"` |
| 49 | BaseBranch string `json:"base_branch"` |
| 50 | } |
| 51 | path := fmt.Sprintf("repos/%s/%s/merge-upstream", repo.RepoOwner(), repo.RepoName()) |
| 52 | var httpErr api.HTTPError |
| 53 | if err := client.REST(repo.RepoHost(), "POST", path, &payload, &response); err != nil { |
| 54 | if errors.As(err, &httpErr) { |
| 55 | switch httpErr.StatusCode { |
| 56 | case http.StatusUnprocessableEntity, http.StatusConflict: |
| 57 | if missingWorkflowScopeRE.MatchString(httpErr.Message) { |
| 58 | return "", missingWorkflowScopeErr |
| 59 | } |
| 60 | return "", upstreamMergeErr{errors.New(httpErr.Message)} |
| 61 | } |
| 62 | } |
| 63 | return "", err |
| 64 | } |
| 65 | return response.BaseBranch, nil |
| 66 | } |
| 67 | |
| 68 | func syncFork(client *api.Client, repo ghrepo.Interface, branch, SHA string, force bool) error { |
| 69 | path := fmt.Sprintf("repos/%s/%s/git/refs/heads/%s", repo.RepoOwner(), repo.RepoName(), branch) |
no test coverage detected