summaryrefslogtreecommitdiffstats
path: root/models/action_test.go
diff options
context:
space:
mode:
authorHarshit Bansal <harshitbansal2015@gmail.com>2019-01-04 14:52:58 +0530
committerLauris BH <lauris@nix.lv>2019-01-04 11:22:58 +0200
commit9f476b8d1e8eb8f576fad208701a4dc3d8e7108f (patch)
tree7d8e75311c78f8a7f6d9327e62fdc414643ee689 /models/action_test.go
parent0de57fd57ca1a268e084d322c3e0f2d054b931e2 (diff)
downloadgitea-9f476b8d1e8eb8f576fad208701a4dc3d8e7108f.tar.gz
gitea-9f476b8d1e8eb8f576fad208701a4dc3d8e7108f.zip
Don't close issues via commits on non-default branch. (#5622)
Adds a small check to close the issues only if the referencing commits are on the default branch. Fixes: #2314.
Diffstat (limited to 'models/action_test.go')
-rw-r--r--models/action_test.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/models/action_test.go b/models/action_test.go
index d0e0a5d8fa..0310b0ad5d 100644
--- a/models/action_test.go
+++ b/models/action_test.go
@@ -227,10 +227,37 @@ func TestUpdateIssuesCommit(t *testing.T) {
AssertNotExistsBean(t, commentBean)
AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
- assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits))
+ assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
AssertExistsAndLoadBean(t, commentBean)
AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
CheckConsistencyFor(t, &Action{})
+
+ // Test that push to a non-default branch closes no issue.
+ pushCommits = []*PushCommit{
+ {
+ Sha1: "abcdef1",
+ CommitterEmail: "user2@example.com",
+ CommitterName: "User Two",
+ AuthorEmail: "user4@example.com",
+ AuthorName: "User Four",
+ Message: "close #1",
+ },
+ }
+ repo = AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
+ commentBean = &Comment{
+ Type: CommentTypeCommitRef,
+ CommitSHA: "abcdef1",
+ PosterID: user.ID,
+ IssueID: 6,
+ }
+ issueBean = &Issue{RepoID: repo.ID, Index: 1}
+
+ AssertNotExistsBean(t, commentBean)
+ AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
+ AssertExistsAndLoadBean(t, commentBean)
+ AssertNotExistsBean(t, issueBean, "is_closed=1")
+ CheckConsistencyFor(t, &Action{})
}
func testCorrectRepoAction(t *testing.T, opts CommitRepoActionOptions, actionBean *Action) {