Commit Graph

805 Commits

Author SHA1 Message Date
jskrill
00aae565b2 feat: add autodiscover enabled feature (#3895)
* add flag to allow the user disable the autodiscover

* add global config and doc

* feat: Implement autodiscover.mode

* fix: Minor doc fixes

* fix: Small fixes to docs/indent/tests

* fix: Line length, quoting, function comments

* fix: Add a few more tests and remove newlines

* fix: Always camel case never snake

---------

Co-authored-by: Marcelo Medeiros <m.medeiros@carepay.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-11-29 15:43:53 -08:00
Henry Muru Paenga
ce2b99223a fix: Check user permissions on autoplan (#3742)
* Check user permissions on autoplan

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-11-14 22:21:11 -08:00
Simon Heather
1b45fb1ae1 fix: When GitHub/GitLab Auto-Merge Is Used with Atlantis Pre Workflow Hooks, the PR will be Merged Prematurely (#3880)
* Fix Premature Auto-Merge

* Add CommitStatusUpdater to commandRunner
2023-11-03 22:41:16 -04:00
Simon Heather
3056701c6b fix: Update GitLab Pipeline Type Detection to use Head Pipeline Property (#3887)
* Fix GitLab Mulitple Pipelines

* Add logger to tests and fix test ref

* Add retry to GetMergeRequest

* Update retries

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-11-03 22:22:12 -04:00
Simon Heather
edc9bd9262 feat: Improve GitHub and GitLab Debug Logging (#3876)
* Improve GitHub and GitLab Debug Logging

* Fix formatting

* Fix g.client.Repositories.Get debug message

* Update gitlab_client_test with logger

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-10-20 08:49:57 -07:00
Rui Chen
23b373e8a6 fix: add misspell check for linting codebase (#3865)
* add misspell check

* lint: fix misspell issues

```
server/events/vcs/instrumented_client.go:46:26: `soley` is a misspelling of `solely` (misspell)
// methods and implement soley any github specific interfaces.
                         ^
server/events/project_command_context_builder.go:49:5: `Conciously` is a misspelling of `Consciously` (misspell)
	// Conciously making this global since it gets flushed periodically anyways
	   ^
server/controllers/events/gitlab_request_parser_validator.go:87:32: `noteable` is a misspelling of `notable` (misspell)
				NoteableType string `json:"noteable_type"`
				                           ^
server/controllers/events/gitlab_request_parser_validator_test.go:351:6: `noteable` is a misspelling of `notable` (misspell)
    "noteable_type": "MergeRequest",
     ^
server/controllers/events/gitlab_request_parser_validator_test.go:359:6: `noteable` is a misspelling of `notable` (misspell)
    "noteable_id": 7,
     ^
server/controllers/events/gitlab_request_parser_validator_test.go:467:6: `noteable` is a misspelling of `notable` (misspell)
    "noteable_type": "Commit",
     ^
server/controllers/events/gitlab_request_parser_validator_test.go:475:6: `noteable` is a misspelling of `notable` (misspell)
    "noteable_id": null,
     ^
server/events/event_parser_test.go:1012:23: `seperate` is a misspelling of `separate` (misspell)
	// If sha changes in seperate PR,
	                     ^
```

Signed-off-by: Rui Chen <rui@chenrui.dev>

* add locale setting

Signed-off-by: Rui Chen <rui@chenrui.dev>

* Revert "lint: fix misspell issues"

This reverts commit 7cc56afa8e.

* lint: fix some misspell issues

Signed-off-by: Rui Chen <rui@chenrui.dev>

---------

Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-10-16 20:17:57 +00:00
Koen van Zuijlen
786e57c1d6 feat: Added disable-unlock-label config option (#3799)
* Added disable-unlock-label config option

* Fixed tests

* Wrote tests + fixed mistakes

* Added docs

* added defaults to docs

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-10-10 11:02:26 -04:00
Leandro López
df04456325 Return error on InstrumentedClient.MergePull (#3839)
When the underlying GitHub Client returns an error it gets swallowed
in this wrapper method. Not only that but also the emitted metrics are
wrong, as it counts one error AND success at the same time.

We've found this @grafana when using Atlantis in a massive repository
with many changes per minute, and sometimes Atlantis leave a comment
saying it's automatically merging but then nothing happens. But
checking the logs, we've found the following error message:

    Unable to merge pull, error: merging pull request: PUT
    https://api.github.com/repos/grafana/redacted/pulls/666/merge: 405
    Base branch was modified. Review and try the merge again. []

And because the error is swallowed and `InstrumentedClient.MergePull`
returns `nil`, then `Automerger` fails to leave a comment saying
merging failed.
2023-10-09 14:18:07 -07:00
PePe Amengual
d083aa119f Revert "feat: Add project depends on functionality (#3821)" (#3825)
This reverts commit cf2b7911f4.
2023-10-06 11:35:38 -04:00
Finn Arne Gangstad
4a921b3d65 fix: make go-generate now creates working mocks out of the box (#3802)
* Rename arguments in mocked functions from result to res

The code generated by pegomock is broken if any of the arguments to the
mocked function are named "result", so they must be named something else.

* Regenerate all mocks with make go-generate

The mocks now work without further modification after running go-generate.
2023-10-06 11:04:34 -04:00
Brett Galkowski
22060fe5d2 feat: Add option allowing usage of custom policy check tools (#3765)
* Adding new flag everywhere relevant, implementing policy result workaround

* Fixing unit test str matching, adding custom policy conditional to step_runner

* Adding documentation steps for custom policy tools

* Refactoring ConftestOutput attribute to PolicyOutput
2023-10-06 10:57:29 -04:00
Vincent
cf2b7911f4 feat: Add project depends on functionality (#3821)
* feat: implemented the code for the depends on functionnality

* chore: Address PR comments

---------

Co-authored-by: Luay-Sol <luay.grira@solace.com>
2023-10-06 10:10:40 -04:00
Simon Heather
64f7d2e1a1 feat: Add Targeted Execution to the Pre/Post Workflow Hooks (#3708)
* Add Workflow hook target filter

* Fix post workflow hook example

* Update WokrflowHook in global_cfg

* Fix linting

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-10-06 09:37:07 -04:00
JSNortal
352bbedfbf fix: issue with GH App credential not writing if lines already exist (#3679)
* Fix issue with GH App credential not writing if lines already exist

* Fix lint issue of unused variable.

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
Co-authored-by: Dylan Page <dylan.page@autodesk.com>
2023-09-25 19:53:06 +00:00
Finn Arne Gangstad
078af70376 fix: safer re-merging with updated upstream (#3499)
* Safer handling of merging with an updated upstream.

We used to call forceClone() to update with upstream, but this deletes the
checked out directory. This is inefficient, can delete existing plan files,
and is very surprising if you are working manually in the working directory.

We now fetch an updated upstream, and re-do the merge operation. This
leaves any working files intact.

* Rename SafeToReClone -> CheckForUpstreamChanges

It's never safe to clone again. But sometimes we need to check
for upstream changes to avoid reverting changes.

The flag is now used to know when we need to merge
again non-destructively with new changes.

* Update fixtures.go

* Add test to make sure plans are not wiped out

As long as the branch itself has not been updated, plans
should be kept. Even if upstream has changed.

* renamed HasDiverged to MergedAgain in PlanResult and from Clone()

This flag was only set to true in case a call to Clone()
ended up merging with an updated upstream, so the
new name better represents what it means.

* Test that Clone on branch update wipes old plans

This complements the test that Clone with unmodified
branch but modified upstream does _not_ wipe plans.

* runGit now runs git instead of returning a function that runs git

* Updated template to merged again instead of diverged

This is no longer a warning, but expected behavior in merge chekout mode

* Rename git wrapper to wrappedGit, add a type for static config

Every call to wrappedGit for the same PR uses identical setup
for directory, head repo and PR, so passing the

---------

Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-09-25 15:17:27 -04:00
Ghais Zaher
80ecc38273 feat: disable autoplan label (#3649)
* feat: disable autoplan label

* documentation

* revert unrelated change

* fix property

* gitlab and github

* dd more test

* small fixes

* add tests for github and gitlab clients

* fix: remove unrelated comments

* fmt

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-09-25 13:43:35 -04:00
Luke Massa
fad6f0f956 fix: Do not unnecessarily update apply check if it doesn't exist yet (#3747)
* Do not unnecessarily create apply pipeline if it doesn't exist yet

* Updates

* Fix remaining

* Fix test logic

* Cleanup more tests

* Fix test

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-09-25 12:01:16 -04:00
Simon Heather
b459645d03 fix: Running 'atlantis unlock' on a PR Causes The Whole Working Directory to be Deleted (#3751)
* Running 'atlantis unlock' on a PR Causes The Whole Working Directory to be Deleted

* Update events controller tests

* Fix events controller tests

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-09-11 11:00:12 -04:00
Simon Heather
cd7ae114eb feat: add ability to track git untracked files (#3724) 2023-09-11 10:57:50 -04:00
Luke Massa
70c9f17007 Revert "fix(deps): update module github.com/google/go-github/v54 to v55 in go.mod (#3743)" (#3748)
This reverts commit 3a2a244272.
2023-09-06 21:15:56 -07:00
renovate[bot]
3a2a244272 fix(deps): update module github.com/google/go-github/v54 to v55 in go.mod (#3743)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-06 21:12:07 +00:00
Luke Massa
6142b460bf fix: Change message for when request is not approved to be more accurate (#3744)
* Change message for when request is not approved

* Updates

* Fix

* Fix tests
2023-09-06 14:04:55 -07:00
Simon Heather
dc644937cf feat: Add A Server Config Flag to Enable Failure on Pre Workflow Hook Errors (#3729)
* FailOnPreWorkflowHookError

* Fix linting issues
2023-09-01 10:17:10 -07:00
MB
bcd917ffba fix(gitlab): Prevent considering non-head pipelines skipped by default (#3695)
By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: https://github.com/runatlantis/atlantis/pull/3428
* Tests Patch MR : https://github.com/runatlantis/atlantis/pull/3653
2023-08-23 17:07:38 -04:00
smstone
b8bb6df40a feat: Slack notifications matched on base branch name (#3644)
* Add ability to send slack notification matched on base branch name

* Update BranchRegex usage doc

* Add test with invalid branch and workspace regex
2023-08-22 15:13:00 +00:00
Finn Arne Gangstad
760190629e fix: complete the upgrade to github v54 to unbreak tests (#3691) 2023-08-21 11:38:17 -04:00
renovate[bot]
55e24fbbf5 fix(deps): update module github.com/google/go-github/v53 to v54 in go.mod (#3676)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 00:41:13 +00:00
Artur Rodrigues
049c146b2c fix(github): prevent null pointer dereferencing when using AllowMergeableBypassApply with no required checks on branch protection (#3672)
* Implement test for allow mergeable bypass apply with no branch protection checks

* Report true combined status if no branch protection required status checks

* Remove warning on feature flag utilization
2023-08-15 10:11:37 -07:00
Ghais Zaher
25c6b43a63 fix: gitlab client failing test (#3653)
* fix: gitlab client failing test

* change HeadCommit to `67cb91d3f6198189f433c045154a885784ba6977`

* remove test case for now
2023-08-09 13:31:36 -04:00
Simon Heather
ec77a951b0 chore: Fix Go Static Check Errors (#3637)
* Fix Go Static Checks

* Fix working dir tests
2023-08-05 16:41:54 -04:00
MB
89a028ffd2 fix(gitlab): Prevent nil pointer dereference when HeadPipeline is empty (#3428)
In this particular example `mr.HeadPipeline.SHA` panics on a nil pointer dereference because HeadPipeline is empty.

This seems to be caused by the lack of permission to update the commit status.

```go
runtime.gopanic
        runtime/panic.go:1038
runtime.panicmem
        runtime/panic.go:221
runtime.sigpanic
        runtime/signal_unix.go:735
github.com/runatlantis/atlantis/server/events/vcs.(*GitlabClient).PullIsMergeable
        github.com/runatlantis/atlantis/server/events/vcs/gitlab_client.go:208
github.com/runatlantis/atlantis/server/events/vcs.(*ClientProxy).PullIsMergeable
        github.com/runatlantis/atlantis/server/events/vcs/proxy.go:72
github.com/runatlantis/atlantis/server/events/vcs.(*pullReqStatusFetcher).FetchPullStatus
        github.com/runatlantis/atlantis/server/events/vcs/pull_status_fetcher.go:28
github.com/runatlantis/atlantis/server/events.(*ApplyCommandRunner).Run
        github.com/runatlantis/atlantis/server/events/apply_command_runner.go:105
github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand
        github.com/runatlantis/atlantis/server/events/command_runner.go:252
```

The least invasive solution is to simply use the commit-hash from pull and guess that the pipeline was "skipped" unless the HeadPipeline is there.

The outcome is:

When mr.HeadPipeline is present:
- use the commit hash and status from the HeadPipeline
When mr.HeadPipeline is NOT present:
- use the commit hash from pull request struct
- assume the pipeline was "skipped"

In cases where GitLab is configured to require a pipeline to pass, this results on a message saying the MR is not mergeable.

More info:
- https://github.com/runatlantis/atlantis/issues/1852
2023-08-04 13:00:47 -04:00
chroju
fbb12fe3b9 feat: set atlantis/apply check to successful if all plans are No Changes (#3378)
* mod: rename updateCommitStatus func

* feat: add PlannedNoChangesPlanStatus

* Add skipApplyNoChanges option to PlanCommandRunner

* Add skipApplyNoChanges option to ApplyCommandRunner

* Add --skip-apply-no-changes flag

* Fix typo

Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>

* Rename --skip-apply-no-changes flag

* Refactor updateCommitStatus functions

* chore(docs): add detailed use case for the flag

* test: add plan_command_runner set apply status

* feat: set apply status to successful by default when result is 'No Changes'

---------

Co-authored-by: chroju <chroju@users.noreply.github.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
2023-08-03 11:15:13 -04:00
Torben Tretau
62271955de fix(github): Mergeable requirement for fork PRs (#3620)
While using a PR from a fork and the "Github allow mergeable bypass apply" flag, the mergeable checks were run with the wrong owner in the request, leading to 404. By choosing the owner from the head repo data it should work both, for fork PRs and in-repo PRs.

Co-authored-by: Dylan Page <dylan.page@autodesk.com>
2023-08-01 02:25:31 +00:00
Simon Heather
b024cef470 chore: Update server/events/working_dir Logging Configuration (#3636)
* Update server/events/working_dir logging

* Add e2e FileWorkspace logger

* Fix github app working dir test logger

* Update working_dir_test

---------

Co-authored-by: Dylan Page <dylan.page@autodesk.com>
2023-07-31 22:10:03 -04:00
Shouichi Kamiya
2bd778b01e fix: auto plan when .terraform.lock.hcl changed (#3473)
Problem

When `projects` are specified and `when_modified` is not specified via
the config file, changing `.terraform.lock.hcl` file won't trigger auto
plan. This is because the default `raw.WhenModified` does not include
`.terraform.lock.hcl`.

Note that when projects are auto detected, changing
`.terraform.lock.hcl` triggers auto plan. This is because the
`cmd.DefaultAutoplanFileList` includes `.terraform.lock.hcl`.

Solution

Include `.terraform.lock.hcl` to the default `raw.WhenModified`.
2023-07-31 11:29:33 -04:00
Luke Massa
cbb86c248e feat: Allow for negations in repo allowlist (#3414)
* feat: Omit repos from allowlist

* Add quote in comment

* Better comment

* Remove test
2023-07-31 13:46:11 +00:00
William Richard
3ca5d82ebf fix: Include information about imports in PlanSuccessStats (#3621)
* Include information about imports in PlanSuccessStats

Terraform 1.5 introduced a feature to import existing resources into
state via code.

https://developer.hashicorp.com/terraform/language/import

When you run `terraform plan` with imports, the output includes information
about the imported resources, which breaks the current regex for parsing
plan changes.

This PR updates the regex to include the, optional, import information.

* Use the ?

Co-authored-by: Benjamin Ullian <5695343+bnu0@users.noreply.github.com>

---------

Co-authored-by: Will Richard <wrichard@seatgeek.com>
Co-authored-by: Benjamin Ullian <5695343+bnu0@users.noreply.github.com>
Co-authored-by: Dylan Page <dylan.page@autodesk.com>
2023-07-30 20:04:29 +00:00
Ross Strickland
1c232b5f90 fix: broken automerge logic (#3591)
* fix automerge logic.

* address failing autoplan test with automerge
2023-07-10 13:23:16 -04:00
Almenon
78632beb20 fix(bitbucket): avoid extra plans using a local LRU (#3402) 2023-07-07 18:35:22 -04:00
Simon Heather
b8994190be feat: Add Support for Customising the Shell for Pre and Post Workflow Hooks (#3451) 2023-07-07 18:34:01 -04:00
Ross Strickland
76c482b83a feat: global repo params (#3379) 2023-07-07 18:33:21 -04:00
Simon Heather
847cab74c4 feat: Add Command Name Environment Variable to Pre/Post Workflow Executions (#3571)
* Add Workflow Command Name env var

* Update tests

* Update command runner

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-07-07 16:21:32 -04:00
Simon Heather
91593b647b fix: Discarding a Plan Causes the Whole Working Directory to be Deleted (#3553) 2023-07-07 11:12:06 -04:00
Andre Ziviani
b6466bdfd2 fix: Tests broken by #3503 (#3583) 2023-07-06 22:22:47 +00:00
Andre Ziviani
974eed3803 feat: Disable policy check on some repositories (#3503)
* feat: Allow enabling policy check per repository

* chore: Tests

* chore: Docs

* chore: Improve tests

* chore: E2E tests
2023-07-06 16:39:36 -04:00
Simon Heather
fce28ebceb fix: Atlantis Triggers AutoPlans on Non-Code Change GitLab Merge Event Webhooks (#3567)
* Gitlab merge event fix

* Update events controller tests

* Update eventrsController formatting

* Update events controller test formatting

* Revert gitlab_request_parser_validator

* Update event_parser

* Update tests

* Add new testdata

* Add testdata EOF LF

* Update gitlab-merge-request-event-update-reviewer.json

* Update gitlab-merge-request-event-update-milestone.json
2023-07-06 12:57:32 -07:00
Simon Heather
0d1f87810d fix: Gitlab Autoplan wont trigger when switching Draft to Ready (#3568)
* Fix: Gitlab Autoplan wont trigger when switching Draft to Ready

* Update gitlab-merge-request-event-mark-as-ready.json

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
2023-07-05 12:56:21 -07:00
Yunchi Luo
a6161c9926 feat: Add an output option to filter output for custom run steps (#3518)
* feat: Add an `output` option to filter output for custom run steps
2023-06-30 10:00:31 -04:00
Ken Kaizu
3954955e13 fix(deps): update module github.com/petergtz/pegomock/v3 to v4 (#3534)
* fix(deps): update module github.com/petergtz/pegomock/v3 to v4 in go.mod

* remove pegomock generate m option, which is not support after v4

* make regen-mocks

* replace pegomock v4 primitive eq/matchers

* convert pegomock v4 Eq/Any matchers

* remove custom models.Repo matcher

* pegomock v4 cannot use result method args

ref https://github.com/petergtz/pegomock/issues/123

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-06-20 15:05:23 -04:00
Ross Strickland
7545296741 fix: parse custom run step output in policy_check (#3502)
* parse custom run output in policy_check

* error if no conftest output

* e2e test

* Adding other policy template.

* update markdown renderer test
2023-06-20 14:55:37 -04:00