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

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