* 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>
We should use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` when matching string to avoid
unnecessary `[]byte` conversions and reduce allocations.
Example benchmark:
func BenchmarkMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := branchRegex.Match([]byte("main")); !match {
b.Fail()
}
}
}
func BenchmarkMatchString(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := branchRegex.MatchString("main"); !match {
b.Fail()
}
}
}
goos: linux
goarch: amd64
pkg: github.com/runatlantis/atlantis/server/core/config
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16 8269699 141.4 ns/op 4 B/op 1 allocs/op
BenchmarkMatchString-16 14298446 95.81 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/runatlantis/atlantis/server/core/config 2.784s
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
* 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>
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.
* Make code more Go-idiomatic
While at it makes it more readable.
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
* Add internal function to parse multienv step input
This new function properly deals with quotes and commas in values.
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
* Add regression test for multienv output with comma in values
See #2765 for an issue report.
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
* Use parseMultienvLine for parsing multienv steps output
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
* Add internal function to parse multienv step input
This new function properly deals with quotes and commas in values.
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
---------
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
* 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.
* 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
* 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>
* 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>
* feat: Add use plugin cache bool flag
* feat: Added use-plugin-cache doc
* feat: refactor to reflect terrafrom in plugin cache flag
Co-authored-by: Simon Heather <32168619+X-Guardian@users.noreply.github.com>
* fix: missing closing in bash block documentation
* fix: typo in flag example
* feat: improve docs
* feat: performance implications documented
* feat: increase terraform minor version to 1.3.10
---------
Co-authored-by: Simon Heather <32168619+X-Guardian@users.noreply.github.com>
* 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>
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
* 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
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
* 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>
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>
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`.
* 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>