feat: pull request backporting

feat: backport still open pull requests
This commit is contained in:
Andrea Lamparelli 2023-01-05 11:41:14 +01:00
commit b3936e019a
53 changed files with 48467 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,89 @@
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
import { Moctokit } from "@kie/mock-github";
import { targetOwner, repo, mergedPullRequestFixture, openPullRequestFixture, notMergedPullRequestFixture, notFoundPullRequestNumber, sameOwnerPullRequestFixture } from "./moctokit-data";
const logger = LoggerServiceFactory.getLogger();
export const setupMoctokit = (): Moctokit => {
logger.debug("Setting up moctokit.");
const mock = new Moctokit();
// setup the mock requests here
// valid requests
mock.rest.pulls
.get({
owner: targetOwner,
repo: repo,
pull_number: mergedPullRequestFixture.number
})
.reply({
status: 200,
data: mergedPullRequestFixture
});
mock.rest.pulls
.get({
owner: targetOwner,
repo: repo,
pull_number: sameOwnerPullRequestFixture.number
})
.reply({
status: 200,
data: sameOwnerPullRequestFixture
});
mock.rest.pulls
.get({
owner: targetOwner,
repo: repo,
pull_number: openPullRequestFixture.number
})
.reply({
status: 200,
data: openPullRequestFixture
});
mock.rest.pulls
.get({
owner: targetOwner,
repo: repo,
pull_number: notMergedPullRequestFixture.number
})
.reply({
status: 200,
data: notMergedPullRequestFixture
});
mock.rest.pulls
.create()
.reply({
status: 201,
data: mergedPullRequestFixture
});
mock.rest.pulls
.requestReviewers()
.reply({
status: 201,
data: mergedPullRequestFixture
});
// invalid requests
mock.rest.pulls
.get({
owner: targetOwner,
repo: repo,
pull_number: notFoundPullRequestNumber
})
.reply({
status: 404,
data: {
message: "Not found"
}
});
return mock;
};

17
test/support/utils.ts Normal file
View file

@ -0,0 +1,17 @@
import * as core from "@actions/core";
export const addProcessArgs = (args: string[]) => {
process.argv = [...process.argv, ...args];
};
export const resetProcessArgs = () => {
process.argv = ["node", "backporting"];
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const spyGetInput = (obj: any) => {
const mock = jest.spyOn(core, "getInput");
mock.mockImplementation((name: string) : string => {
return obj[name];
});
};