Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherrypickapproved: Add option to approve PRs without lgtm or approved labels #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/plugins/cherrypickapproved/cherrypickapproved.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ func (h *handler) handle(log *logrus.Entry, gc plugins.PluginGitHubClient, e git
}()

var (
approvers []string
branchRe *regexp.Regexp
approvers []string
branchRe *regexp.Regexp
allowMissingApprovedLabel bool
allowMissingLGTMLabel bool
)

// Filter configurations
Expand All @@ -139,6 +141,8 @@ func (h *handler) handle(log *logrus.Entry, gc plugins.PluginGitHubClient, e git
foundRepoOrg = true
approvers = cfg.Approvers
branchRe = cfg.BranchRe
allowMissingApprovedLabel = cfg.AllowMissingApprovedLabel
allowMissingLGTMLabel = cfg.AllowMissingLGTMLabel
}
}

Expand Down Expand Up @@ -219,7 +223,7 @@ func (h *handler) handle(log *logrus.Entry, gc plugins.PluginGitHubClient, e git
return nil
}

if hasLGTMLabel && hasApprovedLabel && !hasInvalidLabels {
if (hasLGTMLabel || allowMissingLGTMLabel) && (hasApprovedLabel || allowMissingApprovedLabel) && !hasInvalidLabels {
if !hasCherryPickApprovedLabel {
if err := h.AddLabel(gc, org, repo, prNumber, labels.CpApproved); err != nil {
log.WithError(err).Errorf("failed to add the label: %s", labels.CpApproved)
Expand Down
28 changes: 28 additions & 0 deletions pkg/plugins/cherrypickapproved/cherrypickapproved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"sigs.k8s.io/prow/pkg/github"
"sigs.k8s.io/prow/pkg/labels"
"sigs.k8s.io/prow/pkg/plugins"
Expand Down Expand Up @@ -109,6 +110,33 @@ func TestHandle(t *testing.T) {
assert.EqualValues(t, 1, mock.RemoveLabelCallCount())
},
},
{
name: "success apply cherry-pick-approved label on PR without lgtm+approved",
config: []plugins.CherryPickApproved{
{
Org: testOrgRepo,
Repo: testOrgRepo,
BranchRe: regexp.MustCompile("^release-*"),
Approvers: []string{"user"},
AllowMissingApprovedLabel: true,
AllowMissingLGTMLabel: true,
},
},
prepare: func(mock *cherrypickapprovedfakes.FakeImpl) {
mock.GetCombinedStatusReturns(&github.CombinedStatus{}, nil)
mock.GetIssueLabelsReturns(
[]github.Label{
{Name: labels.CpUnapproved},
},
nil,
)
},
assert: func(mock *cherrypickapprovedfakes.FakeImpl, err error) {
assert.NoError(t, err)
assert.EqualValues(t, 1, mock.AddLabelCallCount())
assert.EqualValues(t, 1, mock.RemoveLabelCallCount())
},
},
{
name: "skip non approver",
config: []plugins.CherryPickApproved{{
Expand Down
4 changes: 4 additions & 0 deletions pkg/plugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ type CherryPickApproved struct {
BranchRe *regexp.Regexp `json:"-"`
// Approvers is the list of GitHub logins allowed to approve a cherry-pick.
Approvers []string `json:"approvers,omitempty"`
// AllowMissingApprovedLabel allows approving cherry-pick without the approved label.
AllowMissingApprovedLabel bool `json:"allow_missing_approved_label,omitempty"`
// AllowMissingLGTMLabel allows approving cherry-pick without the lgtm label.
AllowMissingLGTMLabel bool `json:"allow_missing_lgtm_label,omitempty"`
}

// CherryPickUnapproved is the config for the cherrypick-unapproved plugin.
Expand Down