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

Function NewPullRequest

internal/database/pull.go:444–513  ·  view source on GitHub ↗

NewPullRequest creates new pull request with labels for repository.

(repo *Repository, pull *Issue, labelIDs []int64, uuids []string, pr *PullRequest, patch []byte)

Source from the content-addressed store, hash-verified

442
443// NewPullRequest creates new pull request with labels for repository.
444func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []string, pr *PullRequest, patch []byte) (err error) {
445 sess := x.NewSession()
446 defer sess.Close()
447 if err = sess.Begin(); err != nil {
448 return err
449 }
450
451 if err = newIssue(sess, NewIssueOptions{
452 Repo: repo,
453 Issue: pull,
454 LableIDs: labelIDs,
455 Attachments: uuids,
456 IsPull: true,
457 }); err != nil {
458 return errors.Newf("newIssue: %v", err)
459 }
460
461 pr.Index = pull.Index
462 if err = repo.SavePatch(pr.Index, patch); err != nil {
463 return errors.Newf("SavePatch: %v", err)
464 }
465
466 pr.BaseRepo = repo
467 if err = pr.testPatch(); err != nil {
468 return errors.Newf("testPatch: %v", err)
469 }
470 // No conflict appears after test means mergeable.
471 if pr.Status == PullRequestStatusChecking {
472 pr.Status = PullRequestStatusMergeable
473 }
474
475 pr.IssueID = pull.ID
476 if _, err = sess.Insert(pr); err != nil {
477 return errors.Newf("insert pull repo: %v", err)
478 }
479
480 if err = sess.Commit(); err != nil {
481 return errors.Newf("commit: %v", err)
482 }
483
484 if err = NotifyWatchers(&Action{
485 ActUserID: pull.Poster.ID,
486 ActUserName: pull.Poster.Name,
487 OpType: ActionCreatePullRequest,
488 Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
489 RepoID: repo.ID,
490 RepoUserName: repo.Owner.Name,
491 RepoName: repo.Name,
492 IsPrivate: repo.IsPrivate,
493 }); err != nil {
494 log.Error("NotifyWatchers: %v", err)
495 }
496 if err = pull.MailParticipants(); err != nil {
497 log.Error("MailParticipants: %v", err)
498 }
499
500 pr.Issue = pull
501 pull.PullRequest = pr

Callers 1

Calls 10

newIssueFunction · 0.85
NotifyWatchersFunction · 0.85
PrepareWebhooksFunction · 0.85
SavePatchMethod · 0.80
testPatchMethod · 0.80
InsertMethod · 0.80
MailParticipantsMethod · 0.80
APIFormatLegacyMethod · 0.80
ErrorMethod · 0.45
APIFormatMethod · 0.45

Tested by

no test coverage detected