Skip to content

Commit

Permalink
Merge branch 'main' into parallel_operation_config
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudomorph authored May 9, 2023
2 parents 80a28ff + 898f781 commit 9fa0d02
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ WORKDIR /tmp/build

# install conftest
# renovate: datasource=github-releases depName=open-policy-agent/conftest
ENV DEFAULT_CONFTEST_VERSION=0.41.0
ENV DEFAULT_CONFTEST_VERSION=0.42.1
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN AVAILABLE_CONFTEST_VERSIONS=${DEFAULT_CONFTEST_VERSION} && \
case ${TARGETPLATFORM} in \
Expand Down Expand Up @@ -174,7 +174,7 @@ COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main/ \
git~=2.40 && \
apk add --no-cache \
ca-certificates~=20220614 \
ca-certificates~=20230506 \
curl~=8.0 \
unzip~=6.0 \
bash~=5.2 \
Expand Down
4 changes: 4 additions & 0 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Values are chosen in this order:
and in links from pull request comments. Defaults to `http://$(hostname):$port`
where `$port` is from the [`--port`](#port) flag. Supports a basepath if you're hosting Atlantis under a path.

Notes:
* If a load balancer with a non http/https port (not the one defined in the `--port` flag) is used, update the URL to include the port like in the example above.
* This URL is used as the `details` link next to each atlantis job to view the job's logs.

### `--automerge`
```bash
atlantis server --automerge
Expand Down
29 changes: 15 additions & 14 deletions server/controllers/events/events_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,11 @@ func (e *VCSEventsController) HandleGithubCommentEvent(event *github.IssueCommen
}
}

body := event.GetComment().GetBody()

if strings.HasPrefix(body, e.ExecutableName+" ") {
err = e.VCSClient.ReactToComment(baseRepo, *event.Comment.ID, e.EmojiReaction)
if err != nil {
logger.Warn("Failed to react to comment: %s", err)
}
}
comment := event.GetComment()

// We pass in nil for maybeHeadRepo because the head repo data isn't
// available in the GithubIssueComment event.
return e.handleCommentEvent(logger, baseRepo, nil, nil, user, pullNum, body, models.Github)
return e.handleCommentEvent(logger, baseRepo, nil, nil, user, pullNum, comment.GetBody(), comment.GetID(), models.Github)
}

// HandleBitbucketCloudCommentEvent handles comment events from Bitbucket.
Expand All @@ -332,7 +325,7 @@ func (e *VCSEventsController) HandleBitbucketCloudCommentEvent(w http.ResponseWr
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s=%s", err, bitbucketCloudRequestIDHeader, reqID)
return
}
resp := e.handleCommentEvent(e.Logger, baseRepo, &headRepo, &pull, user, pull.Num, comment, models.BitbucketCloud)
resp := e.handleCommentEvent(e.Logger, baseRepo, &headRepo, &pull, user, pull.Num, comment, -1, models.BitbucketCloud)

//TODO: move this to the outer most function similar to github
lvl := logging.Debug
Expand All @@ -353,7 +346,7 @@ func (e *VCSEventsController) HandleBitbucketServerCommentEvent(w http.ResponseW
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s=%s", err, bitbucketCloudRequestIDHeader, reqID)
return
}
resp := e.handleCommentEvent(e.Logger, baseRepo, &headRepo, &pull, user, pull.Num, comment, models.BitbucketCloud)
resp := e.handleCommentEvent(e.Logger, baseRepo, &headRepo, &pull, user, pull.Num, comment, -1, models.BitbucketCloud)

//TODO: move this to the outer most function similar to github
lvl := logging.Debug
Expand Down Expand Up @@ -527,7 +520,7 @@ func (e *VCSEventsController) HandleGitlabCommentEvent(w http.ResponseWriter, ev
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing webhook: %s", err)
return
}
resp := e.handleCommentEvent(e.Logger, baseRepo, &headRepo, nil, user, event.MergeRequest.IID, event.ObjectAttributes.Note, models.Gitlab)
resp := e.handleCommentEvent(e.Logger, baseRepo, &headRepo, nil, user, event.MergeRequest.IID, event.ObjectAttributes.Note, -1, models.Gitlab)

//TODO: move this to the outer most function similar to github
lvl := logging.Debug
Expand All @@ -541,7 +534,7 @@ func (e *VCSEventsController) HandleGitlabCommentEvent(w http.ResponseWriter, ev
e.respond(w, lvl, code, msg)
}

func (e *VCSEventsController) handleCommentEvent(logger logging.SimpleLogging, baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, user models.User, pullNum int, comment string, vcsHost models.VCSHostType) HTTPResponse {
func (e *VCSEventsController) handleCommentEvent(logger logging.SimpleLogging, baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, user models.User, pullNum int, comment string, commentID int64, vcsHost models.VCSHostType) HTTPResponse {
parseResult := e.CommentParser.Parse(comment, vcsHost)
if parseResult.Ignore {
truncated := comment
Expand Down Expand Up @@ -572,6 +565,14 @@ func (e *VCSEventsController) handleCommentEvent(logger logging.SimpleLogging, b
}
}

// It's a comment we're gonna react to, so add a reaction.
if e.EmojiReaction != "" {
err := e.VCSClient.ReactToComment(baseRepo, commentID, e.EmojiReaction)
if err != nil {
logger.Warn("Failed to react to comment: %s", err)
}
}

// If the command isn't valid or doesn't require processing, ex.
// "atlantis help" then we just comment back immediately.
// We do this here rather than earlier because we need access to the pull
Expand Down Expand Up @@ -665,7 +666,7 @@ func (e *VCSEventsController) HandleAzureDevopsPullRequestCommentedEvent(w http.
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull request repository field: %s; %s", err, azuredevopsReqID)
return
}
resp := e.handleCommentEvent(e.Logger, baseRepo, nil, nil, user, resource.PullRequest.GetPullRequestID(), string(strippedComment), models.AzureDevops)
resp := e.handleCommentEvent(e.Logger, baseRepo, nil, nil, user, resource.PullRequest.GetPullRequestID(), string(strippedComment), -1, models.AzureDevops)

//TODO: move this to the outer most function similar to github
lvl := logging.Debug
Expand Down
5 changes: 3 additions & 2 deletions server/controllers/events/events_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestPost_GitlabCommentInvalidCommand(t *testing.T) {

func TestPost_GithubCommentInvalidCommand(t *testing.T) {
t.Log("when the event is a github comment with an invalid command we ignore it")
e, v, _, _, p, _, _, _, cp := setup(t)
e, v, _, _, p, _, _, vcsClient, cp := setup(t)
req, _ := http.NewRequest("GET", "", bytes.NewBuffer(nil))
req.Header.Set(githubHeader, "issue_comment")
event := `{"action": "created"}`
Expand All @@ -189,6 +189,7 @@ func TestPost_GithubCommentInvalidCommand(t *testing.T) {
w := httptest.NewRecorder()
e.Post(w, req)
ResponseContains(t, w, http.StatusOK, "Ignoring non-command comment: \"\"")
vcsClient.VerifyWasCalled(Never()).ReactToComment(models.Repo{}, 1, "eyes")
}

func TestPost_GitlabCommentNotAllowlisted(t *testing.T) {
Expand Down Expand Up @@ -386,7 +387,7 @@ func TestPost_GithubCommentReaction(t *testing.T) {
e, v, _, _, p, _, _, vcsClient, cp := setup(t)
req, _ := http.NewRequest("GET", "", bytes.NewBuffer(nil))
req.Header.Set(githubHeader, "issue_comment")
event := `{"action": "created", "comment": {"body": "atlantis help", "id": 1}}`
event := `{"action": "created", "comment": {"body": "@atlantis-bot help", "id": 1}}`
When(v.Validate(req, secret)).ThenReturn([]byte(event), nil)
baseRepo := models.Repo{}
user := models.User{}
Expand Down
2 changes: 1 addition & 1 deletion testing/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN case $(uname -m) in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64|armv7l) ARCH

# Install conftest
# renovate: datasource=github-releases depName=open-policy-agent/conftest
ENV CONFTEST_VERSION=0.41.0
ENV CONFTEST_VERSION=0.42.0
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN case $(uname -m) in x86_64|amd64) ARCH="x86_64" ;; aarch64|arm64|armv7l) ARCH="arm64" ;; esac && \
curl -LOs https://github.com/open-policy-agent/conftest/releases/download/v${CONFTEST_VERSION}/conftest_${CONFTEST_VERSION}_Linux_${ARCH}.tar.gz && \
Expand Down

0 comments on commit 9fa0d02

Please sign in to comment.