feat: auto-detect the value of the no-squash option

The auto-no-squash option is added to:

* backport all the commits when the pull/merge request has been merged
* backport the squashed commit otherwise

It is equivalent to dynamically adjust the value of the no-squash
option, depending on the context.

The no-squash option is kept for backward compatibility for a single
use case: backporting the merged commit instead of backporting the
commits of the pull/merge request request.

Detecting if a pull/merge request was squashed or not depends on the
underlying forge:

* Forgejo / GitHub: use the API to count the number of parents
* GitLab: if the squash_commit_sha is set, the merge request was
  squashed

If the pull/merge request is open, always backport all the commits it
contains.

Fixes: https://github.com/kiegroup/git-backporting/issues/113

Co-authored-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
This commit is contained in:
Earl Warren 2024-04-05 19:22:09 +02:00
parent fc5dba6703
commit f591021c06
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
23 changed files with 324 additions and 54 deletions

View file

@ -51,6 +51,7 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
@ -123,6 +124,7 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
@ -195,7 +197,8 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
bpBranchName: "custom-branch"
bpBranchName: "custom-branch",
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);
@ -268,7 +271,8 @@ describe("gitlab merge request config parser", () => {
labels: [],
inheritLabels: false,
comments: [],
bpBranchName: "custom1, custom2, custom3"
bpBranchName: "custom1, custom2, custom3",
squash: true,
};
const configs: Configs = await configParser.parseAndValidate(args);