[merge_metrics.ml]: fix diff size for merge train MRs
What
We've being seeing errors since the introduction of merge trains on tezos/tezos like this:
https://gitlab.com/nomadic-labs/tezos-sw-metrics/-/jobs/7363570940
Seems like with merged results & merge trains, our old mechanism for calculating the size of MRs no longer work.
Indeed, we would take the two fields for each MR:
- the head:
mr.merge_request_sha
, assuming this to be the tip of the MR - the merge commit:
mr.merge_request_merge_commit_sha
, assuming this to be the merge commit onmaster
for the MR
Then, we would find out which of the merge commit's two parents is
not the head
that we can call base
. Finally, the size of the MR
is the size of the diff between base
and head
.
This seems to work fine before the introduction of merged result pipelines.
With merged result pipelines, the MR's head
is not necessarily a
parent of the merge commit. Consider tezos/tezos!14132 (merged).
Notice that the head does not figure in the parents.
This is since with
- merged results MRs;
- merge trains; and
- marge-bot2,
the MR is no longer rebased just before merging. Hence, the last head of the MR is not a commit that will appear on master unless the MR was rebased on the target branch when merged.
The unknown parent 2f2a1469 that figures above is the HEAD of the MR as rebased on the tip of the target branch just before merging. This happens behind the scenes in this new setting: this rebased version of the branch is not pushed back to the MR.
Anyhow, we can side-step this fragile mechanism for working out which
two commits to diff by using a new set of fields in the gitlab api
under the key .diff_refs
. It seems like .diff_refs.base_sha
and
.diff_refs.head_sha
are exactly the two commits we want to
compare. It seems they are not on master -- whatever, we just fetch
them.