mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
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>
This commit is contained in:
parent
9f40bb020e
commit
36943e56d6
32 changed files with 489 additions and 68 deletions
|
@ -134,7 +134,7 @@ func TestAPISearchIssue(t *testing.T) {
|
|||
var apiIssues []*api.Issue
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
|
||||
assert.Len(t, apiIssues, 8)
|
||||
assert.Len(t, apiIssues, 9)
|
||||
|
||||
query := url.Values{}
|
||||
query.Add("token", token)
|
||||
|
@ -142,7 +142,7 @@ func TestAPISearchIssue(t *testing.T) {
|
|||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.Len(t, apiIssues, 8)
|
||||
assert.Len(t, apiIssues, 9)
|
||||
|
||||
query.Add("state", "closed")
|
||||
link.RawQuery = query.Encode()
|
||||
|
@ -163,5 +163,5 @@ func TestAPISearchIssue(t *testing.T) {
|
|||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.Len(t, apiIssues, 0)
|
||||
assert.Len(t, apiIssues, 1)
|
||||
}
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
65f1bf27bc3bf70f64657658635e66094edbcb4d refs/heads/master
|
||||
985f0301dba5e7b34be866819cd15ad3d8f508ee refs/heads/branch2
|
||||
62fb502a7172d4453f0322a2cc85bddffa57f07a refs/heads/pr-to-update
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
985f0301dba5e7b34be866819cd15ad3d8f508ee
|
|
@ -0,0 +1 @@
|
|||
62fb502a7172d4453f0322a2cc85bddffa57f07a
|
|
@ -0,0 +1 @@
|
|||
4a357436d925b5c974181ff12a994538ddc5a269
|
|
@ -0,0 +1 @@
|
|||
62fb502a7172d4453f0322a2cc85bddffa57f07a
|
136
integrations/pull_update_test.go
Normal file
136
integrations/pull_update_test.go
Normal file
|
@ -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
|
||||
}
|
|
@ -56,9 +56,9 @@ func TestRepoActivity(t *testing.T) {
|
|||
list = htmlDoc.doc.Find("#merged-pull-requests").Next().Find("p.desc")
|
||||
assert.Len(t, list.Nodes, 1)
|
||||
|
||||
// Should be 2 merged proposed pull requests
|
||||
// Should be 3 merged proposed pull requests
|
||||
list = htmlDoc.doc.Find("#proposed-pull-requests").Next().Find("p.desc")
|
||||
assert.Len(t, list.Nodes, 2)
|
||||
assert.Len(t, list.Nodes, 3)
|
||||
|
||||
// Should be 3 new issues
|
||||
list = htmlDoc.doc.Find("#new-issues").Next().Find("p.desc")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue