mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-02-23 11:05:44 -05:00
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>
41 lines
No EOL
1.4 KiB
TypeScript
41 lines
No EOL
1.4 KiB
TypeScript
import GitClientFactory from "@bp/service/git/git-client-factory";
|
|
import { GitPullRequest, GitClientType } from "@bp/service/git/git.types";
|
|
import GitHubClient from "@bp/service/git/github/github-client";
|
|
import { MERGED_PR_FIXTURE, REPO, TARGET_OWNER } from "../../../support/mock/github-data";
|
|
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
|
|
|
describe("github service", () => {
|
|
|
|
let gitClient: GitHubClient;
|
|
|
|
beforeAll(() => {
|
|
// init git service
|
|
GitClientFactory.reset();
|
|
GitClientFactory.getOrCreate(GitClientType.GITHUB, "whatever", "http://localhost/api/v3");
|
|
});
|
|
|
|
beforeEach(() => {
|
|
// mock github api calls
|
|
mockGitHubClient("http://localhost/api/v3");
|
|
|
|
gitClient = GitClientFactory.getClient() as GitHubClient;
|
|
});
|
|
|
|
test("get pull request: success", async () => {
|
|
const res: GitPullRequest = await gitClient.getPullRequest(TARGET_OWNER, REPO, MERGED_PR_FIXTURE.number, true);
|
|
expect(res.sourceRepo).toEqual({
|
|
owner: "fork",
|
|
project: "reponame",
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
});
|
|
expect(res.targetRepo).toEqual({
|
|
owner: "owner",
|
|
project: "reponame",
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
});
|
|
expect(res.title).toBe("PR Title");
|
|
expect(res.commits!.length).toBe(1);
|
|
expect(res.commits).toEqual(["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]);
|
|
});
|
|
|
|
}); |