-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add "Update Branch" button to Pull Requests #9784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
38a27df
add Divergence
6543 2c7fc31
add Update Button
6543 26d686f
first working version
6543 d8522ac
re-use code
6543 efe6982
split raw merge commands and db-change functions (notify, cache, ...)
6543 328ecc3
use rawMerge (remove redundant code)
6543 9249d47
own function to get Diverging of PRs
6543 454ee44
use FlashError
6543 5d5d919
correct Error Msg
6543 3c6157b
hook is triggerd ... so remove comment
6543 88fa4c5
add "branch2" to "user2/repo1" because it unit-test "TestPullView_Rev…
6543 7776738
move GetPerm to IsUserAllowedToUpdate
6543 e3adbd2
add Flash Success MSG
6543 05c0c1b
imprufe code
6543 f7d924a
fix-lint
6543 e2f96d9
TEST: add PullRequest ID:5
6543 8bad5d2
correct comments
6543 7442991
Merge branch 'master' into update-pr
6543 143d8e8
make PR5 outdated
6543 fb33b4b
fix Tests
6543 069a393
WIP: add pull update test
6543 720fbf1
update revs
6543 892ddd9
update locales
6543 7aa9e84
working TEST
6543 7502ff5
Merge branch 'master' into update-pr
6543 36a34cd
update UI
6543 18fadef
misspell
6543 97e51ec
change style
6543 18eb495
add 1s delay so rev exist
6543 2b58961
move row up (before merge row)
6543 688a53a
fix lint nit
6543 97a6f83
UI remove divider
6543 32c5eee
Merge branch 'master' into update-pr
6543 6400bcc
Update style
lafriks fa4779b
nits
6543 fbbc7f4
do it right
6543 717406e
introduce IsSameRepo
6543 f26c8b3
remove useless check
6543 246748f
Merge branch 'master' into update-pr
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
integrations/gitea-repositories-meta/user2/repo1.git/info/refs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
65f1bf27bc3bf70f64657658635e66094edbcb4d refs/heads/master | ||
985f0301dba5e7b34be866819cd15ad3d8f508ee refs/heads/branch2 | ||
62fb502a7172d4453f0322a2cc85bddffa57f07a refs/heads/pr-to-update |
Binary file added
BIN
+833 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/5c/050d3b6d2db231ab1f64e324f1b6b9a0b181c2
Binary file not shown.
Binary file added
BIN
+839 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/62/fb502a7172d4453f0322a2cc85bddffa57f07a
Binary file not shown.
Binary file added
BIN
+86 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/6a/a3a5385611c5eb8986c9961a9c34a93cbaadfb
Binary file not shown.
Binary file added
BIN
+54 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/7c/4df115542e05c700f297519e906fd63c9c9804
Binary file not shown.
Binary file added
BIN
+54 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/94/922e1295c678267de1193b7b84ad8a086c27f9
Binary file not shown.
Binary file added
BIN
+842 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/98/5f0301dba5e7b34be866819cd15ad3d8f508ee
Binary file not shown.
Binary file added
BIN
+76 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/a6/9277c81e90b98a7c0ab25b042a6e296da8eb9a
Binary file not shown.
Binary file added
BIN
+61 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/a7/57c0ea621e63d0fd6fc353a175fdc7199e5d1d
Binary file not shown.
Binary file added
BIN
+20 Bytes
...gitea-repositories-meta/user2/repo1.git/objects/b2/60587271671842af0b036e4fe643c9d45b7ddd
Binary file not shown.
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/user2/repo1.git/refs/heads/branch2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
985f0301dba5e7b34be866819cd15ad3d8f508ee |
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/user2/repo1.git/refs/heads/pr-to-update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
62fb502a7172d4453f0322a2cc85bddffa57f07a |
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/user2/repo1.git/refs/pull/2/head
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4a357436d925b5c974181ff12a994538ddc5a269 |
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/user2/repo1.git/refs/pull/5/head
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
62fb502a7172d4453f0322a2cc85bddffa57f07a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2020 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 integrations | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/repofiles" | ||
repo_module "code.gitea.io/gitea/modules/repository" | ||
pull_service "code.gitea.io/gitea/services/pull" | ||
repo_service "code.gitea.io/gitea/services/repository" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPullUpdate(t *testing.T) { | ||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { | ||
//Create PR to test | ||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) | ||
org26 := models.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User) | ||
pr := createOutdatedPR(t, user, org26) | ||
|
||
//Test GetDiverging | ||
diffCount, err := pull_service.GetDiverging(pr) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 1, diffCount.Behind) | ||
assert.EqualValues(t, 1, diffCount.Ahead) | ||
|
||
message := fmt.Sprintf("Merge branch '%s' into %s", pr.BaseBranch, pr.HeadBranch) | ||
err = pull_service.Update(pr, user, message) | ||
assert.NoError(t, err) | ||
|
||
//Test GetDiverging after update | ||
diffCount, err = pull_service.GetDiverging(pr) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 0, diffCount.Behind) | ||
assert.EqualValues(t, 2, diffCount.Ahead) | ||
|
||
}) | ||
} | ||
|
||
func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullRequest { | ||
baseRepo, err := repo_service.CreateRepository(actor, actor, models.CreateRepoOptions{ | ||
Name: "repo-pr-update", | ||
Description: "repo-tmp-pr-update description", | ||
AutoInit: true, | ||
Gitignores: "C,C++", | ||
License: "MIT", | ||
Readme: "Default", | ||
IsPrivate: false, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, baseRepo) | ||
|
||
headRepo, err := repo_module.ForkRepository(actor, forkOrg, baseRepo, "repo-pr-update", "desc") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, headRepo) | ||
|
||
//create a commit on base Repo | ||
_, err = repofiles.CreateOrUpdateRepoFile(baseRepo, actor, &repofiles.UpdateRepoFileOptions{ | ||
TreePath: "File_A", | ||
Message: "Add File A", | ||
Content: "File A", | ||
IsNewFile: true, | ||
OldBranch: "master", | ||
NewBranch: "master", | ||
Author: &repofiles.IdentityOptions{ | ||
Name: actor.Name, | ||
Email: actor.Email, | ||
}, | ||
Committer: &repofiles.IdentityOptions{ | ||
Name: actor.Name, | ||
Email: actor.Email, | ||
}, | ||
Dates: &repofiles.CommitDateOptions{ | ||
Author: time.Now(), | ||
Committer: time.Now(), | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
|
||
//create a commit on head Repo | ||
_, err = repofiles.CreateOrUpdateRepoFile(headRepo, actor, &repofiles.UpdateRepoFileOptions{ | ||
TreePath: "File_B", | ||
Message: "Add File on PR branch", | ||
Content: "File B", | ||
IsNewFile: true, | ||
OldBranch: "master", | ||
NewBranch: "newBranch", | ||
Author: &repofiles.IdentityOptions{ | ||
Name: actor.Name, | ||
Email: actor.Email, | ||
}, | ||
Committer: &repofiles.IdentityOptions{ | ||
Name: actor.Name, | ||
Email: actor.Email, | ||
}, | ||
Dates: &repofiles.CommitDateOptions{ | ||
Author: time.Now(), | ||
Committer: time.Now(), | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
|
||
//create Pull | ||
pullIssue := &models.Issue{ | ||
RepoID: baseRepo.ID, | ||
Title: "Test Pull -to-update-", | ||
PosterID: actor.ID, | ||
Poster: actor, | ||
IsPull: true, | ||
} | ||
pullRequest := &models.PullRequest{ | ||
HeadRepoID: headRepo.ID, | ||
BaseRepoID: baseRepo.ID, | ||
HeadBranch: "newBranch", | ||
BaseBranch: "master", | ||
HeadRepo: headRepo, | ||
BaseRepo: baseRepo, | ||
Type: models.PullRequestGitea, | ||
} | ||
err = pull_service.NewPullRequest(baseRepo, pullIssue, nil, nil, pullRequest, nil) | ||
assert.NoError(t, err) | ||
|
||
issue := models.AssertExistsAndLoadBean(t, &models.Issue{Title: "Test Pull -to-update-"}).(*models.Issue) | ||
pr, err := models.GetPullRequestByIssueID(issue.ID) | ||
assert.NoError(t, err) | ||
|
||
return pr | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.