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

Add --silence-whitelist-errors server flag #313

Merged
merged 3 commits into from
Oct 16, 2018

Conversation

vanetix
Copy link
Contributor

@vanetix vanetix commented Oct 10, 2018

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.

@codecov
Copy link

codecov bot commented Oct 10, 2018

Codecov Report

Merging #313 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
cmd/server.go 79.02% <ø> (ø) ⬆️
server/events_controller.go 53.27% <100%> (+0.41%) ⬆️
server/server.go 62.44% <100%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f174bf8...05a0b09. Read the comment docs.

@vanetix vanetix changed the title Add initial implementation of --silence-repo-errors server flag Add initial implementation of --silence-whitelist-errors server flag Oct 11, 2018
Copy link
Member

@lkysow lkysow left a 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.

@@ -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
Copy link
Member

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.

@@ -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.
Copy link
Member

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.

@@ -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")
Copy link
Member

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"

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```")
Copy link
Member

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.

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> Do not comment...

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```")
Copy link
Member

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())

@@ -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", "", "")
Copy link
Member

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.

@@ -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", "", "")
Copy link
Member

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

@vanetix
Copy link
Contributor Author

vanetix commented Oct 16, 2018

Thanks! Totally forgot about the golang comment style. Also went ahead and removed the expRepo, _ := since gofmt was grumpy about no references to expRepo.

@vanetix
Copy link
Contributor Author

vanetix commented Oct 16, 2018

Removed, I thought it could probably be - just not really familiar with pegomock.

@lkysow lkysow changed the title Add initial implementation of --silence-whitelist-errors server flag Add --silence-whitelist-errors server flag Oct 16, 2018
Copy link
Member

@lkysow lkysow left a 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!

@lkysow lkysow merged commit 5cd7208 into runatlantis:master Oct 16, 2018
@vanetix vanetix deleted the f/silence-whitelist-errors branch October 16, 2018 17:55
@vanetix
Copy link
Contributor Author

vanetix commented Oct 16, 2018

No problem, thanks again for all your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants