Fix head of commit in danger_as_local
What does this MR do and why?
In MR !73189 (diffs) we've added use of CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
variable in danger_as_local
job.
However, this variable is only available in merged results pipelines, and it's empty for detached jobs:
This causes jobs from forks to fail:
- https://gitlab.com/trakos/gitlab/-/jobs/1727649653
- https://gitlab.com/ZJUGuoShuai/gitlab/-/jobs/1723135629
- https://gitlab.com/mehulsharma/gitlab/-/jobs/1726381503
- https://gitlab.com/icbd/gitlab/-/jobs/1725827269
I think the same would happen for draft MRs running danger-review-local
- as far as I understand it, draft MRs don't use merged results pipeline. There was very similar issue mentioned in !66844 (merged), discussed in #336839 (comment 634919898) .
In my fix, I simply propose to fallback to $CI_COMMIT_SHA
value when $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
is empty. Note that it's important that I've used ${VAR1:-$VAR2}
instead of ${VAR1-$VAR2}
. The latter fallbacks to $VAR2
only when $VAR1
is not set, but not when it's set to empty string, so it wouldn't work here (from what I understand, $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
is set to empty string for detached pipelines).
This relates to #330964 .
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.