wip
This commit is contained in:
parent
f6bd0c10c0
commit
ac6fb96534
@ -688,13 +688,6 @@ func (e *GitHandlerImpl) GitSubmoduleList(gitPath, commitId string) (submoduleLi
|
||||
}
|
||||
|
||||
func (e *GitHandlerImpl) GitSubmoduleCommitId(cwd, packageName, commitId string) (subCommitId string, valid bool) {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
commitId = ""
|
||||
valid = false
|
||||
}
|
||||
}()
|
||||
|
||||
data_in, data_out := ChanIO{make(chan byte, 256)}, ChanIO{make(chan byte, 70)}
|
||||
var wg sync.WaitGroup
|
||||
|
||||
@ -705,6 +698,14 @@ func (e *GitHandlerImpl) GitSubmoduleCommitId(cwd, packageName, commitId string)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
subCommitId = "wrong"
|
||||
commitId = "ok"
|
||||
valid = false
|
||||
}
|
||||
}()
|
||||
|
||||
defer wg.Done()
|
||||
defer close(data_out.ch)
|
||||
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
transport "github.com/go-openapi/runtime/client"
|
||||
@ -56,31 +55,39 @@ const (
|
||||
ReviewStateUnknown models.ReviewStateType = ""
|
||||
)
|
||||
|
||||
type GiteaPRFetcher interface {
|
||||
GetAssociatedPRs(org, repo string, prNo int64) ([]*models.PullRequest, error)
|
||||
}
|
||||
|
||||
type GiteaMaintainershipInterface interface {
|
||||
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, error)
|
||||
}
|
||||
|
||||
type Gitea interface {
|
||||
type GiteaPRReviewFetcher interface {
|
||||
GetPullRequestAndReviews(org, project string, num int64) (*models.PullRequest, []*models.PullReview, error)
|
||||
}
|
||||
|
||||
type GiteaReviewRequester interface {
|
||||
RequestReviews(pr *models.PullRequest, reviewer string) ([]*models.PullReview, error)
|
||||
}
|
||||
|
||||
type GiteaReviewer interface {
|
||||
AddReviewComment(pr *models.PullRequest, state models.ReviewStateType, comment string) (*models.PullReview, error)
|
||||
}
|
||||
|
||||
type Gitea interface {
|
||||
GiteaReviewRequester
|
||||
GiteaReviewer
|
||||
GiteaPRReviewFetcher
|
||||
|
||||
GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error)
|
||||
SetNotificationRead(notificationId int64) error
|
||||
GetOrganization(orgName string) (*models.Organization, error)
|
||||
GetOrganizationRepositories(orgName string) ([]*models.Repository, error)
|
||||
CreateRepositoryIfNotExist(git Git, org Organization, repoName string) (*models.Repository, error)
|
||||
CreatePullRequestIfNotExist(repo *models.Repository, srcId, targetId, title, body string) (*models.PullRequest, error)
|
||||
RequestReviews(pr *models.PullRequest, reviewer string) ([]*models.PullReview, error)
|
||||
AddReviewComment(pr *models.PullRequest, state models.ReviewStateType, comment string) (*models.PullReview, error)
|
||||
GetRepositoryFileContent(org, repo, hash, path string) ([]byte, error)
|
||||
GetPullRequestFileContent(pr *models.PullRequest, path string) ([]byte, error)
|
||||
GetRecentPullRequests(org, repo string) ([]*models.PullRequest, error)
|
||||
GetRecentCommits(org, repo, branch string, commitNo int64) ([]*models.Commit, error)
|
||||
|
||||
GiteaMaintainershipInterface
|
||||
GiteaPRFetcher
|
||||
}
|
||||
|
||||
type GiteaTransport struct {
|
||||
@ -374,24 +381,6 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
|
||||
return c.Payload, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetAssociatedPRs(org, repo string, prNo int64) ([]*models.PullRequest, error) {
|
||||
prData, err := gitea.client.Repository.RepoGetPullRequest(
|
||||
repository.NewRepoGetPullRequestParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithIndex(prNo),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
desc := prData.Payload.Body
|
||||
strings.Split(desc, "\n")
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path string) ([]byte, error) {
|
||||
var retData []byte
|
||||
|
||||
|
@ -75,8 +75,8 @@ func TestSyncPR(t *testing.T) {
|
||||
Ref: "branch",
|
||||
Sha: "11eb36d5a58d7bb376cac59ac729a1986c6a7bfc63e7818e14382f545ccda985",
|
||||
Repo: &models.Repository{
|
||||
Name: "testRepo",
|
||||
Owner: &models.User {
|
||||
Name: "testRepo",
|
||||
Owner: &models.User{
|
||||
UserName: "test",
|
||||
},
|
||||
DefaultBranch: "main1",
|
||||
@ -116,7 +116,6 @@ func TestSyncPR(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
t.Run("Missing submodule in prjgit", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mock := mock_common.NewMockGitea(ctl)
|
||||
@ -125,20 +124,23 @@ func TestSyncPR(t *testing.T) {
|
||||
git.GitPath = t.TempDir()
|
||||
|
||||
config.GitProjectName = "prjGit"
|
||||
event.Repository.Name = "tester"
|
||||
event.Repository.Name = "testRepo"
|
||||
|
||||
setupGitForTests(t, git)
|
||||
|
||||
// mock.EXPECT().GetAssociatedPrjGitPR(event).Return(PrjGitPR, nil)
|
||||
oldSha := PrjGitPR.Head.Sha
|
||||
defer func() { PrjGitPR.Head.Sha = oldSha }()
|
||||
PrjGitPR.Head.Sha = "ab8adab91edb476b9762097d10c6379aa71efd6b60933a1c0e355ddacf419a95"
|
||||
|
||||
mock.EXPECT().GetPullRequestAndReviews(config.Organization, "testRepo", event.Pull_Request.Number).Return(modelPR, nil, nil)
|
||||
mock.EXPECT().GetPullRequestAndReviews(config.Organization, "prj", int64(24)).Return(PrjGitPR, nil, nil)
|
||||
|
||||
err := pr.Process(event, git, config)
|
||||
|
||||
if err == nil || err.Error() != "Cannot fetch submodule commit id in prjgit for 'tester'" {
|
||||
if err == nil || err.Error() != "Cannot fetch submodule commit id in prjgit for 'testRepo'" {
|
||||
t.Error("Invalid error received.", err)
|
||||
}
|
||||
})
|
||||
*/
|
||||
|
||||
t.Run("Missing PrjGit PR for the sync", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
|
@ -1,3 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"src.opensuse.org/autogits/common"
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
type Review interface {
|
||||
IsApproved() (bool, error)
|
||||
}
|
||||
|
||||
type PRInfo struct {
|
||||
pr *models.PullRequest
|
||||
reviews []*models.PullReview
|
||||
}
|
||||
|
||||
type ReviewSet struct {
|
||||
maintainers MaintainershipData
|
||||
prs []PRInfo
|
||||
}
|
||||
|
||||
func FetchReviewSet(gitea common.GiteaPRReviewFetcher, org, repo string, num int64) (*ReviewSet, error) {
|
||||
_,_, err := gitea.GetPullRequestAndReviews(org, repo, num)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, errors.New("Error")
|
||||
}
|
||||
|
@ -9,20 +9,6 @@ import (
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
)
|
||||
|
||||
type Review interface {
|
||||
IsApproved() (bool, error)
|
||||
}
|
||||
|
||||
type PRInfo struct {
|
||||
pr *models.PullRequest
|
||||
reviews []*models.PullReview
|
||||
}
|
||||
|
||||
type ReviewSet struct {
|
||||
maintainers MaintainershipData
|
||||
prs []PRInfo
|
||||
}
|
||||
|
||||
func fetchPRInfo(gitea GiteaPRInterface, pr common.BasicPR) PRInfo {
|
||||
data, reviews, _ := gitea.GetPullRequestAndReviews(pr.Org, pr.Repo, pr.Num)
|
||||
return PRInfo{
|
||||
|
@ -1,10 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/mock/gomock"
|
||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||
mock_common "src.opensuse.org/autogits/common/mock"
|
||||
)
|
||||
|
||||
func TestReview(t *testing.T) {
|
||||
@ -15,5 +20,30 @@ func TestReview(t *testing.T) {
|
||||
t.Fatal(string(out))
|
||||
}
|
||||
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
org string
|
||||
repo string
|
||||
pr_no int64
|
||||
pr *models.PullRequest
|
||||
err error
|
||||
}{
|
||||
{name: "Error fetching ReviewSet if there are missing links", org: "test", repo: "repo", pr_no: 42, pr: &models.PullRequest{Body: ""}},
|
||||
{name: "Error fetching ReviewSet if there are missing links", org: "test", repo: "repo", pr_no: 42, pr: &models.PullRequest{Body: ""}, err: errors.New("Missing PR")},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mock := mock_common.NewMockGiteaPRReviewFetcher(ctl)
|
||||
|
||||
mock.EXPECT().GetPullRequestAndReviews(test.org, test.repo, test.pr_no).Return(test.pr, nil, test.err)
|
||||
|
||||
_, err := FetchReviewSet(mock, "test", "repo", 42)
|
||||
if test.err != nil && err == nil {
|
||||
t.Fatal("Expected", test.err, "but got", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user