summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-01-17 07:03:40 +0100
committerLauris BH <lauris@nix.lv>2020-01-17 08:03:40 +0200
commit36943e56d66a2d711a6b0c27219ce91a3ddc020a (patch)
tree6e1c57454beeaa9d64470c82db1140a5f540ad65 /models
parent9f40bb020eaea153eca77d3071a4f2cc8bcd2a8e (diff)
downloadgitea-36943e56d66a2d711a6b0c27219ce91a3ddc020a.tar.gz
gitea-36943e56d66a2d711a6b0c27219ce91a3ddc020a.zip
Add "Update Branch" button to Pull Requests (#9784)
* add Divergence * add Update Button * first working version * re-use code * split raw merge commands and db-change functions (notify, cache, ...) * use rawMerge (remove redundant code) * own function to get Diverging of PRs * use FlashError * correct Error Msg * hook is triggerd ... so remove comment * add "branch2" to "user2/repo1" because it unit-test "TestPullView_ReviewerMissed" use it but dont exist jet :/ * move GetPerm to IsUserAllowedToUpdate * add Flash Success MSG * imprufe code - remove useless js chage * fix-lint * TEST: add PullRequest ID:5 Repo: user2/repo1 Base: branch1 Head: pr-to-update * correct comments * make PR5 outdated * fix Tests * WIP: add pull update test * update revs * update locales * working TEST * update UI * misspell * change style * add 1s delay so rev exist * move row up (before merge row) * fix lint nit * UI remove divider * Update style * nits * do it right * introduce IsSameRepo * remove useless check Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models')
-rw-r--r--models/fixtures/issue.yml12
-rw-r--r--models/fixtures/pull_request.yml15
-rw-r--r--models/fixtures/repository.yml2
-rw-r--r--models/issue_test.go8
-rw-r--r--models/issue_user_test.go2
-rw-r--r--models/pull.go5
-rw-r--r--models/pull_test.go18
7 files changed, 47 insertions, 15 deletions
diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml
index ecee7499f6..e52a23a46b 100644
--- a/models/fixtures/issue.yml
+++ b/models/fixtures/issue.yml
@@ -122,3 +122,15 @@
created_unix: 946684830
updated_unix: 999307200
deadline_unix: 1019307200
+
+-
+ id: 11
+ repo_id: 1
+ index: 5
+ poster_id: 1
+ name: pull5
+ content: content for the a pull request
+ is_closed: false
+ is_pull: true
+ created_unix: 1579194806
+ updated_unix: 1579194806
diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml
index e8d81a0007..da9566bc48 100644
--- a/models/fixtures/pull_request.yml
+++ b/models/fixtures/pull_request.yml
@@ -49,4 +49,17 @@
head_branch: branch1
base_branch: master
merge_base: abcdef1234567890
- has_merged: false \ No newline at end of file
+ has_merged: false
+
+-
+ id: 5 # this PR is outdated (one commit behind branch1 )
+ type: 0 # gitea pull request
+ status: 2 # mergable
+ issue_id: 11
+ index: 5
+ head_repo_id: 1
+ base_repo_id: 1
+ head_branch: pr-to-update
+ base_branch: branch1
+ merge_base: 1234567890abcdef
+ has_merged: false
diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml
index a68e63e309..05989d9030 100644
--- a/models/fixtures/repository.yml
+++ b/models/fixtures/repository.yml
@@ -7,7 +7,7 @@
is_private: false
num_issues: 2
num_closed_issues: 1
- num_pulls: 2
+ num_pulls: 3
num_closed_pulls: 0
num_milestones: 3
num_closed_milestones: 1
diff --git a/models/issue_test.go b/models/issue_test.go
index ec4867d075..d65345a508 100644
--- a/models/issue_test.go
+++ b/models/issue_test.go
@@ -276,8 +276,8 @@ func TestIssue_SearchIssueIDsByKeyword(t *testing.T) {
total, ids, err = SearchIssueIDsByKeyword("for", []int64{1}, 10, 0)
assert.NoError(t, err)
- assert.EqualValues(t, 4, total)
- assert.EqualValues(t, []int64{1, 2, 3, 5}, ids)
+ assert.EqualValues(t, 5, total)
+ assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
// issue1's comment id 2
total, ids, err = SearchIssueIDsByKeyword("good", []int64{1}, 10, 0)
@@ -305,8 +305,8 @@ func testInsertIssue(t *testing.T, title, content string) {
assert.True(t, has)
assert.EqualValues(t, issue.Title, newIssue.Title)
assert.EqualValues(t, issue.Content, newIssue.Content)
- // there are 4 issues and max index is 4 on repository 1, so this one should 5
- assert.EqualValues(t, 5, newIssue.Index)
+ // there are 5 issues and max index is 5 on repository 1, so this one should 6
+ assert.EqualValues(t, 6, newIssue.Index)
_, err = x.ID(issue.ID).Delete(new(Issue))
assert.NoError(t, err)
diff --git a/models/issue_user_test.go b/models/issue_user_test.go
index a57ab33f9e..01e0bdc644 100644
--- a/models/issue_user_test.go
+++ b/models/issue_user_test.go
@@ -17,7 +17,7 @@ func Test_newIssueUsers(t *testing.T) {
newIssue := &Issue{
RepoID: repo.ID,
PosterID: 4,
- Index: 5,
+ Index: 6,
Title: "newTestIssueTitle",
Content: "newTestIssueContent",
}
diff --git a/models/pull.go b/models/pull.go
index 1edd890035..fcfcd221c4 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -742,3 +742,8 @@ func (pr *PullRequest) IsHeadEqualWithBranch(branchName string) (bool, error) {
}
return baseCommit.HasPreviousCommit(headCommit.ID)
}
+
+// IsSameRepo returns true if base repo and head repo is the same
+func (pr *PullRequest) IsSameRepo() bool {
+ return pr.BaseRepoID == pr.HeadRepoID
+}
diff --git a/models/pull_test.go b/models/pull_test.go
index 9c27b603aa..6ceeae6653 100644
--- a/models/pull_test.go
+++ b/models/pull_test.go
@@ -61,10 +61,11 @@ func TestPullRequestsNewest(t *testing.T) {
Labels: []string{},
})
assert.NoError(t, err)
- assert.Equal(t, int64(2), count)
- if assert.Len(t, prs, 2) {
- assert.Equal(t, int64(2), prs[0].ID)
- assert.Equal(t, int64(1), prs[1].ID)
+ assert.EqualValues(t, 3, count)
+ if assert.Len(t, prs, 3) {
+ assert.EqualValues(t, 5, prs[0].ID)
+ assert.EqualValues(t, 2, prs[1].ID)
+ assert.EqualValues(t, 1, prs[2].ID)
}
}
@@ -77,10 +78,11 @@ func TestPullRequestsOldest(t *testing.T) {
Labels: []string{},
})
assert.NoError(t, err)
- assert.Equal(t, int64(2), count)
- if assert.Len(t, prs, 2) {
- assert.Equal(t, int64(1), prs[0].ID)
- assert.Equal(t, int64(2), prs[1].ID)
+ assert.EqualValues(t, 3, count)
+ if assert.Len(t, prs, 3) {
+ assert.EqualValues(t, 1, prs[0].ID)
+ assert.EqualValues(t, 2, prs[1].ID)
+ assert.EqualValues(t, 5, prs[2].ID)
}
}