MCPcopy
hub / github.com/cli/cli / triggerUpstreamMerge

Function triggerUpstreamMerge

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

Source from the content-addressed store, hash-verified

36var 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
38func 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
68func 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)

Callers 1

executeRemoteRepoSyncFunction · 0.85

Calls 4

RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected