wip
This commit is contained in:
parent
c1df08dc59
commit
6fc0607823
@ -85,6 +85,7 @@ type Gitea interface {
|
|||||||
GiteaReviewRequester
|
GiteaReviewRequester
|
||||||
GiteaReviewer
|
GiteaReviewer
|
||||||
GiteaPRFetcher
|
GiteaPRFetcher
|
||||||
|
GiteaReviewFetcher
|
||||||
|
|
||||||
GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error)
|
GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error)
|
||||||
SetNotificationRead(notificationId int64) error
|
SetNotificationRead(notificationId int64) error
|
||||||
@ -137,10 +138,9 @@ func (gitea *GiteaTransport) GetPullRequest(org, project string, num int64) (*mo
|
|||||||
return pr.Payload, err
|
return pr.Payload, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gitea *GiteaTransport) GetPullReviews(org, project string, num int64) ([]*models.PullReview, error) {
|
func (gitea *GiteaTransport) GetPullRequestReviews(org, project string, PRnum int64) ([]*models.PullReview, error) {
|
||||||
limit := int64(20)
|
limit := int64(20)
|
||||||
var page int64
|
var page int64
|
||||||
|
|
||||||
var allReviews []*models.PullReview
|
var allReviews []*models.PullReview
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -149,7 +149,7 @@ func (gitea *GiteaTransport) GetPullReviews(org, project string, num int64) ([]*
|
|||||||
WithDefaults().
|
WithDefaults().
|
||||||
WithOwner(org).
|
WithOwner(org).
|
||||||
WithRepo(project).
|
WithRepo(project).
|
||||||
WithIndex(num).
|
WithIndex(PRnum).
|
||||||
WithPage(&page).
|
WithPage(&page).
|
||||||
WithLimit(&limit),
|
WithLimit(&limit),
|
||||||
gitea.transport.DefaultAuthentication,
|
gitea.transport.DefaultAuthentication,
|
||||||
|
@ -111,3 +111,31 @@ func (rs *PRSet) IsReviewed(gitea common.GiteaReviewFetcher) bool {
|
|||||||
}
|
}
|
||||||
return is_reviewed
|
return is_reviewed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rs *PRSet) Merge() error {
|
||||||
|
prjgit, err := rs.GetPrjGitPR()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
gh:=common.GitHandlerGeneratorImpl{}
|
||||||
|
git, err := gh.CreateGitHandler(GitAuthor, GitEmail, prjgit.Base.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
git.GitExecOrPanic("", "clone", "--depth", "1", prjgit.Base.Repo.SSHURL, common.DefaultGitPrj)
|
||||||
|
git.GitExecOrPanic(common.DefaultGitPrj, "fetch", common.DefaultGitPrj, "origin", prjgit.Base.Sha, prjgit.Head.Sha)
|
||||||
|
|
||||||
|
// if other changes merged, check if we have conflicts
|
||||||
|
rev := git.GitExecWithOutputOrPanic(common.DefaultGitPrj, "rev-list", "-1", "HEAD")
|
||||||
|
if rev != prjgit.Base.Sha {
|
||||||
|
panic("FIXME")
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := "haha"
|
||||||
|
|
||||||
|
git.GitExecOrPanic(common.DefaultGitPrj, "merge", "--no-ff", "-m", msg, prjgit.Head.Sha)
|
||||||
|
git.GitExecOrPanic(common.DefaultGitPrj, "push", "origin")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,18 @@ package main
|
|||||||
import "src.opensuse.org/autogits/common"
|
import "src.opensuse.org/autogits/common"
|
||||||
|
|
||||||
type PullRequestReviewed struct {
|
type PullRequestReviewed struct {
|
||||||
|
gitea common.Gitea
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *PullRequestReviewed) Process(req *common.PullRequestWebhookEvent, git common.Git, config *common.AutogitConfig) error {
|
func (o *PullRequestReviewed) Process(req *common.PullRequestWebhookEvent, git common.Git, config *common.AutogitConfig) error {
|
||||||
|
prset, err := FetchPRSet(o.gitea, req.Repository.Owner.Username, req.Repository.Name, req.Number, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if prset.IsReviewed(o.gitea) {
|
||||||
|
prset.Merge()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"go.uber.org/mock/gomock"
|
||||||
"src.opensuse.org/autogits/common"
|
"src.opensuse.org/autogits/common"
|
||||||
|
mock_common "src.opensuse.org/autogits/common/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPRReviewed(t *testing.T) {
|
func TestPRReviewed(t *testing.T) {
|
||||||
@ -39,6 +41,7 @@ func TestPRReviewed(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Repository: &common.Repository{
|
Repository: &common.Repository{
|
||||||
|
Name: "testRepo",
|
||||||
Owner: &common.Organization{
|
Owner: &common.Organization{
|
||||||
Username: "test",
|
Username: "test",
|
||||||
},
|
},
|
||||||
@ -47,7 +50,15 @@ func TestPRReviewed(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range testData {
|
for _, test := range testData {
|
||||||
t.Run(test.title, func(t *testing.T) {
|
t.Run(test.title, func(t *testing.T) {
|
||||||
s := PullRequestReviewed{}
|
ctl := gomock.NewController(t)
|
||||||
|
mock := mock_common.NewMockGitea(ctl)
|
||||||
|
|
||||||
|
s := PullRequestReviewed{
|
||||||
|
gitea: mock,
|
||||||
|
}
|
||||||
|
|
||||||
|
mock.EXPECT().GetPullRequest("test", "testRepo", int64(1)).Return(nil, nil)
|
||||||
|
|
||||||
if err := s.Process(event, nil, nil); err != test.error {
|
if err := s.Process(event, nil, nil); err != test.error {
|
||||||
t.Error("unexected error:", err, "Expected:", test.error)
|
t.Error("unexected error:", err, "Expected:", test.error)
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPR(t *testing.T) {
|
func TestPR(t *testing.T) {
|
||||||
cwd, _ := os.Getwd()
|
|
||||||
cmd := exec.Command("/usr/bin/bash", path.Join(cwd, "test_repo_setup.sh"))
|
|
||||||
cmd.Dir = t.TempDir()
|
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
t.Fatal(string(out))
|
|
||||||
}
|
|
||||||
|
|
||||||
baseConfig := common.AutogitConfig{
|
baseConfig := common.AutogitConfig{
|
||||||
Reviewers: []string{"super1", "super2"},
|
Reviewers: []string{"super1", "super2"},
|
||||||
Branch: "branch",
|
Branch: "branch",
|
||||||
@ -116,7 +109,7 @@ func TestPR(t *testing.T) {
|
|||||||
resLen: 1,
|
resLen: 1,
|
||||||
prjGitPRIndex: 0,
|
prjGitPRIndex: 0,
|
||||||
consistentSet: true,
|
consistentSet: true,
|
||||||
reviewed: true,
|
reviewed: true,
|
||||||
reviewSetFetcher: func(mock *mock_common.MockGiteaPRFetcher) (*PRSet, error) {
|
reviewSetFetcher: func(mock *mock_common.MockGiteaPRFetcher) (*PRSet, error) {
|
||||||
return FetchPRSet(mock, "foo", "barPrj", 42, &baseConfig)
|
return FetchPRSet(mock, "foo", "barPrj", 42, &baseConfig)
|
||||||
},
|
},
|
||||||
@ -225,3 +218,29 @@ func TestPR(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPRMerge(t *testing.T) {
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
|
cmd := exec.Command("/usr/bin/bash", path.Join(cwd, "test_repo_setup.sh"))
|
||||||
|
cmd.Dir = t.TempDir()
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
t.Fatal(string(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
prjgit_base, prjgit_head string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Merge conflicts in submodules",
|
||||||
|
prjgit_base: "base_add_b1",
|
||||||
|
prjgit_head: "base_add_b2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,6 +26,8 @@ create_prjgit_sample() {
|
|||||||
|
|
||||||
git submodule init
|
git submodule init
|
||||||
git submodule -q add ../pkgA pkgA
|
git submodule -q add ../pkgA pkgA
|
||||||
|
git submodule -q add ../pkgB pkgB
|
||||||
|
git submodule -q add ../pkgC pkgC
|
||||||
|
|
||||||
git commit -q -m 'first commit'
|
git commit -q -m 'first commit'
|
||||||
|
|
||||||
@ -45,7 +47,62 @@ create_pkgA() {
|
|||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_pkgB() {
|
||||||
|
mkdir pkgB
|
||||||
|
pushd pkgB
|
||||||
|
|
||||||
|
git init -q --object-format=sha256
|
||||||
|
echo "Package B" > README.md
|
||||||
|
git add README.md
|
||||||
|
|
||||||
|
git commit -q -m 'Something also base here'
|
||||||
|
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
create_pkgB1() {
|
||||||
|
mkdir pkgB1
|
||||||
|
pushd pkgB1
|
||||||
|
|
||||||
|
git init -q --object-format=sha256
|
||||||
|
echo "Package B1" > README.md
|
||||||
|
git add README.md
|
||||||
|
|
||||||
|
git commit -q -m 'Something also base here'
|
||||||
|
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
create_pkgB2() {
|
||||||
|
mkdir pkgB2
|
||||||
|
pushd pkgB2
|
||||||
|
|
||||||
|
git init -q --object-format=sha256
|
||||||
|
echo "Package B2" > README.md
|
||||||
|
git add README.md
|
||||||
|
|
||||||
|
git commit -q -m 'Something also base here'
|
||||||
|
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
create_pkgC() {
|
||||||
|
mkdir pkgC
|
||||||
|
pushd pkgC
|
||||||
|
|
||||||
|
git init -q --object-format=sha256
|
||||||
|
echo "Package C" > README.md
|
||||||
|
git add README.md
|
||||||
|
|
||||||
|
git commit -q -m 'Something another base here'
|
||||||
|
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
create_pkgA
|
create_pkgA
|
||||||
|
create_pkgB
|
||||||
|
create_pkgB1
|
||||||
|
create_pkgB2
|
||||||
|
create_pkgC
|
||||||
create_prjgit_sample
|
create_prjgit_sample
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user