You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pull.go 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "container/list"
  7. "path"
  8. "strings"
  9. "github.com/Unknwon/com"
  10. "github.com/gogits/gogs/models"
  11. "github.com/gogits/gogs/modules/auth"
  12. "github.com/gogits/gogs/modules/base"
  13. "github.com/gogits/gogs/modules/git"
  14. "github.com/gogits/gogs/modules/log"
  15. "github.com/gogits/gogs/modules/middleware"
  16. "github.com/gogits/gogs/modules/setting"
  17. )
  18. const (
  19. FORK base.TplName = "repo/pulls/fork"
  20. COMPARE_PULL base.TplName = "repo/pulls/compare"
  21. PULL_COMMITS base.TplName = "repo/pulls/commits"
  22. PULL_FILES base.TplName = "repo/pulls/files"
  23. )
  24. func getForkRepository(ctx *middleware.Context) *models.Repository {
  25. forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
  26. if err != nil {
  27. if models.IsErrRepoNotExist(err) {
  28. ctx.Handle(404, "GetRepositoryByID", nil)
  29. } else {
  30. ctx.Handle(500, "GetRepositoryByID", err)
  31. }
  32. return nil
  33. }
  34. // Cannot fork bare repo.
  35. if forkRepo.IsBare {
  36. ctx.Handle(404, "", nil)
  37. return nil
  38. }
  39. ctx.Data["repo_name"] = forkRepo.Name
  40. ctx.Data["desc"] = forkRepo.Description
  41. ctx.Data["IsPrivate"] = forkRepo.IsPrivate
  42. if err = forkRepo.GetOwner(); err != nil {
  43. ctx.Handle(500, "GetOwner", err)
  44. return nil
  45. }
  46. ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
  47. if err := ctx.User.GetOrganizations(); err != nil {
  48. ctx.Handle(500, "GetOrganizations", err)
  49. return nil
  50. }
  51. ctx.Data["Orgs"] = ctx.User.Orgs
  52. return forkRepo
  53. }
  54. func Fork(ctx *middleware.Context) {
  55. ctx.Data["Title"] = ctx.Tr("new_fork")
  56. getForkRepository(ctx)
  57. if ctx.Written() {
  58. return
  59. }
  60. ctx.Data["ContextUser"] = ctx.User
  61. ctx.HTML(200, FORK)
  62. }
  63. func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
  64. ctx.Data["Title"] = ctx.Tr("new_fork")
  65. forkRepo := getForkRepository(ctx)
  66. if ctx.Written() {
  67. return
  68. }
  69. ctxUser := checkContextUser(ctx, form.Uid)
  70. if ctx.Written() {
  71. return
  72. }
  73. ctx.Data["ContextUser"] = ctxUser
  74. if ctx.HasError() {
  75. ctx.HTML(200, FORK)
  76. return
  77. }
  78. repo, has := models.HasForkedRepo(ctxUser.Id, forkRepo.ID)
  79. if has {
  80. ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
  81. return
  82. }
  83. // Check ownership of organization.
  84. if ctxUser.IsOrganization() {
  85. if !ctxUser.IsOwnedBy(ctx.User.Id) {
  86. ctx.Error(403)
  87. return
  88. }
  89. }
  90. repo, err := models.ForkRepository(ctxUser, forkRepo, form.RepoName, form.Description)
  91. if err != nil {
  92. ctx.Data["Err_RepoName"] = true
  93. switch {
  94. case models.IsErrRepoAlreadyExist(err):
  95. ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), FORK, &form)
  96. case models.IsErrNameReserved(err):
  97. ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), FORK, &form)
  98. case models.IsErrNamePatternNotAllowed(err):
  99. ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), FORK, &form)
  100. default:
  101. ctx.Handle(500, "ForkPost", err)
  102. }
  103. return
  104. }
  105. log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
  106. ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
  107. }
  108. func checkPullInfo(ctx *middleware.Context) *models.Issue {
  109. pull, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  110. if err != nil {
  111. if models.IsErrIssueNotExist(err) {
  112. ctx.Handle(404, "GetIssueByIndex", err)
  113. } else {
  114. ctx.Handle(500, "GetIssueByIndex", err)
  115. }
  116. return nil
  117. }
  118. ctx.Data["Title"] = pull.Name
  119. ctx.Data["Issue"] = pull
  120. if !pull.IsPull {
  121. ctx.Handle(404, "ViewPullCommits", nil)
  122. return nil
  123. }
  124. if err = pull.GetPoster(); err != nil {
  125. ctx.Handle(500, "GetPoster", err)
  126. return nil
  127. }
  128. if ctx.IsSigned {
  129. // Update issue-user.
  130. if err = pull.ReadBy(ctx.User.Id); err != nil {
  131. ctx.Handle(500, "ReadBy", err)
  132. return nil
  133. }
  134. }
  135. return pull
  136. }
  137. func PrepareMergedViewPullInfo(ctx *middleware.Context, pull *models.Issue) {
  138. ctx.Data["HasMerged"] = true
  139. var err error
  140. ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBarcnh
  141. ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch
  142. ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID)
  143. if err != nil {
  144. ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err)
  145. return
  146. }
  147. ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, pull.MergedCommitID)
  148. if err != nil {
  149. ctx.Handle(500, "Repo.GitRepo.FilesCountBetween", err)
  150. return
  151. }
  152. }
  153. func PrepareViewPullInfo(ctx *middleware.Context, pull *models.Issue) *git.PullRequestInfo {
  154. repo := ctx.Repo.Repository
  155. ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBarcnh
  156. ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch
  157. headRepoPath, err := pull.HeadRepo.RepoPath()
  158. if err != nil {
  159. ctx.Handle(500, "HeadRepo.RepoPath", err)
  160. return nil
  161. }
  162. headGitRepo, err := git.OpenRepository(headRepoPath)
  163. if err != nil {
  164. ctx.Handle(500, "OpenRepository", err)
  165. return nil
  166. }
  167. if pull.HeadRepo == nil || !headGitRepo.IsBranchExist(pull.HeadBarcnh) {
  168. ctx.Data["IsPullReuqestBroken"] = true
  169. ctx.Data["HeadTarget"] = "deleted"
  170. ctx.Data["NumCommits"] = 0
  171. ctx.Data["NumFiles"] = 0
  172. return nil
  173. }
  174. prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(repo.Owner.Name, repo.Name),
  175. pull.BaseBranch, pull.HeadBarcnh)
  176. if err != nil {
  177. ctx.Handle(500, "GetPullRequestInfo", err)
  178. return nil
  179. }
  180. ctx.Data["NumCommits"] = prInfo.Commits.Len()
  181. ctx.Data["NumFiles"] = prInfo.NumFiles
  182. return prInfo
  183. }
  184. func ViewPullCommits(ctx *middleware.Context) {
  185. ctx.Data["PageIsPullCommits"] = true
  186. pull := checkPullInfo(ctx)
  187. if ctx.Written() {
  188. return
  189. }
  190. ctx.Data["Username"] = pull.HeadUserName
  191. ctx.Data["Reponame"] = pull.HeadRepo.Name
  192. var commits *list.List
  193. if pull.HasMerged {
  194. PrepareMergedViewPullInfo(ctx, pull)
  195. if ctx.Written() {
  196. return
  197. }
  198. startCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergeBase)
  199. if err != nil {
  200. ctx.Handle(500, "Repo.GitRepo.GetCommit", err)
  201. return
  202. }
  203. endCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID)
  204. if err != nil {
  205. ctx.Handle(500, "Repo.GitRepo.GetCommit", err)
  206. return
  207. }
  208. commits, err = ctx.Repo.GitRepo.CommitsBetween(endCommit, startCommit)
  209. if err != nil {
  210. ctx.Handle(500, "Repo.GitRepo.CommitsBetween", err)
  211. return
  212. }
  213. } else {
  214. prInfo := PrepareViewPullInfo(ctx, pull)
  215. if ctx.Written() {
  216. return
  217. } else if prInfo == nil {
  218. ctx.Handle(404, "ViewPullCommits", nil)
  219. return
  220. }
  221. commits = prInfo.Commits
  222. }
  223. commits = models.ValidateCommitsWithEmails(commits)
  224. ctx.Data["Commits"] = commits
  225. ctx.Data["CommitCount"] = commits.Len()
  226. ctx.HTML(200, PULL_COMMITS)
  227. }
  228. func ViewPullFiles(ctx *middleware.Context) {
  229. ctx.Data["PageIsPullFiles"] = true
  230. pull := checkPullInfo(ctx)
  231. if ctx.Written() {
  232. return
  233. }
  234. var (
  235. diffRepoPath string
  236. startCommitID string
  237. endCommitID string
  238. gitRepo *git.Repository
  239. )
  240. if pull.HasMerged {
  241. PrepareMergedViewPullInfo(ctx, pull)
  242. if ctx.Written() {
  243. return
  244. }
  245. diffRepoPath = ctx.Repo.GitRepo.Path
  246. startCommitID = pull.MergeBase
  247. endCommitID = pull.MergedCommitID
  248. gitRepo = ctx.Repo.GitRepo
  249. } else {
  250. prInfo := PrepareViewPullInfo(ctx, pull)
  251. if ctx.Written() {
  252. return
  253. } else if prInfo == nil {
  254. ctx.Handle(404, "ViewPullFiles", nil)
  255. return
  256. }
  257. headRepoPath := models.RepoPath(pull.HeadUserName, pull.HeadRepo.Name)
  258. headGitRepo, err := git.OpenRepository(headRepoPath)
  259. if err != nil {
  260. ctx.Handle(500, "OpenRepository", err)
  261. return
  262. }
  263. headCommitID, err := headGitRepo.GetCommitIdOfBranch(pull.HeadBarcnh)
  264. if err != nil {
  265. ctx.Handle(500, "GetCommitIdOfBranch", err)
  266. return
  267. }
  268. diffRepoPath = headRepoPath
  269. startCommitID = prInfo.MergeBase
  270. endCommitID = headCommitID
  271. gitRepo = headGitRepo
  272. }
  273. diff, err := models.GetDiffRange(diffRepoPath,
  274. startCommitID, endCommitID, setting.Git.MaxGitDiffLines)
  275. if err != nil {
  276. ctx.Handle(500, "GetDiffRange", err)
  277. return
  278. }
  279. ctx.Data["Diff"] = diff
  280. ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
  281. commit, err := gitRepo.GetCommit(endCommitID)
  282. if err != nil {
  283. ctx.Handle(500, "GetCommit", err)
  284. return
  285. }
  286. headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
  287. ctx.Data["Username"] = pull.HeadUserName
  288. ctx.Data["Reponame"] = pull.HeadRepo.Name
  289. ctx.Data["IsImageFile"] = commit.IsImageFile
  290. ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", endCommitID)
  291. ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", startCommitID)
  292. ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", endCommitID)
  293. ctx.HTML(200, PULL_FILES)
  294. }
  295. func MergePullRequest(ctx *middleware.Context) {
  296. pull := checkPullInfo(ctx)
  297. if ctx.Written() {
  298. return
  299. }
  300. if pull.IsClosed {
  301. ctx.Handle(404, "MergePullRequest", nil)
  302. return
  303. }
  304. pr, err := models.GetPullRequestByPullID(pull.ID)
  305. if err != nil {
  306. if models.IsErrPullRequestNotExist(err) {
  307. ctx.Handle(404, "GetPullRequestByPullID", nil)
  308. } else {
  309. ctx.Handle(500, "GetPullRequestByPullID", err)
  310. }
  311. return
  312. }
  313. if !pr.CanAutoMerge || pr.HasMerged {
  314. ctx.Handle(404, "MergePullRequest", nil)
  315. return
  316. }
  317. pr.Pull = pull
  318. pr.Pull.Repo = ctx.Repo.Repository
  319. if err = pr.Merge(ctx.User, ctx.Repo.GitRepo); err != nil {
  320. ctx.Handle(500, "GetPullRequestByPullID", err)
  321. return
  322. }
  323. log.Trace("Pull request merged: %d", pr.ID)
  324. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.PullIndex))
  325. }
  326. func ParseCompareInfo(ctx *middleware.Context) (*models.User, *models.Repository, *git.Repository, *git.PullRequestInfo, string, string) {
  327. // Get compare branch information.
  328. infos := strings.Split(ctx.Params("*"), "...")
  329. if len(infos) != 2 {
  330. ctx.Handle(404, "CompareAndPullRequest", nil)
  331. return nil, nil, nil, nil, "", ""
  332. }
  333. baseBranch := infos[0]
  334. ctx.Data["BaseBranch"] = baseBranch
  335. headInfos := strings.Split(infos[1], ":")
  336. if len(headInfos) != 2 {
  337. ctx.Handle(404, "CompareAndPullRequest", nil)
  338. return nil, nil, nil, nil, "", ""
  339. }
  340. headUsername := headInfos[0]
  341. headBranch := headInfos[1]
  342. ctx.Data["HeadBranch"] = headBranch
  343. headUser, err := models.GetUserByName(headUsername)
  344. if err != nil {
  345. if models.IsErrUserNotExist(err) {
  346. ctx.Handle(404, "GetUserByName", nil)
  347. } else {
  348. ctx.Handle(500, "GetUserByName", err)
  349. }
  350. return nil, nil, nil, nil, "", ""
  351. }
  352. repo := ctx.Repo.Repository
  353. // Check if base branch is valid.
  354. if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
  355. ctx.Handle(404, "IsBranchExist", nil)
  356. return nil, nil, nil, nil, "", ""
  357. }
  358. // Check if current user has fork of repository.
  359. headRepo, has := models.HasForkedRepo(headUser.Id, repo.ID)
  360. if !has || !ctx.User.IsAdminOfRepo(headRepo) {
  361. ctx.Handle(404, "HasForkedRepo", nil)
  362. return nil, nil, nil, nil, "", ""
  363. }
  364. headGitRepo, err := git.OpenRepository(models.RepoPath(headUser.Name, headRepo.Name))
  365. if err != nil {
  366. ctx.Handle(500, "OpenRepository", err)
  367. return nil, nil, nil, nil, "", ""
  368. }
  369. // Check if head branch is valid.
  370. if !headGitRepo.IsBranchExist(headBranch) {
  371. ctx.Handle(404, "IsBranchExist", nil)
  372. return nil, nil, nil, nil, "", ""
  373. }
  374. headBranches, err := headGitRepo.GetBranches()
  375. if err != nil {
  376. ctx.Handle(500, "GetBranches", err)
  377. return nil, nil, nil, nil, "", ""
  378. }
  379. ctx.Data["HeadBranches"] = headBranches
  380. prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(repo.Owner.Name, repo.Name), baseBranch, headBranch)
  381. if err != nil {
  382. ctx.Handle(500, "GetPullRequestInfo", err)
  383. return nil, nil, nil, nil, "", ""
  384. }
  385. ctx.Data["BeforeCommitID"] = prInfo.MergeBase
  386. return headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch
  387. }
  388. func PrepareCompareDiff(
  389. ctx *middleware.Context,
  390. headUser *models.User,
  391. headRepo *models.Repository,
  392. headGitRepo *git.Repository,
  393. prInfo *git.PullRequestInfo,
  394. baseBranch, headBranch string) bool {
  395. var (
  396. repo = ctx.Repo.Repository
  397. err error
  398. )
  399. // Get diff information.
  400. ctx.Data["CommitRepoLink"], err = headRepo.RepoLink()
  401. if err != nil {
  402. ctx.Handle(500, "RepoLink", err)
  403. return false
  404. }
  405. headCommitID, err := headGitRepo.GetCommitIdOfBranch(headBranch)
  406. if err != nil {
  407. ctx.Handle(500, "GetCommitIdOfBranch", err)
  408. return false
  409. }
  410. ctx.Data["AfterCommitID"] = headCommitID
  411. if headCommitID == prInfo.MergeBase {
  412. ctx.Data["IsNothingToCompare"] = true
  413. return true
  414. }
  415. diff, err := models.GetDiffRange(models.RepoPath(headUser.Name, headRepo.Name),
  416. prInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines)
  417. if err != nil {
  418. ctx.Handle(500, "GetDiffRange", err)
  419. return false
  420. }
  421. ctx.Data["Diff"] = diff
  422. ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
  423. headCommit, err := headGitRepo.GetCommit(headCommitID)
  424. if err != nil {
  425. ctx.Handle(500, "GetCommit", err)
  426. return false
  427. }
  428. prInfo.Commits = models.ValidateCommitsWithEmails(prInfo.Commits)
  429. ctx.Data["Commits"] = prInfo.Commits
  430. ctx.Data["CommitCount"] = prInfo.Commits.Len()
  431. ctx.Data["Username"] = headUser.Name
  432. ctx.Data["Reponame"] = headRepo.Name
  433. ctx.Data["IsImageFile"] = headCommit.IsImageFile
  434. headTarget := path.Join(headUser.Name, repo.Name)
  435. ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", headCommitID)
  436. ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", prInfo.MergeBase)
  437. ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", headCommitID)
  438. return false
  439. }
  440. func CompareAndPullRequest(ctx *middleware.Context) {
  441. ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
  442. ctx.Data["PageIsComparePull"] = true
  443. ctx.Data["IsDiffCompare"] = true
  444. renderAttachmentSettings(ctx)
  445. headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
  446. if ctx.Written() {
  447. return
  448. }
  449. pr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch)
  450. if err != nil {
  451. if !models.IsErrPullRequestNotExist(err) {
  452. ctx.Handle(500, "GetUnmergedPullRequest", err)
  453. return
  454. }
  455. } else {
  456. ctx.Data["HasPullRequest"] = true
  457. ctx.Data["PullRequest"] = pr
  458. ctx.HTML(200, COMPARE_PULL)
  459. return
  460. }
  461. nothingToCompare := PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch)
  462. if ctx.Written() {
  463. return
  464. }
  465. if !nothingToCompare {
  466. // Setup information for new form.
  467. RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  468. if ctx.Written() {
  469. return
  470. }
  471. }
  472. ctx.HTML(200, COMPARE_PULL)
  473. }
  474. func CompareAndPullRequestPost(ctx *middleware.Context, form auth.CreateIssueForm) {
  475. ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
  476. ctx.Data["PageIsComparePull"] = true
  477. ctx.Data["IsDiffCompare"] = true
  478. renderAttachmentSettings(ctx)
  479. var (
  480. repo = ctx.Repo.Repository
  481. attachments []string
  482. )
  483. headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
  484. if ctx.Written() {
  485. return
  486. }
  487. patch, err := headGitRepo.GetPatch(models.RepoPath(repo.Owner.Name, repo.Name), baseBranch, headBranch)
  488. if err != nil {
  489. ctx.Handle(500, "GetPatch", err)
  490. return
  491. }
  492. labelIDs, milestoneID, assigneeID := ValidateRepoMetas(ctx, form)
  493. if ctx.Written() {
  494. return
  495. }
  496. if setting.AttachmentEnabled {
  497. attachments = form.Attachments
  498. }
  499. if ctx.HasError() {
  500. ctx.HTML(200, COMPARE_PULL)
  501. return
  502. }
  503. pull := &models.Issue{
  504. RepoID: repo.ID,
  505. Index: int64(repo.NumIssues) + 1,
  506. Name: form.Title,
  507. PosterID: ctx.User.Id,
  508. Poster: ctx.User,
  509. MilestoneID: milestoneID,
  510. AssigneeID: assigneeID,
  511. IsPull: true,
  512. Content: form.Content,
  513. }
  514. if err := models.NewPullRequest(repo, pull, labelIDs, attachments, &models.PullRequest{
  515. HeadRepoID: headRepo.ID,
  516. BaseRepoID: repo.ID,
  517. HeadUserName: headUser.Name,
  518. HeadBarcnh: headBranch,
  519. BaseBranch: baseBranch,
  520. MergeBase: prInfo.MergeBase,
  521. Type: models.PULL_REQUEST_GOGS,
  522. }, patch); err != nil {
  523. ctx.Handle(500, "NewPullRequest", err)
  524. return
  525. }
  526. log.Trace("Pull request created: %d/%d", repo.ID, pull.ID)
  527. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pull.Index))
  528. }