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

Make hold related commands only working for PR #16667

Merged
merged 1 commit into from
Mar 7, 2020
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
3 changes: 3 additions & 0 deletions prow/plugins/hold/hold.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func handleGenericComment(pc plugins.Agent, e github.GenericCommentEvent) error
// a /hold directive, we want to add a label if one does not already exist.
// If they add /hold cancel, we want to remove the label if it exists.
func handle(gc githubClient, log *logrus.Entry, e *github.GenericCommentEvent, f hasLabelFunc) error {
if !e.IsPR {
return nil
}
if e.Action != github.GenericCommentActionCreated {
return nil
}
Expand Down
30 changes: 30 additions & 0 deletions prow/plugins/hold/hold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,90 +34,119 @@ func TestHandle(t *testing.T) {
hasLabel bool
shouldLabel bool
shouldUnlabel bool
isPR bool
}{
{
name: "nothing to do",
body: "noise",
hasLabel: false,
shouldLabel: false,
shouldUnlabel: false,
isPR: true,
},
{
name: "quoted hold in a reply",
body: "> /hold",
hasLabel: false,
shouldLabel: false,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested hold",
body: "/hold",
hasLabel: false,
shouldLabel: true,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested hold with reason",
body: "/hold for further review",
hasLabel: false,
shouldLabel: true,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested hold, Label already exists",
body: "/hold",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested hold with reason, Label already exists",
body: "/hold for further review",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested hold cancel",
body: "/hold cancel",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: true,
isPR: true,
},
{
name: "requested hold cancel with whitespace",
body: "/hold cancel ",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: true,
isPR: true,
},
{
name: "requested hold cancel, Label already gone",
body: "/hold cancel",
hasLabel: false,
shouldLabel: false,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested unhold",
body: "/unhold",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: true,
isPR: true,
},
{
name: "requested unhold with whitespace",
body: "/unhold ",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: true,
isPR: true,
},
{
name: "requested unhold, Label already gone",
body: "/unhold",
hasLabel: false,
shouldLabel: false,
shouldUnlabel: false,
isPR: true,
},
{
name: "requested hold for issues",
body: "/hold",
hasLabel: false,
shouldLabel: false,
shouldUnlabel: false,
isPR: false,
},
{
name: "requested unhold for issues",
body: "/unhold",
hasLabel: true,
shouldLabel: false,
shouldUnlabel: false,
isPR: false,
},
}

Expand All @@ -131,6 +160,7 @@ func TestHandle(t *testing.T) {
Body: tc.body,
Number: 1,
Repo: github.Repo{Owner: github.User{Login: "org"}, Name: "repo"},
IsPR: tc.isPR,
}
hasLabel := func(label string, issueLabels []github.Label) bool {
return tc.hasLabel
Expand Down