-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add --silence-whitelist-errors server flag #313
Add --silence-whitelist-errors server flag #313
Conversation
Codecov Report
@@ Coverage Diff @@
## master #313 +/- ##
==========================================
+ Coverage 70.54% 70.56% +0.02%
==========================================
Files 61 61
Lines 3639 3642 +3
==========================================
+ Hits 2567 2570 +3
Misses 893 893
Partials 179 179
Continue to review full report at Codecov.
|
73165a7
to
23b5623
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a couple comments.
server/events_controller.go
Outdated
@@ -57,6 +57,9 @@ type EventsController struct { | |||
// request validation is done. | |||
GitlabWebhookSecret []byte | |||
RepoWhitelistChecker *events.RepoWhitelistChecker | |||
// Signifies if we post a comment when an event comes in for a non-whitelisted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment needs to start with // SilenceWhitelistErrors
as per golang comment style guide:
Notice this comment is a complete sentence that begins with the name of the element it describes...
https://blog.golang.org/godoc-documenting-go-code
ex:
// SilenceWhitelistErrors controls whether we write an error comment on pull requests from non-whitelisted repos.
server/events_controller.go
Outdated
@@ -418,6 +421,10 @@ func (e *EventsController) respond(w http.ResponseWriter, lvl logging.LogLevel, | |||
// commentNotWhitelisted comments on the pull request that the repo is not | |||
// whitelisted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to update this comment to read:
// commentNotWhitelisted comments on the pull request that the repo is not
// whitelisted unless whitelist error comments are disabled.
server/events_controller_test.go
Outdated
@@ -198,6 +198,35 @@ func TestPost_GitlabCommentNotWhitelisted(t *testing.T) { | |||
vcsClient.VerifyWasCalledOnce().CreateComment(expRepo, 1, "```\nError: This repo is not whitelisted for Atlantis.\n```") | |||
} | |||
|
|||
func TestPost_GitlabCommentNotWhitelistedWithSilenceErrors(t *testing.T) { | |||
t.Log("when the event is a gitlab comment from a repo that isn't whitelisted and we are silencing errors, do no comment with an error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing t in "do not comment"
server/events_controller_test.go
Outdated
exp := "Repo not whitelisted" | ||
Assert(t, strings.Contains(string(body), exp), "exp %q to be contained in %q", exp, string(body)) | ||
expRepo, _ := models.NewRepo(models.Gitlab, "gitlabhq/gitlab-test", "https://example.com/gitlabhq/gitlab-test.git", "", "") | ||
vcsClient.VerifyWasCalled(Never()).CreateComment(expRepo, 1, "```\nError: This repo is not whitelisted for Atlantis.\n```") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString())
Instead. This way we can ensure we never comment and the test won't pass even if we change the comment format.
server/events_controller_test.go
Outdated
@@ -227,6 +256,36 @@ func TestPost_GithubCommentNotWhitelisted(t *testing.T) { | |||
vcsClient.VerifyWasCalledOnce().CreateComment(expRepo, 2, "```\nError: This repo is not whitelisted for Atlantis.\n```") | |||
} | |||
|
|||
func TestPost_GithubCommentNotWhitelistedWithSilenceErrors(t *testing.T) { | |||
t.Log("when the event is a github comment from a repo that isn't whitelisted and we are silencing errors, do no comment with an error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> Do not comment...
server/events_controller_test.go
Outdated
exp := "Repo not whitelisted" | ||
Assert(t, strings.Contains(string(body), exp), "exp %q to be contained in %q", exp, string(body)) | ||
expRepo, _ := models.NewRepo(models.Github, "baxterthehacker/public-repo", "https://github.com/baxterthehacker/public-repo.git", "", "") | ||
vcsClient.VerifyWasCalled(Never()).CreateComment(expRepo, 2, "```\nError: This repo is not whitelisted for Atlantis.\n```") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString())
server/events_controller_test.go
Outdated
@@ -223,8 +223,9 @@ func TestPost_GitlabCommentNotWhitelistedWithSilenceErrors(t *testing.T) { | |||
body, _ := ioutil.ReadAll(w.Result().Body) | |||
exp := "Repo not whitelisted" | |||
Assert(t, strings.Contains(string(body), exp), "exp %q to be contained in %q", exp, string(body)) | |||
expRepo, _ := models.NewRepo(models.Gitlab, "gitlabhq/gitlab-test", "https://example.com/gitlabhq/gitlab-test.git", "", "") | |||
vcsClient.VerifyWasCalled(Never()).CreateComment(expRepo, 1, "```\nError: This repo is not whitelisted for Atlantis.\n```") | |||
models.NewRepo(models.Gitlab, "gitlabhq/gitlab-test", "https://example.com/gitlabhq/gitlab-test.git", "", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can delete this line.
server/events_controller_test.go
Outdated
@@ -282,8 +283,8 @@ func TestPost_GithubCommentNotWhitelistedWithSilenceErrors(t *testing.T) { | |||
body, _ := ioutil.ReadAll(w.Result().Body) | |||
exp := "Repo not whitelisted" | |||
Assert(t, strings.Contains(string(body), exp), "exp %q to be contained in %q", exp, string(body)) | |||
expRepo, _ := models.NewRepo(models.Github, "baxterthehacker/public-repo", "https://github.com/baxterthehacker/public-repo.git", "", "") | |||
vcsClient.VerifyWasCalled(Never()).CreateComment(expRepo, 2, "```\nError: This repo is not whitelisted for Atlantis.\n```") | |||
models.NewRepo(models.Github, "baxterthehacker/public-repo", "https://github.com/baxterthehacker/public-repo.git", "", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this line too
Thanks! Totally forgot about the golang comment style. Also went ahead and removed the |
Removed, I thought it could probably be - just not really familiar with pegomock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, great work!
No problem, thanks again for all your work! |
Fixes #312
Some users would like to add the Atlantis webhook at the org level and then use the whitelist to configure which repos Atlantis actually runs on. In this configuration, it's annoying that Atlantis continually comments on pull requests "Repo is not whitelisted".
This PR adds a flag
--silence-whitelist-errors
which will prevent commenting back on the pull request.