-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(gitlab): Prevent nil pointer dereference when HeadPipeline is empty #3428
Conversation
@@ -198,14 +198,23 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest | |||
return false, err | |||
} | |||
|
|||
// Prevent nil pointer error when mr.HeadPipeline is empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is at
func TestGitlabClient_PullIsMergeable(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just haven't got the time yet. I'm gonna try doing this over the long weekend here and get back to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GenPage finally got the time to work on this, the tests are here, could you review them?
Please fill out the pr template |
cc: @jamengual thoughts on this pr? |
we have been going back and forth about this in the issues and slack and I think we agreed on merging this since gitlab have no ETA on fixing the api. |
This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month. |
Any chance for having this merged and released soon? |
@marceloboeira friendly ping, were you able to write a test for this? |
Anyone can write the test, if anyone is able to do so, that works too. |
I can attempt to write the test next week. |
1bc01d3
to
87cd1ba
Compare
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: - runatlantis#1852
87cd1ba
to
bdcc10c
Compare
Folks, sorry for the delay, finally, the tests are here 🎈 |
Thank you for the contribution, LGTM |
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: runatlantis#3428 * Tests Patch MR : runatlantis#3653
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: runatlantis#3428 * Tests Patch MR : runatlantis#3653
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: runatlantis#3428 * Tests Patch MR : runatlantis#3653
#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: #3428 * Tests Patch MR : #3653
…ty (runatlantis#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: - runatlantis#1852
runatlantis#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: runatlantis#3428 * Tests Patch MR : runatlantis#3653
…ty (runatlantis#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: - runatlantis#1852
runatlantis#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: runatlantis#3428 * Tests Patch MR : runatlantis#3653
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.
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:
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:
what
why
tests
references