Skip to content

Commit

Permalink
better match agreed rule
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Jan 16, 2025
1 parent 22be411 commit 7495e92
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contribs/github-bot/internal/conditions/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions contribs/github-bot/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))).
Expand Down
21 changes: 21 additions & 0 deletions contribs/github-bot/internal/requirements/draft.go
Original file line number Diff line number Diff line change
@@ -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{}
}
34 changes: 34 additions & 0 deletions contribs/github-bot/internal/requirements/draft_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
}
}

0 comments on commit 7495e92

Please sign in to comment.