Skip to content

Commit

Permalink
Merge pull request #1270 from rawlingsj/master
Browse files Browse the repository at this point in the history
chore: to improve kick the tyres experience and reduce the barrier to…
  • Loading branch information
jenkins-x-bot-test authored Apr 1, 2021
2 parents 8cd5caf + e6c07d6 commit cf1c5ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jenkins-x/go-scm v1.6.7 h1:Tc8yLV1B0OdKCbtQX76Bc5FfbsvShqa+HWrTky92vGY=
github.com/jenkins-x/go-scm v1.6.7/go.mod h1:yVqpMl3ZSkPWVcPi9EhcK3QtTM/anrtYqI//FqwrdxQ=
github.com/jenkins-x/go-scm v1.6.11 h1:rfynVghXbrJAC/wSSrBg2Qddgs1N0/HNjbuu2PGjAWM=
github.com/jenkins-x/go-scm v1.6.11/go.mod h1:yVqpMl3ZSkPWVcPi9EhcK3QtTM/anrtYqI//FqwrdxQ=
github.com/jenkins-x/pipeline v0.3.2-0.20210223153617-0d1186b27496 h1:yN90dXuD7TkAkYwKr5h2fT7bjA7osK7tMhuz31qL7gE=
github.com/jenkins-x/pipeline v0.3.2-0.20210223153617-0d1186b27496/go.mod h1:y1XwzBDu4EmOCfoeV2cUW2icCto/izTyjEKK5j0UmwA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
17 changes: 10 additions & 7 deletions pkg/plugins/approve/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func handleGenericComment(log *logrus.Entry, spc scmProviderClient, oc ownersCli
}

opts := optionsForRepo(config, ce.Repo.Namespace, ce.Repo.Name)
if !isApprovalCommand(botName, opts.LgtmActsAsApprove, &comment{Body: ce.Body, Author: ce.Author.Login}) {
if !isApprovalCommand(log, botName, opts.LgtmActsAsApprove, &comment{Body: ce.Body, Author: ce.Author.Login}) {
return nil
}

Expand Down Expand Up @@ -242,7 +242,7 @@ func handleReview(log *logrus.Entry, spc scmProviderClient, oc ownersClient, ser
// Check for an approval command is in the body. If one exists, let the
// genericCommentEventHandler handle this event. Approval commands override
// review state.
if isApprovalCommand(botName, opts.LgtmActsAsApprove, &comment{Body: re.Review.Body, Author: re.Review.Author.Login}) {
if isApprovalCommand(log, botName, opts.LgtmActsAsApprove, &comment{Body: re.Review.Body, Author: re.Review.Author.Login}) {
return nil
}

Expand Down Expand Up @@ -442,7 +442,7 @@ func handle(log *logrus.Entry, spc scmProviderClient, repo approvers.Repo, baseU
sort.SliceStable(comments, func(i, j int) bool {
return comments[i].Created.Before(comments[j].Created)
})
approveComments := filterComments(comments, approvalMatcher(botName, opts.LgtmActsAsApprove, opts.ConsiderReviewState()))
approveComments := filterComments(comments, approvalMatcher(log, botName, opts.LgtmActsAsApprove, opts.ConsiderReviewState()))
addApprovers(&approversHandler, approveComments, pr.author, opts.ConsiderReviewState())

for _, user := range pr.assignees {
Expand Down Expand Up @@ -513,14 +513,17 @@ func humanAddedApproved(spc scmProviderClient, log *logrus.Entry, org, repo stri
}
}

func approvalMatcher(botName string, lgtmActsAsApprove, reviewActsAsApprove bool) func(*comment) bool {
func approvalMatcher(log *logrus.Entry, botName string, lgtmActsAsApprove, reviewActsAsApprove bool) func(*comment) bool {
return func(c *comment) bool {
return isApprovalCommand(botName, lgtmActsAsApprove, c) || isApprovalState(botName, reviewActsAsApprove, c)
return isApprovalCommand(log, botName, lgtmActsAsApprove, c) || isApprovalState(botName, reviewActsAsApprove, c)
}
}

func isApprovalCommand(botName string, lgtmActsAsApprove bool, c *comment) bool {
if c.Author == botName || isDeprecatedBot(c.Author) {
func isApprovalCommand(log *logrus.Entry, botName string, lgtmActsAsApprove bool, c *comment) bool {
if c.Author == botName {
log.Warn("Approval is made by the bot, for production installs it is recommended to use a different bot user account that your personal one")
}
if isDeprecatedBot(c.Author) {
return false
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/plugins/trigger/generic-comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func handleGenericComment(c Client, trigger *plugins.Trigger, gc scmprovider.Gen
return err
}
if commentAuthor == botName {
c.Logger.Debug("Comment is made by the bot, skipping.")
return nil
c.Logger.Warn("Comment is made by the bot, for production installs it is recommended to use a different bot user account that your personal one")
}

pr, err := c.SCMProviderClient.GetPullRequest(org, repo, number)
Expand Down

0 comments on commit cf1c5ac

Please sign in to comment.