2020-09-21 20:04:11 +00:00
|
|
|
import { ERROR, WARN } from 'bunyan';
|
2020-01-10 10:35:49 +00:00
|
|
|
import { mock } from 'jest-mock-extended';
|
2020-09-21 20:04:11 +00:00
|
|
|
import {
|
|
|
|
RenovateConfig,
|
|
|
|
getConfig,
|
2021-04-13 10:25:51 +00:00
|
|
|
getName,
|
2021-04-23 16:58:48 +00:00
|
|
|
loadFixture,
|
2020-09-21 20:04:11 +00:00
|
|
|
logger,
|
|
|
|
platform,
|
|
|
|
} from '../../../test/util';
|
2021-02-05 21:21:24 +00:00
|
|
|
import { setAdminConfig } from '../../config/admin';
|
2020-03-05 20:57:24 +00:00
|
|
|
import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms';
|
2020-05-07 08:23:45 +00:00
|
|
|
import { Platform, Pr } from '../../platform';
|
2020-08-18 10:19:19 +00:00
|
|
|
import { PrState } from '../../types';
|
2021-04-15 17:06:55 +00:00
|
|
|
import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../types';
|
2020-07-21 13:13:56 +00:00
|
|
|
import * as dependencyDashboard from './dependency-dashboard';
|
2019-07-17 08:14:56 +00:00
|
|
|
|
2020-03-02 11:06:16 +00:00
|
|
|
type PrUpgrade = BranchUpgradeConfig;
|
|
|
|
|
2020-01-10 10:35:49 +00:00
|
|
|
let config: RenovateConfig;
|
2019-07-04 14:00:00 +00:00
|
|
|
beforeEach(() => {
|
2020-09-21 20:04:11 +00:00
|
|
|
jest.clearAllMocks();
|
2020-01-10 10:35:49 +00:00
|
|
|
config = getConfig();
|
2020-01-17 07:26:42 +00:00
|
|
|
config.platform = PLATFORM_TYPE_GITHUB;
|
2019-07-04 14:00:00 +00:00
|
|
|
config.errors = [];
|
|
|
|
config.warnings = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
async function dryRun(
|
2020-01-10 10:35:49 +00:00
|
|
|
branches: BranchConfig[],
|
2020-09-07 07:54:07 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
2020-05-07 08:23:45 +00:00
|
|
|
platform: jest.Mocked<Platform>,
|
2019-07-04 14:00:00 +00:00
|
|
|
ensureIssueClosingCalls = 0,
|
|
|
|
ensureIssueCalls = 0,
|
|
|
|
getBranchPrCalls = 0,
|
|
|
|
findPrCalls = 0
|
|
|
|
) {
|
2020-09-21 20:04:11 +00:00
|
|
|
jest.clearAllMocks();
|
2021-02-05 21:21:24 +00:00
|
|
|
setAdminConfig({ dryRun: true });
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(
|
|
|
|
ensureIssueClosingCalls
|
|
|
|
);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(ensureIssueCalls);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(getBranchPrCalls);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(findPrCalls);
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:15:03 +00:00
|
|
|
describe(getName(), () => {
|
2019-07-04 14:00:00 +00:00
|
|
|
describe('ensureMasterIssue()', () => {
|
2021-02-05 21:21:24 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
setAdminConfig();
|
|
|
|
});
|
2019-07-04 14:00:00 +00:00
|
|
|
it('do nothing if masterissue is disable', async () => {
|
2020-01-10 10:35:49 +00:00
|
|
|
const branches: BranchConfig[] = [];
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('do nothing if it has no masterissueapproval branches', async () => {
|
|
|
|
const branches = [
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr1',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr2',
|
2020-07-11 09:55:30 +00:00
|
|
|
dependencyDashboardApproval: false,
|
2019-07-04 14:00:00 +00:00
|
|
|
},
|
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
2020-07-11 09:55:30 +00:00
|
|
|
it('closes Dependency Dashboard when there is 0 PR opened and dependencyDashboardAutoclose is true', async () => {
|
2020-01-10 10:35:49 +00:00
|
|
|
const branches: BranchConfig[] = [];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
|
|
|
config.dependencyDashboardAutoclose = true;
|
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(1);
|
|
|
|
expect(platform.ensureIssueClosing.mock.calls[0][0]).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
2020-07-11 09:55:30 +00:00
|
|
|
it('closes Dependency Dashboard when all branches are automerged and dependencyDashboardAutoclose is true', async () => {
|
2020-03-02 11:06:16 +00:00
|
|
|
const branches: BranchConfig[] = [
|
2020-08-31 14:05:38 +00:00
|
|
|
{
|
|
|
|
...mock<BranchConfig>(),
|
|
|
|
prTitle: 'pr1',
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Automerged,
|
2020-08-31 14:05:38 +00:00
|
|
|
},
|
2019-07-04 14:00:00 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr2',
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Automerged,
|
2020-07-11 09:55:30 +00:00
|
|
|
dependencyDashboardApproval: false,
|
2019-07-04 14:00:00 +00:00
|
|
|
},
|
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
|
|
|
config.dependencyDashboardAutoclose = true;
|
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(1);
|
|
|
|
expect(platform.ensureIssueClosing.mock.calls[0][0]).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
2020-07-11 09:55:30 +00:00
|
|
|
it('open or update Dependency Dashboard when all branches are closed and dependencyDashboardAutoclose is false', async () => {
|
2020-01-10 10:35:49 +00:00
|
|
|
const branches: BranchConfig[] = [];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
2020-08-24 12:35:22 +00:00
|
|
|
config.dependencyDashboardFooter = 'And this is a footer';
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
2021-02-24 08:34:25 +00:00
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
|
|
|
config.dependencyDashboardTitle
|
|
|
|
);
|
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('open or update Dependency Dashboard when rules contain approvals', async () => {
|
|
|
|
const branches: BranchConfig[] = [];
|
|
|
|
config.packageRules = [
|
|
|
|
{
|
|
|
|
dependencyDashboardApproval: true,
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
];
|
|
|
|
config.dependencyDashboardFooter = 'And this is a footer';
|
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
2020-08-24 12:35:22 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checks an issue with 2 Pending Approvals, 2 not scheduled, 2 pr-hourly-limit-reached and 2 in error', async () => {
|
2020-03-02 11:06:16 +00:00
|
|
|
const branches: BranchConfig[] = [
|
2019-07-04 14:00:00 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr1',
|
2020-03-02 11:06:16 +00:00
|
|
|
upgrades: [{ ...mock<BranchUpgradeConfig>(), depName: 'dep1' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NeedsApproval,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName1',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr2',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep2' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NeedsApproval,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName2',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr3',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep3' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NotScheduled,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName3',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr4',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep4' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NotScheduled,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName4',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr5',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep5' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.PrLimitReached,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName5',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr6',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep6' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.PrLimitReached,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName6',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr7',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep7' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Error,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName7',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr8',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep8' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Error,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName8',
|
|
|
|
},
|
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toBe(
|
2021-04-26 14:15:03 +00:00
|
|
|
loadFixture('master-issue_with_8_PR.txt')
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checks an issue with 2 PR pr-edited', async () => {
|
2020-03-02 11:06:16 +00:00
|
|
|
const branches: BranchConfig[] = [
|
2019-07-04 14:00:00 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr1',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.PrEdited,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName1',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr2',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep2' },
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep3' },
|
|
|
|
],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.PrEdited,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName2',
|
|
|
|
},
|
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
2020-01-10 10:35:49 +00:00
|
|
|
platform.getBranchPr
|
|
|
|
.mockResolvedValueOnce({ ...mock<Pr>(), number: 1 })
|
|
|
|
.mockResolvedValueOnce(undefined);
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toBe(
|
2021-04-26 14:15:03 +00:00
|
|
|
loadFixture('master-issue_with_2_PR_edited.txt')
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(2);
|
|
|
|
expect(platform.getBranchPr.mock.calls[0][0]).toBe('branchName1');
|
|
|
|
expect(platform.getBranchPr.mock.calls[1][0]).toBe('branchName2');
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform, 0, 0, 2, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checks an issue with 3 PR in progress and rebase all option', async () => {
|
2020-03-02 11:06:16 +00:00
|
|
|
const branches: BranchConfig[] = [
|
2019-07-04 14:00:00 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr1',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Rebase,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName1',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr2',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep2' },
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep3' },
|
|
|
|
],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Rebase,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName2',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr3',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep3' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Rebase,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName3',
|
|
|
|
},
|
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
2020-01-10 10:35:49 +00:00
|
|
|
platform.getBranchPr
|
|
|
|
.mockResolvedValueOnce({ ...mock<Pr>(), number: 1 })
|
|
|
|
.mockResolvedValueOnce(undefined)
|
|
|
|
.mockResolvedValueOnce({ ...mock<Pr>(), number: 3 });
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toBe(
|
2021-04-26 14:15:03 +00:00
|
|
|
loadFixture('master-issue_with_3_PR_in_progress.txt')
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(3);
|
|
|
|
expect(platform.getBranchPr.mock.calls[0][0]).toBe('branchName1');
|
|
|
|
expect(platform.getBranchPr.mock.calls[1][0]).toBe('branchName2');
|
|
|
|
expect(platform.getBranchPr.mock.calls[2][0]).toBe('branchName3');
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform, 0, 0, 3, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('checks an issue with 2 PR closed / ignored', async () => {
|
2020-03-02 11:06:16 +00:00
|
|
|
const branches: BranchConfig[] = [
|
2019-07-04 14:00:00 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr1',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.AlreadyExisted,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName1',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-04 14:00:00 +00:00
|
|
|
prTitle: 'pr2',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep2' },
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep3' },
|
|
|
|
],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.AlreadyExisted,
|
2019-07-04 14:00:00 +00:00
|
|
|
branchName: 'branchName2',
|
|
|
|
},
|
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
2020-01-10 10:35:49 +00:00
|
|
|
platform.getBranchPr
|
|
|
|
.mockResolvedValueOnce({ ...mock<Pr>(), number: 1 })
|
|
|
|
.mockResolvedValueOnce(undefined)
|
|
|
|
.mockResolvedValueOnce({ ...mock<Pr>(), number: 3 });
|
2020-07-11 09:55:30 +00:00
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-04 14:00:00 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toBe(
|
2021-04-26 14:15:03 +00:00
|
|
|
loadFixture('master-issue_with_2_PR_closed_ignored.txt')
|
2019-07-04 14:00:00 +00:00
|
|
|
);
|
|
|
|
expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(2);
|
2020-01-14 15:12:14 +00:00
|
|
|
expect(platform.findPr.mock.calls[0][0].branchName).toBe('branchName1');
|
|
|
|
expect(platform.findPr.mock.calls[0][0].prTitle).toBe('pr1');
|
2020-08-18 10:19:19 +00:00
|
|
|
expect(platform.findPr.mock.calls[0][0].state).toBe(PrState.NotOpen);
|
2020-01-14 15:12:14 +00:00
|
|
|
expect(platform.findPr.mock.calls[1][0].branchName).toBe('branchName2');
|
|
|
|
expect(platform.findPr.mock.calls[1][0].prTitle).toBe('pr2');
|
2020-08-18 10:19:19 +00:00
|
|
|
expect(platform.findPr.mock.calls[1][0].state).toBe(PrState.NotOpen);
|
2019-07-04 14:00:00 +00:00
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform, 0, 0, 0, 2);
|
|
|
|
});
|
2019-07-11 11:48:41 +00:00
|
|
|
|
|
|
|
it('checks an issue with 3 PR in approval', async () => {
|
2020-03-02 11:06:16 +00:00
|
|
|
const branches: BranchConfig[] = [
|
2019-07-11 11:48:41 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-11 11:48:41 +00:00
|
|
|
prTitle: 'pr1',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep1' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NeedsPrApproval,
|
2019-07-11 11:48:41 +00:00
|
|
|
branchName: 'branchName1',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-11 11:48:41 +00:00
|
|
|
prTitle: 'pr2',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep2' },
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep3' },
|
|
|
|
],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NeedsPrApproval,
|
2019-07-11 11:48:41 +00:00
|
|
|
branchName: 'branchName2',
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-07-11 11:48:41 +00:00
|
|
|
prTitle: 'pr3',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep3' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.NeedsPrApproval,
|
2019-07-11 11:48:41 +00:00
|
|
|
branchName: 'branchName3',
|
|
|
|
},
|
2019-08-26 06:51:04 +00:00
|
|
|
{
|
2020-01-10 10:35:49 +00:00
|
|
|
...mock<BranchConfig>(),
|
2019-08-26 06:51:04 +00:00
|
|
|
prTitle: 'pr4',
|
2020-01-10 10:35:49 +00:00
|
|
|
upgrades: [{ ...mock<PrUpgrade>(), depName: 'dep4' }],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Pending,
|
2019-08-26 06:51:04 +00:00
|
|
|
branchName: 'branchName4',
|
|
|
|
},
|
2019-07-11 11:48:41 +00:00
|
|
|
];
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboard = true;
|
|
|
|
config.dependencyDashboardPrApproval = true;
|
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
2019-07-11 11:48:41 +00:00
|
|
|
expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].title).toBe(
|
2020-07-11 09:55:30 +00:00
|
|
|
config.dependencyDashboardTitle
|
2019-07-11 11:48:41 +00:00
|
|
|
);
|
2020-01-07 10:40:53 +00:00
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toBe(
|
2021-04-26 14:15:03 +00:00
|
|
|
loadFixture('master-issue_with_3_PR_in_approval.txt')
|
2019-07-11 11:48:41 +00:00
|
|
|
);
|
|
|
|
expect(platform.findPr).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
// same with dry run
|
|
|
|
await dryRun(branches, platform);
|
|
|
|
});
|
2020-09-21 20:04:11 +00:00
|
|
|
|
|
|
|
it('contains logged problems', async () => {
|
|
|
|
const branches: BranchConfig[] = [
|
|
|
|
{
|
|
|
|
...mock<BranchConfig>(),
|
|
|
|
prTitle: 'pr1',
|
|
|
|
upgrades: [
|
|
|
|
{ ...mock<PrUpgrade>(), depName: 'dep1', repository: 'repo1' },
|
|
|
|
],
|
2021-04-15 17:06:55 +00:00
|
|
|
result: BranchResult.Pending,
|
2020-09-21 20:04:11 +00:00
|
|
|
branchName: 'branchName1',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
logger.getProblems.mockReturnValueOnce([
|
|
|
|
{
|
|
|
|
level: ERROR,
|
|
|
|
msg: 'everything is broken',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: WARN,
|
|
|
|
msg: 'just a bit',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: ERROR,
|
|
|
|
msg: 'i am a duplicated problem',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: ERROR,
|
|
|
|
msg: 'i am a duplicated problem',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: ERROR,
|
|
|
|
msg: 'i am a non-duplicated problem',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: WARN,
|
|
|
|
msg: 'i am a non-duplicated problem',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: WARN,
|
|
|
|
msg: 'i am an artifact error',
|
|
|
|
artifactErrors: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
config.dependencyDashboard = true;
|
|
|
|
await dependencyDashboard.ensureMasterIssue(config, branches);
|
|
|
|
expect(platform.ensureIssue).toHaveBeenCalledTimes(1);
|
|
|
|
expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot();
|
|
|
|
});
|
2019-07-04 14:00:00 +00:00
|
|
|
});
|
|
|
|
});
|