Open zyga opened 3 years ago
This seems to be related to https://gitlab.com/gitlab-org/gitlab/-/issues/288876
So, I think there are two separate changes that need to happen.
First, GitLabRetriever.get_commit_range
can switch from CI_COMMIT_BRANCH
to CI_COMMIT_REF_NAME
which is available at all times: https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/ci/variables/predefined_variables.md
Second, inside the same function, when CI_MERGE_REQUEST_ID
is set, we should consider CI_MERGE_REQUEST_EVENT_TYPE
to see if it is 'detached'
. In that mode CI_MERGE_REQUEST_TARGET_BRANCH_NAME
is set but the corresponding CI_MERGE_REQUEST_TARGET_BRANCH_SHA
is empty. The same restriction applies to CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
. Instead of using the precise values, we can use the symbolic names and let git do the hard work, by calling git rev-parse
.
The following GitLab pipeline script is a viable workaround:
- |
if [ "${CI_MERGE_REQUEST_EVENT_TYPE:-}" = detached ]; then
git fetch -a # so that we can resolve branch names below
export CI_COMMIT_BRANCH="$CI_COMMIT_REF_NAME";
export CI_MERGE_REQUEST_SOURCE_BRANCH_SHA="$(git rev-parse "origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME")";
export CI_MERGE_REQUEST_TARGET_BRANCH_SHA="$(git rev-parse "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME")";
fi
- dco-check --default-branch-from-remote --verbose
Interesting. Your proposed fix explanation makes sense.
If you don't mind, could you open a PR? I'm not sure if I can test with an actual detached pipeline since it's a premium feature.
@christophebedard yeah, yesterday it took me a while to distill the problem. The one thing that worries me is the apparent need to git fetch origin
to resolve the branch names. If that's an acceptable (costly) element then I think we can go ahead with a Python version of the small shell snippet I've posted above.
@zyga as long as it's only used/called when needed (for detached pipelines) then I think it's fine.
Our project is using pipelines for merge requests. This feature is documented at https://docs.gitlab.com/ee/ci/merge_request_pipelines/
In the default recommended setup, dco-check 0.0.11 fails as follows:
Some extra debugging shows more information, interestingly
CI_COMMIT_BRANCH
is obviously missing andCI_MERGE_REQUEST_EVENT_TYPE=detached
indicates that this is a detached merge request.I think that in this mode, it's sufficient to use
CI_COMMIT_REF_NAME
instead.