mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-28 05:33:47 +00:00
feat: auto-detect the value of the no-squash option (#118)
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:
parent
fc5dba6703
commit
6042bcc40b
23 changed files with 324 additions and 54 deletions
|
@ -1,4 +1,4 @@
|
|||
import { inferGitApiUrl, inferGitClient } from "@bp/service/git/git-util";
|
||||
import { inferGitApiUrl, inferGitClient, inferSquash } from "@bp/service/git/git-util";
|
||||
import { GitClientType } from "@bp/service/git/git.types";
|
||||
|
||||
describe("check git utilities", () => {
|
||||
|
@ -54,4 +54,10 @@ describe("check git utilities", () => {
|
|||
test("check infer codeberg client", ()=> {
|
||||
expect(inferGitClient("https://codeberg.org/lampajr/backporting-example/pulls/1")).toStrictEqual(GitClientType.CODEBERG);
|
||||
});
|
||||
});
|
||||
|
||||
test("check inferSquash", ()=> {
|
||||
expect(inferSquash(true, undefined)).toStrictEqual(false);
|
||||
expect(inferSquash(false, "SHA")).toStrictEqual(true);
|
||||
expect(inferSquash(false, undefined)).toStrictEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ describe("github service", () => {
|
|||
});
|
||||
|
||||
test("get pull request: success", async () => {
|
||||
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number);
|
||||
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number, true);
|
||||
expect(res.sourceRepo).toEqual({
|
||||
owner: "fork",
|
||||
project: "reponame",
|
||||
|
|
|
@ -31,7 +31,7 @@ describe("github service", () => {
|
|||
});
|
||||
|
||||
test("get merged pull request", async () => {
|
||||
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 1);
|
||||
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 1, true);
|
||||
|
||||
// check content
|
||||
expect(res.sourceRepo).toEqual({
|
||||
|
@ -56,7 +56,7 @@ describe("github service", () => {
|
|||
});
|
||||
|
||||
test("get open pull request", async () => {
|
||||
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 2);
|
||||
const res: GitPullRequest = await gitClient.getPullRequest("superuser", "backporting-example", 2, true);
|
||||
expect(res.sourceRepo).toEqual({
|
||||
owner: "superuser",
|
||||
project: "backporting-example",
|
||||
|
@ -325,7 +325,7 @@ describe("github service", () => {
|
|||
});
|
||||
|
||||
test("get pull request for nested namespaces", async () => {
|
||||
const res: GitPullRequest = await gitClient.getPullRequestFromUrl("https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example/-/merge_requests/4");
|
||||
const res: GitPullRequest = await gitClient.getPullRequestFromUrl("https://my.gitlab.host.com/mysuperorg/6/mysuperproduct/mysuperunit/backporting-example/-/merge_requests/4", true);
|
||||
|
||||
// check content
|
||||
expect(res.sourceRepo).toEqual({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue