MCPcopy
hub / github.com/mislav/hub / pullRequest

Function pullRequest

commands/pull_request.go:134–441  ·  view source on GitHub ↗
(cmd *Command, args *Args)

Source from the content-addressed store, hash-verified

132}
133
134func pullRequest(cmd *Command, args *Args) {
135 localRepo, err := github.LocalRepo()
136 utils.Check(err)
137
138 currentBranch, currentBranchErr := localRepo.CurrentBranch()
139
140 baseProject, err := localRepo.MainProject()
141 utils.Check(err)
142
143 host, err := github.CurrentConfig().PromptForHost(baseProject.Host)
144 if err != nil {
145 utils.Check(github.FormatError("creating pull request", err))
146 }
147 client := github.NewClientWithHost(host)
148
149 trackedBranch, headProject, _ := localRepo.RemoteBranchAndProject(host.User, false)
150 if headProject == nil {
151 utils.Check(fmt.Errorf("could not determine project for head branch"))
152 }
153
154 var (
155 base, head string
156 )
157
158 if flagPullRequestBase := args.Flag.Value("--base"); flagPullRequestBase != "" {
159 baseProject, base = parsePullRequestProject(baseProject, flagPullRequestBase)
160 }
161
162 if flagPullRequestHead := args.Flag.Value("--head"); flagPullRequestHead != "" {
163 headProject, head = parsePullRequestProject(headProject, flagPullRequestHead)
164 }
165
166 baseRemote, _ := localRepo.RemoteForProject(baseProject)
167 if base == "" && baseRemote != nil {
168 base = localRepo.DefaultBranch(baseRemote).ShortName()
169 }
170
171 if head == "" && trackedBranch != nil {
172 if !trackedBranch.IsRemote() {
173 // the current branch tracking another branch
174 // pretend there's no upstream at all
175 trackedBranch = nil
176 } else {
177 if baseProject.SameAs(headProject) && base == trackedBranch.ShortName() {
178 e := fmt.Errorf(`Aborted: head branch is the same as base ("%s")`, base)
179 e = fmt.Errorf("%s\n(use `-h <branch>` to specify an explicit pull request head)", e)
180 utils.Check(e)
181 }
182 }
183 }
184
185 force := args.Flag.Bool("--force")
186 flagPullRequestPush := args.Flag.Bool("--push")
187
188 if head == "" {
189 if trackedBranch == nil {
190 utils.Check(currentBranchErr)
191 if !force && !flagPullRequestPush {

Callers

nothing calls this directly

Calls 15

AddCommentedSectionMethod · 0.95
ExtractMethod · 0.95
CleanupMethod · 0.95
HasRequestedTeamMethod · 0.95
HasRequestedReviewerMethod · 0.95
LocalRepoFunction · 0.92
CheckFunction · 0.92
CurrentConfigFunction · 0.92
FormatErrorFunction · 0.92
NewClientWithHostFunction · 0.92
RefListFunction · 0.92
ShowFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…