mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-27 21:23:48 +00:00
feat(issue-77): handle multiple target branches (#78)
fix: https://github.com/kiegroup/git-backporting/issues/77 This enhancement allow users to backport the same change to multiple branches with one single tool invocation
This commit is contained in:
parent
c19a56a9ad
commit
5fc72e127b
25 changed files with 1774 additions and 234 deletions
|
@ -1,8 +1,12 @@
|
|||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||
import { Moctokit } from "@kie/mock-github";
|
||||
import { targetOwner, repo, mergedPullRequestFixture, openPullRequestFixture, notMergedPullRequestFixture, notFoundPullRequestNumber, multipleCommitsPullRequestFixture, multipleCommitsPullRequestCommits } from "./github-data";
|
||||
import { TARGET_OWNER, REPO, MERGED_PR_FIXTURE, OPEN_PR_FIXTURE, NOT_MERGED_PR_FIXTURE, NOT_FOUND_PR_NUMBER, MULT_COMMITS_PR_FIXTURE, MULT_COMMITS_PR_COMMITS, NEW_PR_URL, NEW_PR_NUMBER } from "./github-data";
|
||||
import { CLOSED_NOT_MERGED_MR, MERGED_SQUASHED_MR, OPEN_MR, OPEN_PR_COMMITS, PROJECT_EXAMPLE, SUPERUSER} from "./gitlab-data";
|
||||
|
||||
// high number, for each test we are not expecting
|
||||
// to send more than 3 reqs per api endpoint
|
||||
const REPEAT = 20;
|
||||
|
||||
const logger = LoggerServiceFactory.getLogger();
|
||||
|
||||
// AXIOS
|
||||
|
@ -94,76 +98,82 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
|
|||
// valid requests
|
||||
mock.rest.pulls
|
||||
.get({
|
||||
owner: targetOwner,
|
||||
repo: repo,
|
||||
pull_number: mergedPullRequestFixture.number
|
||||
owner: TARGET_OWNER,
|
||||
repo: REPO,
|
||||
pull_number: MERGED_PR_FIXTURE.number
|
||||
})
|
||||
.reply({
|
||||
status: 200,
|
||||
data: mergedPullRequestFixture
|
||||
data: MERGED_PR_FIXTURE
|
||||
});
|
||||
|
||||
mock.rest.pulls
|
||||
.get({
|
||||
owner: targetOwner,
|
||||
repo: repo,
|
||||
pull_number: multipleCommitsPullRequestFixture.number
|
||||
owner: TARGET_OWNER,
|
||||
repo: REPO,
|
||||
pull_number: MULT_COMMITS_PR_FIXTURE.number
|
||||
})
|
||||
.reply({
|
||||
status: 200,
|
||||
data: multipleCommitsPullRequestFixture
|
||||
data: MULT_COMMITS_PR_FIXTURE
|
||||
});
|
||||
|
||||
mock.rest.pulls
|
||||
.get({
|
||||
owner: targetOwner,
|
||||
repo: repo,
|
||||
pull_number: openPullRequestFixture.number
|
||||
owner: TARGET_OWNER,
|
||||
repo: REPO,
|
||||
pull_number: OPEN_PR_FIXTURE.number
|
||||
})
|
||||
.reply({
|
||||
status: 200,
|
||||
data: openPullRequestFixture
|
||||
data: OPEN_PR_FIXTURE
|
||||
});
|
||||
|
||||
mock.rest.pulls
|
||||
.get({
|
||||
owner: targetOwner,
|
||||
repo: repo,
|
||||
pull_number: notMergedPullRequestFixture.number
|
||||
owner: TARGET_OWNER,
|
||||
repo: REPO,
|
||||
pull_number: NOT_MERGED_PR_FIXTURE.number
|
||||
})
|
||||
.reply({
|
||||
status: 200,
|
||||
data: notMergedPullRequestFixture
|
||||
data: NOT_MERGED_PR_FIXTURE
|
||||
});
|
||||
|
||||
mock.rest.pulls
|
||||
.listCommits({
|
||||
owner: targetOwner,
|
||||
repo: repo,
|
||||
pull_number: multipleCommitsPullRequestFixture.number
|
||||
owner: TARGET_OWNER,
|
||||
repo: REPO,
|
||||
pull_number: MULT_COMMITS_PR_FIXTURE.number
|
||||
})
|
||||
.reply({
|
||||
status: 200,
|
||||
data: multipleCommitsPullRequestCommits
|
||||
data: MULT_COMMITS_PR_COMMITS
|
||||
});
|
||||
|
||||
mock.rest.pulls
|
||||
.create()
|
||||
.reply({
|
||||
repeat: REPEAT,
|
||||
status: 201,
|
||||
data: mergedPullRequestFixture
|
||||
data: {
|
||||
number: NEW_PR_NUMBER,
|
||||
html_url: NEW_PR_URL,
|
||||
}
|
||||
});
|
||||
|
||||
mock.rest.pulls
|
||||
.requestReviewers()
|
||||
.reply({
|
||||
repeat: REPEAT,
|
||||
status: 201,
|
||||
data: mergedPullRequestFixture
|
||||
data: MERGED_PR_FIXTURE
|
||||
});
|
||||
|
||||
mock.rest.issues
|
||||
.addAssignees()
|
||||
.reply({
|
||||
repeat: REPEAT,
|
||||
status: 201,
|
||||
data: {}
|
||||
});
|
||||
|
@ -171,6 +181,7 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
|
|||
mock.rest.issues
|
||||
.addLabels()
|
||||
.reply({
|
||||
repeat: REPEAT,
|
||||
status: 200,
|
||||
data: {}
|
||||
});
|
||||
|
@ -178,6 +189,7 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
|
|||
mock.rest.issues
|
||||
.createComment()
|
||||
.reply({
|
||||
repeat: REPEAT,
|
||||
status: 201,
|
||||
data: {}
|
||||
});
|
||||
|
@ -185,16 +197,17 @@ export const mockGitHubClient = (apiUrl = "https://api.github.com"): Moctokit =>
|
|||
// invalid requests
|
||||
mock.rest.pulls
|
||||
.get({
|
||||
owner: targetOwner,
|
||||
repo: repo,
|
||||
pull_number: notFoundPullRequestNumber
|
||||
owner: TARGET_OWNER,
|
||||
repo: REPO,
|
||||
pull_number: NOT_FOUND_PR_NUMBER
|
||||
})
|
||||
.reply({
|
||||
repeat: REPEAT,
|
||||
status: 404,
|
||||
data: {
|
||||
message: "Not found"
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return mock;
|
||||
};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
export const targetOwner = "owner";
|
||||
export const sourceOwner = "fork";
|
||||
export const repo = "reponame";
|
||||
export const notFoundPullRequestNumber = 1;
|
||||
export const TARGET_OWNER = "owner";
|
||||
export const SOURCE_OWNER = "fork";
|
||||
export const REPO = "reponame";
|
||||
export const NOT_FOUND_PR_NUMBER = 1;
|
||||
export const NEW_PR_URL = "new_pr_url";
|
||||
export const NEW_PR_NUMBER = 9999;
|
||||
|
||||
export const mergedPullRequestFixture = {
|
||||
export const MERGED_PR_FIXTURE = {
|
||||
"url": "https://api.github.com/repos/owner/reponame/pulls/2368",
|
||||
"id": 1137188271,
|
||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||
|
@ -474,7 +476,7 @@ export const mergedPullRequestFixture = {
|
|||
"changed_files": 2
|
||||
};
|
||||
|
||||
export const openPullRequestFixture = {
|
||||
export const OPEN_PR_FIXTURE = {
|
||||
"url": "https://api.github.com/repos/owner/reponame/pulls/4444",
|
||||
"id": 1137188271,
|
||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||
|
@ -898,7 +900,7 @@ export const openPullRequestFixture = {
|
|||
"changed_files": 2
|
||||
};
|
||||
|
||||
export const notMergedPullRequestFixture = {
|
||||
export const NOT_MERGED_PR_FIXTURE = {
|
||||
"url": "https://api.github.com/repos/owner/reponame/pulls/6666",
|
||||
"id": 1137188271,
|
||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||
|
@ -1341,7 +1343,7 @@ export const notMergedPullRequestFixture = {
|
|||
"changed_files": 2
|
||||
};
|
||||
|
||||
export const multipleCommitsPullRequestFixture = {
|
||||
export const MULT_COMMITS_PR_FIXTURE = {
|
||||
"url": "https://api.github.com/repos/owner/reponame/pulls/8632",
|
||||
"id": 1137188271,
|
||||
"node_id": "PR_kwDOABTq6s5DyB2v",
|
||||
|
@ -1804,7 +1806,7 @@ export const multipleCommitsPullRequestFixture = {
|
|||
"changed_files": 2
|
||||
};
|
||||
|
||||
export const multipleCommitsPullRequestCommits = [
|
||||
export const MULT_COMMITS_PR_COMMITS = [
|
||||
{
|
||||
"sha": "0404fb922ab75c3a8aecad5c97d9af388df04695",
|
||||
"node_id": "C_kwDOImgs99oAKDA0MDRmYjkyMmFiNzVjM2E4YWVjYWQ1Yzk3ZDlhZjM4OGRmMDQ2OTU",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue