summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/error.go55
-rw-r--r--models/issue_comment.go8
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v113.go23
-rw-r--r--models/pull.go29
5 files changed, 117 insertions, 0 deletions
diff --git a/models/error.go b/models/error.go
index a17ff5f9d0..396d7594c8 100644
--- a/models/error.go
+++ b/models/error.go
@@ -953,6 +953,22 @@ func (err ErrBranchNameConflict) Error() string {
return fmt.Sprintf("branch conflicts with existing branch [name: %s]", err.BranchName)
}
+// ErrBranchesEqual represents an error that branch name conflicts with other branch.
+type ErrBranchesEqual struct {
+ BaseBranchName string
+ HeadBranchName string
+}
+
+// IsErrBranchesEqual checks if an error is an ErrBranchesEqual.
+func IsErrBranchesEqual(err error) bool {
+ _, ok := err.(ErrBranchesEqual)
+ return ok
+}
+
+func (err ErrBranchesEqual) Error() string {
+ return fmt.Sprintf("branches are equal [head: %sm base: %s]", err.HeadBranchName, err.BaseBranchName)
+}
+
// ErrNotAllowedToMerge represents an error that a branch is protected and the current user is not allowed to modify it.
type ErrNotAllowedToMerge struct {
Reason string
@@ -1090,6 +1106,23 @@ func (err ErrIssueNotExist) Error() string {
return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
}
+// ErrIssueIsClosed represents a "IssueIsClosed" kind of error.
+type ErrIssueIsClosed struct {
+ ID int64
+ RepoID int64
+ Index int64
+}
+
+// IsErrIssueIsClosed checks if an error is a ErrIssueNotExist.
+func IsErrIssueIsClosed(err error) bool {
+ _, ok := err.(ErrIssueIsClosed)
+ return ok
+}
+
+func (err ErrIssueIsClosed) Error() string {
+ return fmt.Sprintf("issue is closed [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
+}
+
// ErrIssueLabelTemplateLoad represents a "ErrIssueLabelTemplateLoad" kind of error.
type ErrIssueLabelTemplateLoad struct {
TemplateFile string
@@ -1326,6 +1359,28 @@ func (err ErrRebaseConflicts) Error() string {
return fmt.Sprintf("Rebase Error: %v: Whilst Rebasing: %s\n%s\n%s", err.Err, err.CommitSHA, err.StdErr, err.StdOut)
}
+// ErrPullRequestHasMerged represents a "PullRequestHasMerged"-error
+type ErrPullRequestHasMerged struct {
+ ID int64
+ IssueID int64
+ HeadRepoID int64
+ BaseRepoID int64
+ HeadBranch string
+ BaseBranch string
+}
+
+// IsErrPullRequestHasMerged checks if an error is a ErrPullRequestHasMerged.
+func IsErrPullRequestHasMerged(err error) bool {
+ _, ok := err.(ErrPullRequestHasMerged)
+ return ok
+}
+
+// Error does pretty-printing :D
+func (err ErrPullRequestHasMerged) Error() string {
+ return fmt.Sprintf("pull request has merged [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
+ err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
+}
+
// _________ __
// \_ ___ \ ____ _____ _____ ____ _____/ |_
// / \ \/ / _ \ / \ / \_/ __ \ / \ __\
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 9f87c049df..aeaee68003 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -82,6 +82,8 @@ const (
CommentTypeLock
// Unlocks a previously locked issue
CommentTypeUnlock
+ // Change pull request's target branch
+ CommentTypeChangeTargetBranch
)
// CommentTag defines comment tag type
@@ -116,6 +118,8 @@ type Comment struct {
Assignee *User `xorm:"-"`
OldTitle string
NewTitle string
+ OldRef string
+ NewRef string
DependentIssueID int64
DependentIssue *Issue `xorm:"-"`
@@ -517,6 +521,8 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
Content: opts.Content,
OldTitle: opts.OldTitle,
NewTitle: opts.NewTitle,
+ OldRef: opts.OldRef,
+ NewRef: opts.NewRef,
DependentIssueID: opts.DependentIssueID,
TreePath: opts.TreePath,
ReviewID: opts.ReviewID,
@@ -673,6 +679,8 @@ type CreateCommentOptions struct {
RemovedAssignee bool
OldTitle string
NewTitle string
+ OldRef string
+ NewRef string
CommitID int64
CommitSHA string
Patch string
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 78fbc18ca5..cbea5a95dd 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -280,6 +280,8 @@ var migrations = []Migration{
NewMigration("update branch protection for can push and whitelist enable", addBranchProtectionCanPushAndEnableWhitelist),
// v112 -> v113
NewMigration("remove release attachments which repository deleted", removeAttachmentMissedRepo),
+ // v113 -> v114
+ NewMigration("new feature: change target branch of pull requests", featureChangeTargetBranch),
}
// Migrate database to current version
diff --git a/models/migrations/v113.go b/models/migrations/v113.go
new file mode 100644
index 0000000000..199c02ac98
--- /dev/null
+++ b/models/migrations/v113.go
@@ -0,0 +1,23 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "fmt"
+
+ "xorm.io/xorm"
+)
+
+func featureChangeTargetBranch(x *xorm.Engine) error {
+ type Comment struct {
+ OldRef string
+ NewRef string
+ }
+
+ if err := x.Sync2(new(Comment)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+ return nil
+}
diff --git a/models/pull.go b/models/pull.go
index d703c9a2ee..ba9c575775 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -664,3 +664,32 @@ func (pr *PullRequest) GetWorkInProgressPrefix() string {
}
return ""
}
+
+// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head
+func (pr *PullRequest) IsHeadEqualWithBranch(branchName string) (bool, error) {
+ var err error
+ if err = pr.GetBaseRepo(); err != nil {
+ return false, err
+ }
+ baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
+ if err != nil {
+ return false, err
+ }
+ baseCommit, err := baseGitRepo.GetBranchCommit(branchName)
+ if err != nil {
+ return false, err
+ }
+
+ if err = pr.GetHeadRepo(); err != nil {
+ return false, err
+ }
+ headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
+ if err != nil {
+ return false, err
+ }
+ headCommit, err := headGitRepo.GetBranchCommit(pr.HeadBranch)
+ if err != nil {
+ return false, err
+ }
+ return baseCommit.HasPreviousCommit(headCommit.ID)
+}