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

The server side repos is not matching by branch regex and only repo ID #5281

Open
flassagn opened this issue Jan 28, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@flassagn
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

I would like to have distinct repo match on branch match and not only repoID which it seems allowed by the documentation https://www.runatlantis.io/docs/server-side-repo-config.html#reference.

Reproduction Steps

Configure the server side configuration with the following content

repos:
- id: /.*/
  branch: /.*/
  plan_requirements: [approved, mergeable]
  apply_requirements: [approved, mergeable]
  import_requirements: [approved, mergeable]
- id: github.com/owner/repo
  branch: /main/
  plan_requirements: []
  apply_requirements: []
  import_requirements: []

And request an apply from main branch, I used the api enpoint myself

❯ curl --request POST 'https://<atlantis_url>/api/apply' \
      --header 'X-Atlantis-Token: <atlantis_token>' \
      --header 'Content-Type: application/json' \
      --data-raw '{
      "Repository": "github.com/owner/repo",
      "Ref": "main",
      "Type": "Github",
  }' 2>/dev/null | jq
{
  "Error": null,
  "Failure": "",
  "ProjectResults": [
    {
      "Command": 0,
      "SubCommand": "",
      "RepoRelDir": "github.com/owner/repo",
      "Workspace": "default",
      "Error": null,
      "Failure": "Pull request must be approved according to the project's approval rules before running apply.",
      "PlanSuccess": null,
      "PolicyCheckResults": null,
      "ApplySuccess": "",
      "VersionSuccess": "",
      "ImportSuccess": null,
      "StateRmSuccess": null,
      "ProjectName": "ultra-organization",
      "SilencePRComments": null
    }
  ],
  "PlansDeleted": false
}

As you can see, I'm not able to apply it because the merge doesn't take the branch in account

Logs

{"level":"info","ts":"2025-01-28T12:47:44.125Z","caller":"models/shell_command_runner.go:181","msg":"successfully ran 'sh -c' '/atlantis-data/bin/terraform1.9.2 init -input=false -upgrade -reconfigure' in '/atlantis-data/repos/ultraio/devops/terraform/0/default/gitlab/ultra-organization'","json":{"duration":11.795900726}}
{"level":"info","ts":"2025-01-28T12:47:44.516Z","caller":"terraform/terraform_client.go:383","msg":"Successfully ran '/atlantis-data/bin/terraform1.9.2 workspace show' in '/atlantis-data/repos/ultraio/devops/terraform/0/default/gitlab/ultra-organization'","json":{"duration":0.390805303}}
{"level":"info","ts":"2025-01-28T12:48:06.466Z","caller":"models/shell_command_runner.go:181","msg":"successfully ran 'sh -c' '/atlantis-data/bin/terraform1.9.2 plan -input=false -refresh -out \"/atlantis-data/repos/ultraio/devops/terraform/0/default/gitlab/ultra-organization/ultra-organization-default.tfplan\" -var vault_dev_token=${DEV_VAULT_TOKEN} -var vault_staging_token=${STAGING_VAULT_TOKEN} -var vault_prod_token=${PROD_VAULT_TOKEN}' in '/atlantis-data/repos/ultraio/devops/terraform/0/default/gitlab/ultra-organization'","json":{"duration":21.948748395}}
{"level":"error","ts":"2025-01-28T12:48:08.586Z","caller":"events/instrumented_project_command_runner.go:84","msg":"Failure running apply operation: Pull request must be approved according to the project's approval rules before running apply.","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/events.RunAndEmitStats\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:84\ngithub.com/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandRunner).Apply\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:46\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).apiApply\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:185\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).Apply\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:130\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2220\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/[email protected]/mux.go:212\ngithub.com/urfave/negroni/v3.(*Negroni).UseHandler.Wrap.func1\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:59\ngithub.com/urfave/negroni/v3.HandlerFunc.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:33\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:51\ngithub.com/runatlantis/atlantis/server.(*RequestLogger).ServeHTTP\n\tgithub.com/runatlantis/atlantis/server/middleware.go:70\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:51\ngithub.com/urfave/negroni/v3.(*Recovery).ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/recovery.go:210\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:51\ngithub.com/urfave/negroni/v3.(*Negroni).ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:111\nnet/http.serverHandler.ServeHTTP\n\tnet/http/server.go:3210\nnet/http.(*conn).serve\n\tnet/http/server.go:2092"}
{"level":"warn","ts":"2025-01-28T12:48:08.587Z","caller":"controllers/api_controller.go:253","msg":"{\"Error\":null,\"Failure\":\"\",\"ProjectResults\":[{\"Command\":0,\"SubCommand\":\"\",\"RepoRelDir\":\"gitlab/ultra-organization\",\"Workspace\":\"default\",\"Error\":null,\"Failure\":\"Pull request must be approved according to the project's approval rules before running apply.\",\"PlanSuccess\":null,\"PolicyCheckResults\":null,\"ApplySuccess\":\"\",\"VersionSuccess\":\"\",\"ImportSuccess\":null,\"StateRmSuccess\":null,\"ProjectName\":\"ultra-organization\",\"SilencePRComments\":null}],\"PlansDeleted\":false}","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/controllers.(*APIController).respond\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:253\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).Apply\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:144\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2220\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/[email protected]/mux.go:212\ngithub.com/urfave/negroni/v3.(*Negroni).UseHandler.Wrap.func1\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:59\ngithub.com/urfave/negroni/v3.HandlerFunc.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:33\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:51\ngithub.com/runatlantis/atlantis/server.(*RequestLogger).ServeHTTP\n\tgithub.com/runatlantis/atlantis/server/middleware.go:70\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:51\ngithub.com/urfave/negroni/v3.(*Recovery).ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/recovery.go:210\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:51\ngithub.com/urfave/negroni/v3.(*Negroni).ServeHTTP\n\tgithub.com/urfave/negroni/[email protected]/negroni.go:111\nnet/http.serverHandler.ServeHTTP\n\tnet/http/server.go:3210\nnet/http.(*conn).serve\n\tnet/http/server.go:2092"}

Additional Context

@flassagn flassagn added the bug Something isn't working label Jan 28, 2025
Copy link

dosubot bot commented Jan 28, 2025

@flassagn Hello! I'm here to help you with any issues or questions you have. Let's work together to find a solution.

I found a similar open issue regarding branch regex not working as expected in Atlantis. The suggested solution in that thread is to ensure that the branch is specified correctly in the configuration, like so:

branch: /^pull_request_destination_branch_name$/

You might want to check if your branch regex is correctly defined and matches the branch name exactly as expected [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@flassagn
Copy link
Author

flassagn commented Jan 28, 2025

For the record, I already identify where the codebase need to be updated to the getMatchingCfg private function in order to also support filtering by branch.

Same feature need to be added at MatchingRepo accordingly.

I could do a PR but I would to confirm with you the defect and see if you want to support this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant