(c *context.Context)
| 431 | } |
| 432 | |
| 433 | func 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 | ) |
no test coverage detected