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

Function mergePullRequest

pkg/cmd/pr/merge/http.go:47–104  ·  view source on GitHub ↗
(client *http.Client, payload mergePayload)

Source from the content-addressed store, hash-verified

45}
46
47func mergePullRequest(client *http.Client, payload mergePayload) error {
48 input := githubv4.MergePullRequestInput{
49 PullRequestID: githubv4.ID(payload.pullRequestID),
50 }
51
52 switch payload.method {
53 case PullRequestMergeMethodMerge:
54 m := githubv4.PullRequestMergeMethodMerge
55 input.MergeMethod = &m
56 case PullRequestMergeMethodRebase:
57 m := githubv4.PullRequestMergeMethodRebase
58 input.MergeMethod = &m
59 case PullRequestMergeMethodSquash:
60 m := githubv4.PullRequestMergeMethodSquash
61 input.MergeMethod = &m
62 }
63
64 if payload.authorEmail != "" {
65 authorEmail := githubv4.String(payload.authorEmail)
66 input.AuthorEmail = &authorEmail
67 }
68 if payload.commitSubject != "" {
69 commitHeadline := githubv4.String(payload.commitSubject)
70 input.CommitHeadline = &commitHeadline
71 }
72 if payload.setCommitBody {
73 commitBody := githubv4.String(payload.commitBody)
74 input.CommitBody = &commitBody
75 }
76
77 if payload.expectedHeadOid != "" {
78 expectedHeadOid := githubv4.GitObjectID(payload.expectedHeadOid)
79 input.ExpectedHeadOid = &expectedHeadOid
80 }
81
82 variables := map[string]any{
83 "input": input,
84 }
85
86 gql := api.NewClientFromHTTP(client)
87
88 if payload.auto {
89 var mutation struct {
90 EnablePullRequestAutoMerge struct {
91 ClientMutationId string
92 } `graphql:"enablePullRequestAutoMerge(input: $input)"`
93 }
94 variables["input"] = EnablePullRequestAutoMergeInput{input}
95 return gql.Mutate(payload.repo.RepoHost(), "PullRequestAutoMerge", &mutation, variables)
96 }
97
98 var mutation struct {
99 MergePullRequest struct {
100 ClientMutationId string
101 } `graphql:"mergePullRequest(input: $input)"`
102 }
103 return gql.Mutate(payload.repo.RepoHost(), "PullRequestMerge", &mutation, variables)
104}

Callers 1

mergeMethod · 0.85

Calls 5

NewClientFromHTTPFunction · 0.92
IDMethod · 0.65
StringMethod · 0.65
MutateMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected