diff --git a/contribs/github-bot/internal/conditions/draft.go b/contribs/github-bot/internal/conditions/draft.go index 2c263f2ae75..5d554b4b484 100644 --- a/contribs/github-bot/internal/conditions/draft.go +++ b/contribs/github-bot/internal/conditions/draft.go @@ -10,7 +10,7 @@ import ( // Draft Condition. type draft struct{} -var _ Condition = &baseBranch{} +var _ Condition = &draft{} func (*draft) IsMet(pr *github.PullRequest, details treeprint.Tree) bool { return utils.AddStatusNode(pr.GetDraft(), "This pull request is a draft", details) diff --git a/contribs/github-bot/internal/config/config.go b/contribs/github-bot/internal/config/config.go index 4c37bd81b6a..83219c04d1d 100644 --- a/contribs/github-bot/internal/config/config.go +++ b/contribs/github-bot/internal/config/config.go @@ -56,9 +56,9 @@ func Config(gh *client.GitHub) ([]AutomaticCheck, []ManualCheck) { }, { Description: "Pending initial approval by a review team member (and label matches review triage state)", - If: c.Not(c.AuthorAssociationIs("MEMBER")), + If: c.Not(c.AuthorInTeam(gh, "tech-staff")), Then: r. - If(r.ReviewByOrgMembers(gh, 1)). + If(r.Or(r.ReviewByOrgMembers(gh, 1), r.Draft())). // Either there was a first approval from a member, and we // assert that the label for triage-pending is removed... Then(r.Not(r.Label(gh, "review/triage-pending", r.LabelRemove))). diff --git a/contribs/github-bot/internal/requirements/draft.go b/contribs/github-bot/internal/requirements/draft.go new file mode 100644 index 00000000000..675ffa02090 --- /dev/null +++ b/contribs/github-bot/internal/requirements/draft.go @@ -0,0 +1,21 @@ +package requirements + +import ( + "github.com/gnolang/gno/contribs/github-bot/internal/utils" + + "github.com/google/go-github/v64/github" + "github.com/xlab/treeprint" +) + +// Draft Condition. +type draft struct{} + +var _ Requirement = &draft{} + +func (*draft) IsSatisfied(pr *github.PullRequest, details treeprint.Tree) bool { + return utils.AddStatusNode(pr.GetDraft(), "This pull request is a draft", details) +} + +func Draft() Requirement { + return &draft{} +} diff --git a/contribs/github-bot/internal/requirements/draft_test.go b/contribs/github-bot/internal/requirements/draft_test.go new file mode 100644 index 00000000000..ded4917b808 --- /dev/null +++ b/contribs/github-bot/internal/requirements/draft_test.go @@ -0,0 +1,34 @@ +package requirements + +import ( + "fmt" + "testing" + + "github.com/gnolang/gno/contribs/github-bot/internal/utils" + "github.com/google/go-github/v64/github" + "github.com/stretchr/testify/assert" + "github.com/xlab/treeprint" +) + +func TestDraft(t *testing.T) { + t.Parallel() + + for _, testCase := range []struct { + name string + isMet bool + }{ + {"draft is true", true}, + {"draft is false", false}, + } { + t.Run(testCase.name, func(t *testing.T) { + t.Parallel() + + pr := &github.PullRequest{Draft: &testCase.isMet} + details := treeprint.New() + req := Draft() + + assert.Equal(t, req.IsSatisfied(pr, details), testCase.isMet, fmt.Sprintf("condition should have a met status: %t", testCase.isMet)) + assert.True(t, utils.TestLastNodeStatus(t, testCase.isMet, details), fmt.Sprintf("condition details should have a status: %t", testCase.isMet)) + }) + } +}