Skip to content

Fix head of commit in danger_as_local

Piotr Stankowski requested to merge trakos/gitlab:fix-danger-as-local into master

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:

image

This causes jobs from forks to fail:

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.

Edited by Piotr Stankowski

Merge request reports