Skip to content

Commit

Permalink
Make hold related commands only working for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinfish committed Mar 7, 2020
1 parent 9059b58 commit 9cc24bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 9cc24bd

Please sign in to comment.