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

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