MCPcopy Create free account
hub / github.com/gogs/gogs / ParseCompareInfo

Function ParseCompareInfo

internal/route/repo/pull.go:433–558  ·  view source on GitHub ↗
(c *context.Context)

Source from the content-addressed store, hash-verified

431}
432
433func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository, *git.Repository, *gitutil.PullRequestMeta, string, string) {
434 baseRepo := c.Repo.Repository
435
436 // Get compared refs information
437 // format: <base ref>...[<head repo>:]<head ref>
438 // base<-head: master...head:feature
439 // same repo: master...feature
440 infos := strings.Split(c.Params("*"), "...")
441 if len(infos) != 2 {
442 log.Trace("ParseCompareInfo[%d]: not enough compared refs information %s", baseRepo.ID, infos)
443 c.NotFound()
444 return nil, nil, nil, nil, "", ""
445 }
446
447 baseRef := infos[0]
448 c.Data["BaseBranch"] = baseRef
449
450 var (
451 headUser *database.User
452 headRef string
453 isSameRepo bool
454 err error
455 )
456
457 // If there is no head repository, it means pull request between same repository.
458 headInfos := strings.Split(infos[1], ":")
459 if len(headInfos) == 1 {
460 isSameRepo = true
461 headUser = c.Repo.Owner
462 headRef = headInfos[0]
463
464 } else if len(headInfos) == 2 {
465 headUser, err = database.Handle.Users().GetByUsername(c.Req.Context(), headInfos[0])
466 if err != nil {
467 c.NotFoundOrError(err, "get user by name")
468 return nil, nil, nil, nil, "", ""
469 }
470 headRef = headInfos[1]
471 isSameRepo = headUser.ID == baseRepo.OwnerID
472
473 } else {
474 c.NotFound()
475 return nil, nil, nil, nil, "", ""
476 }
477 c.Data["HeadUser"] = headUser
478 c.Data["HeadBranch"] = headRef
479 c.Repo.PullRequest.SameRepo = isSameRepo
480
481 // Check if base ref is valid.
482 if _, err := c.Repo.GitRepo.RevParse(baseRef); err != nil {
483 c.NotFound()
484 return nil, nil, nil, nil, "", ""
485 }
486
487 var (
488 headRepo *database.Repository
489 headGitRepo *git.Repository
490 )

Callers 2

CompareAndPullRequestFunction · 0.85

Calls 13

HasForkedRepoFunction · 0.92
RepoPathFunction · 0.92
IsErrNoMergeBaseFunction · 0.92
SplitMethod · 0.80
GetByUsernameMethod · 0.80
UsersMethod · 0.80
AuthorizeMethod · 0.80
PermissionsMethod · 0.80
SuccessMethod · 0.80
NotFoundMethod · 0.65
PullRequestMetaMethod · 0.65
NotFoundOrErrorMethod · 0.45

Tested by

no test coverage detected