wip
This commit is contained in:
parent
72d5f64f90
commit
888582a74a
@ -16,8 +16,8 @@ type PRInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ReviewSet struct {
|
type ReviewSet struct {
|
||||||
maintainers MaintainershipData
|
prs []PRInfo
|
||||||
prs []PRInfo
|
config *common.AutogitConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPRData(gitea common.GiteaPRFetcher, org, repo string, num int64, currentSet []PRInfo) ([]PRInfo, error) {
|
func readPRData(gitea common.GiteaPRFetcher, org, repo string, num int64, currentSet []PRInfo) ([]PRInfo, error) {
|
||||||
@ -32,9 +32,11 @@ func readPRData(gitea common.GiteaPRFetcher, org, repo string, num int64, curren
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, refPRs := common.ExtractDescriptionAndPRs(bufio.NewScanner(strings.NewReader(pr.Body)))
|
_, refPRs := common.ExtractDescriptionAndPRs(bufio.NewScanner(strings.NewReader(pr.Body)))
|
||||||
|
/*
|
||||||
if len(refPRs) < 1 {
|
if len(refPRs) < 1 {
|
||||||
return nil, errors.New("missing links")
|
return nil, errors.New("missing links")
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
retSet := []PRInfo{PRInfo{pr: pr}}
|
retSet := []PRInfo{PRInfo{pr: pr}}
|
||||||
|
|
||||||
@ -55,6 +57,16 @@ func FetchReviewSet(gitea common.GiteaPRFetcher, org, repo string, num int64, co
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ReviewSet{prs: prs}, nil
|
return &ReviewSet{prs: prs, config: config}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rs *ReviewSet) GetPrjGitPR() (*models.PullRequest, error) {
|
||||||
|
for _, prinfo := range rs.prs {
|
||||||
|
if prinfo.pr.Base.Repo.Name == rs.config.GitProjectName && prinfo.pr.Base.Repo.Owner.UserName == rs.config.Organization {
|
||||||
|
return prinfo.pr, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("No PrjGit PR found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestPR(t *testing.T) {
|
|||||||
baseConfig := common.AutogitConfig{
|
baseConfig := common.AutogitConfig{
|
||||||
Reviewers: []string{"super1", "super2"},
|
Reviewers: []string{"super1", "super2"},
|
||||||
Branch: "branch",
|
Branch: "branch",
|
||||||
Organization: "test",
|
Organization: "foo",
|
||||||
GitProjectName: "barPrj",
|
GitProjectName: "barPrj",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,30 +38,34 @@ func TestPR(t *testing.T) {
|
|||||||
data []prdata
|
data []prdata
|
||||||
api_error string
|
api_error string
|
||||||
|
|
||||||
resLen int
|
resLen int
|
||||||
reviewed bool
|
reviewed bool
|
||||||
|
prjGitPRIndex int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Error fetching ReviewSet if there are missing links",
|
name: "Error fetching PullRequest",
|
||||||
data: []prdata{
|
data: []prdata{
|
||||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}, err: errors.New("Missing PR")},
|
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}, err: errors.New("Missing PR")},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Error fetching is missing links",
|
name: "Error fetching is missing links, fixable",
|
||||||
data: []prdata{
|
data: []prdata{
|
||||||
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
{pr: &models.PullRequest{Body: "", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||||
}, api_error: "missing links",
|
},
|
||||||
|
resLen: 1,
|
||||||
|
prjGitPRIndex: -1,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Review set is not consistent",
|
name: "Review set is not consistent, but fixable",
|
||||||
data: []prdata{
|
data: []prdata{
|
||||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||||
{pr: &models.PullRequest{Body: "", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
{pr: &models.PullRequest{Body: "", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||||
},
|
},
|
||||||
api_error: "missing links",
|
resLen: 2,
|
||||||
|
prjGitPRIndex: 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -70,7 +74,8 @@ func TestPR(t *testing.T) {
|
|||||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 42, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo", Owner: &models.User{UserName: "test"}}}}},
|
||||||
{pr: &models.PullRequest{Body: "PR: test/repo#42", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
{pr: &models.PullRequest{Body: "PR: test/repo#42", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||||
},
|
},
|
||||||
resLen: 2,
|
resLen: 2,
|
||||||
|
prjGitPRIndex: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Review set is consistent: 2pkg",
|
name: "Review set is consistent: 2pkg",
|
||||||
@ -79,7 +84,8 @@ func TestPR(t *testing.T) {
|
|||||||
{pr: &models.PullRequest{Body: "PR: test/repo#42\nPR: test/repo2#41", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
{pr: &models.PullRequest{Body: "PR: test/repo#42\nPR: test/repo2#41", Index: 22, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "barPrj", Owner: &models.User{UserName: "foo"}}}}},
|
||||||
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 41, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo2", Owner: &models.User{UserName: "test"}}}}},
|
{pr: &models.PullRequest{Body: "PR: foo/barPrj#22", Index: 41, Base: &models.PRBranchInfo{Repo: &models.Repository{Name: "repo2", Owner: &models.User{UserName: "test"}}}}},
|
||||||
},
|
},
|
||||||
resLen: 3,
|
resLen: 3,
|
||||||
|
prjGitPRIndex: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +108,10 @@ func TestPR(t *testing.T) {
|
|||||||
t.Fatal("Expected", test_err, "but got", err)
|
t.Fatal("Expected", test_err, "but got", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if res != nil {
|
||||||
|
t.Fatal("error but got ReviewSet?")
|
||||||
|
}
|
||||||
|
|
||||||
if test.api_error != "" {
|
if test.api_error != "" {
|
||||||
if err.Error() != test.api_error {
|
if err.Error() != test.api_error {
|
||||||
t.Fatal("expected", test.api_error, "but got", err)
|
t.Fatal("expected", test.api_error, "but got", err)
|
||||||
@ -117,10 +127,34 @@ func TestPR(t *testing.T) {
|
|||||||
if test.resLen != len(res.prs) {
|
if test.resLen != len(res.prs) {
|
||||||
t.Error("expected result len", test.resLen, "but got", len(res.prs))
|
t.Error("expected result len", test.resLen, "but got", len(res.prs))
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if res.IsReviewed() != test.reviewed {
|
pr, err := res.GetPrjGitPR()
|
||||||
t.Error("expected reviewed to be NOT", res.IsReviewed())
|
if test.prjGitPRIndex < 0 {
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expected error, but nothing")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
pr_found := false
|
||||||
|
if test.prjGitPRIndex >= 0 {
|
||||||
|
for i := range test.data {
|
||||||
|
if pr == test.data[i].pr && i == test.prjGitPRIndex {
|
||||||
|
t.Log("found at index", i)
|
||||||
|
pr_found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !pr_found {
|
||||||
|
t.Error("Cannot find expected PrjGit location in PrjGit set", pr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if pr != nil {
|
||||||
|
t.Log("Expected prjgit not found, but found?", pr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if res.IsReviewed() != test.reviewed {
|
||||||
|
t.Error("expected reviewed to be NOT", res.IsReviewed())
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user