backport
Version:
A CLI tool that automates the process of backporting commits
168 lines • 7.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nock_1 = __importDefault(require("nock"));
const nockHelpers_1 = require("../../../../test/nockHelpers");
const commitsByAuthorMock_1 = require("../mocks/commitsByAuthorMock");
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
const defaultOptions = {
accessToken: 'myAccessToken',
author: 'sorenlouv',
githubApiBaseUrlV4: 'http://localhost/graphql',
maxNumber: 10,
repoName: 'kibana',
repoOwner: 'elastic',
sourceBranch: 'source-branch-from-options',
dateSince: null,
dateUntil: null,
};
const authorIdMockData = { user: { id: 'myUserId' } };
describe('fetchCommitsByAuthor', () => {
beforeEach(() => {
jest.clearAllMocks();
});
afterEach(() => {
nock_1.default.cleanAll();
});
describe('when commit has an associated pull request', () => {
let res;
let authorIdCalls;
let commitsByAuthorCalls;
beforeAll(async () => {
authorIdCalls = (0, nockHelpers_1.mockUrqlRequest)({
operationName: 'AuthorId',
body: { data: authorIdMockData },
});
commitsByAuthorCalls = (0, nockHelpers_1.mockUrqlRequest)({
operationName: 'CommitsByAuthor',
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
});
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
});
it('should return a list of commits with pullNumber and existing backports', () => {
const expectedCommits = [
{
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
suggestedTargetBranches: [],
sourceCommit: {
branchLabelMapping: undefined,
committedDate: '2021-12-24T00:00:00Z',
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
message: 'Add 👻',
},
targetPullRequestStates: [],
sourceBranch: 'source-branch-from-options',
},
{
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
suggestedTargetBranches: [],
sourceCommit: {
branchLabelMapping: undefined,
committedDate: '2021-12-23T00:00:00Z',
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
message: 'Add witch (#85)',
},
sourcePullRequest: {
title: 'Derive Queries Panel',
labels: ['my-label-b'],
number: 85,
url: 'https://github.com/elastic/kibana/pull/85',
mergeCommit: {
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
message: 'Add witch (#85)',
},
},
targetPullRequestStates: [],
sourceBranch: 'master',
},
{
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
suggestedTargetBranches: [],
sourceCommit: {
branchLabelMapping: undefined,
committedDate: '2021-12-22T00:00:00Z',
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
},
sourcePullRequest: {
title: 'Creating own query',
labels: ['v6.3.0'],
number: 80,
url: 'https://github.com/elastic/kibana/pull/80',
mergeCommit: {
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
},
},
targetPullRequestStates: [
{
branch: '6.3',
state: 'MERGED',
number: 99,
url: 'https://github.com/elastic/kibana/pull/99',
mergeCommit: {
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
sha: 'target-merge-commit-sha',
},
},
],
sourceBranch: 'master',
},
{
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
suggestedTargetBranches: [],
sourceCommit: {
branchLabelMapping: undefined,
committedDate: '2021-12-21T00:00:00Z',
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
message: 'Add backport config',
},
targetPullRequestStates: [],
sourceBranch: 'source-branch-from-options',
},
{
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
suggestedTargetBranches: [],
sourceCommit: {
branchLabelMapping: undefined,
committedDate: '2021-12-20T00:00:00Z',
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
message: 'Initial commit',
},
targetPullRequestStates: [],
sourceBranch: 'source-branch-from-options',
},
];
expect(res).toEqual(expectedCommits);
});
it('should call with correct args to fetch author id', () => {
expect(authorIdCalls).toMatchSnapshot();
});
it('should call with correct args to fetch commits', () => {
expect(commitsByAuthorCalls).toMatchSnapshot();
});
});
describe('when a custom github api hostname is supplied', () => {
it('should be used in gql requests', async () => {
const authorIdCalls = (0, nockHelpers_1.mockUrqlRequest)({
operationName: 'AuthorId',
body: { data: authorIdMockData },
apiBaseUrl: 'http://localhost/my-custom-api',
});
const commitsByAuthorCalls = (0, nockHelpers_1.mockUrqlRequest)({
operationName: 'CommitsByAuthor',
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
apiBaseUrl: 'http://localhost/my-custom-api',
});
await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
...defaultOptions,
githubApiBaseUrlV4: 'http://localhost/my-custom-api',
});
expect(authorIdCalls.length).toBe(1);
expect(commitsByAuthorCalls.length).toBe(1);
});
});
});
//# sourceMappingURL=fetchCommitsByAuthor.test.js.map