From e6c07d67b311b31ea4aeb64bd15efd758aca6d66 Mon Sep 17 00:00:00 2001 From: James Rawlings Date: Thu, 1 Apr 2021 12:09:04 +0100 Subject: [PATCH] chore: to improve kick the tyres experience and reduce the barrier to entry lets allow the bot user to be a personal account but warn that production installs should use separate accounts --- go.sum | 2 ++ pkg/plugins/approve/approve.go | 17 ++++++++++------- pkg/plugins/trigger/generic-comment.go | 3 +-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/go.sum b/go.sum index c60f39755..1811b2362 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/plugins/approve/approve.go b/pkg/plugins/approve/approve.go index 306bfe0fa..bbd95a9d2 100644 --- a/pkg/plugins/approve/approve.go +++ b/pkg/plugins/approve/approve.go @@ -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 } @@ -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 } @@ -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 { @@ -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 } diff --git a/pkg/plugins/trigger/generic-comment.go b/pkg/plugins/trigger/generic-comment.go index bb1c6bc6c..62cc5ef15 100644 --- a/pkg/plugins/trigger/generic-comment.go +++ b/pkg/plugins/trigger/generic-comment.go @@ -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)