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

Atlantis API fails to execute for GitHub projects #5143

Open
lukaspj opened this issue Dec 5, 2024 · 2 comments · May be fixed by #5146
Open

Atlantis API fails to execute for GitHub projects #5143

lukaspj opened this issue Dec 5, 2024 · 2 comments · May be fixed by #5146
Labels
bug Something isn't working provider/github

Comments

@lukaspj
Copy link

lukaspj commented Dec 5, 2024

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

When using Atlantis API we saw symptoms similar to this previous issue: #4194

We also have a pre-plan workflow but we are running v0.31.0 and we can confirm that our pre-plan workflow is run. So we investigated the logs and found errors like this:

422 Validation Failed [{Resource:Status Field:sha Code:custom Message:sha must be a 40 character SHA1}]

Similar to the error messages reported by #4194 and we found that this must be because the API Controller constructs a Command context where it uses the ref for most things:
https://github.com/runatlantis/atlantis/blob/main/server/controllers/api_controller.go#L242

But you can't actually pass the ref when running UpdateStatus,
you have to pass a SHA, so setting HeadCommit: request.Ref does not work, at least not for GitHub Commit Statuses.

Reproduction Steps

We are unsure which reproduction steps is really necessary to reproduce, to us it seem like this error happens when using the API for any GitHub projects.

Logs

Logs
{"level":"error","ts":"2024-12-05T22:03:28.020Z","caller":"vcs/instrumented_client.go:220","msg":"Unable to update status at url: https://atlantis.novus.internal.lego/jobs/9899e0ac-d3df-4e2d-8be7-867a00b36025, error: POST https://api.github.com/repos/LEGO/novus-customers-prod/statuses/main: 422 Validation Failed [{Resource:Status Field:sha Code:custom Message:sha must be a 40 character SHA1}]","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/events/vcs.(*InstrumentedClient).UpdateStatus\n\tgithub.com/runatlantis/atlantis/server/events/vcs/instrumented_client.go:220\ngithub.com/runatlantis/atlantis/server/events/vcs.(*ClientProxy).UpdateStatus\n\tgithub.com/runatlantis/atlantis/server/events/vcs/proxy.go:89\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommitStatusUpdater).updateWorkflowHook\n\tgithub.com/runatlantis/atlantis/server/events/commit_status_updater.go:136\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommitStatusUpdater).UpdatePreWorkflowHook\n\tgithub.com/runatlantis/atlantis/server/events/commit_status_updater.go:112\ngithub.com/runatlantis/atlantis/server/events.(*DefaultPreWorkflowHooksCommandRunner).runHooks\n\tgithub.com/runatlantis/atlantis/server/events/pre_workflow_hooks_command_runner.go:146\ngithub.com/runatlantis/atlantis/server/events.(*DefaultPreWorkflowHooksCommandRunner).RunPreHooks\n\tgithub.com/runatlantis/atlantis/server/events/pre_workflow_hooks_command_runner.go:84\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).apiPlan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:155\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).Plan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:93\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"}

Environment details

  • Atlantis version: v0.31.0
  • Deployment method: ecs

Additional Context

@lukaspj lukaspj added the bug Something isn't working label Dec 5, 2024
Copy link

dosubot bot commented Dec 5, 2024

Hey there, @lukaspj! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's squash those bugs together!

The issue you're encountering with the Atlantis API failing due to a 422 Validation Error is because the UpdateStatus method requires a 40-character SHA1 hash, but the api_controller.go file constructs the command context using a reference (request.Ref) instead of a SHA1 hash. This discrepancy leads to the validation error when the API attempts to update the commit status on GitHub [1].

To resolve this, ensure that the request.Ref used in the api_controller.go is a valid SHA1 hash when calling the UpdateStatus method. The UpdateStatus method in github_client.go specifically requires a SHA1 hash for the pull.HeadCommit parameter, which is used to identify the commit whose status is being updated [2].

You may need to modify the way the Ref is set or ensure that the correct SHA1 hash is passed to the UpdateStatus method to avoid this validation error.

To continue talking to Dosu, mention @dosu.

@lukaspj
Copy link
Author

lukaspj commented Dec 7, 2024

I have been considering solutions for this.

Either we implement logic for looking up the SHA for the submitted REF or we change the API to ask for both a SHA and a REF.

I prefer being explicit about the SHA when doing the request, what do you think about that?

@lukaspj lukaspj linked a pull request Dec 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working provider/github
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant