MCPcopy Create free account
hub / github.com/cli/cli / triggerUpstreamMerge

Function triggerUpstreamMerge

pkg/cmd/repo/sync/http.go:42–73  ·  view source on GitHub ↗
(client *api.Client, repo ghrepo.Interface, branch string)

Source from the content-addressed store, hash-verified

40var 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
42func 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
75func 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))

Callers 1

executeRemoteRepoSyncFunction · 0.85

Calls 6

JoinPathFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected