Skip to content
Snippets Groups Projects
Unverified Commit 2e72efde authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

feat(limits): Ignore prNotPendingHours when stabilityDays is set (#7459)


Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 9239a4b9
No related branches found
No related tags found
No related merge requests found
......@@ -176,6 +176,7 @@ describe('workers/pr', () => {
'Some body<!-- Reviewable:start -->something<!-- Reviewable:end -->\n\n',
} as never;
beforeEach(() => {
jest.resetAllMocks();
setupChangelogMock();
config = partial<BranchConfig>({
...defaultConfig,
......@@ -361,12 +362,24 @@ describe('workers/pr', () => {
expect(prResult).toEqual(PrResult.AwaitingNotPending);
expect(pr).toBeUndefined();
});
it('should not create PR if waiting for not pending with stabilityStatus yellow', async () => {
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
git.getBranchLastCommitTime.mockImplementationOnce(() =>
Promise.resolve(new Date())
);
config.prCreation = 'not-pending';
config.stabilityStatus = BranchStatus.yellow;
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.AwaitingNotPending);
expect(pr).toBeUndefined();
});
it('should create PR if pending timeout hit', async () => {
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
git.getBranchLastCommitTime.mockImplementationOnce(() =>
Promise.resolve(new Date('2017-01-01'))
);
config.prCreation = 'not-pending';
config.stabilityStatus = BranchStatus.yellow;
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
......@@ -572,7 +585,7 @@ describe('workers/pr', () => {
expect(prResult).toEqual(PrResult.BlockedByBranchAutomerge);
expect(pr).toBeUndefined();
});
it('should not return no PR if branch automerging taking too long', async () => {
it('should return PR if branch automerging taking too long', async () => {
config.automerge = true;
config.automergeType = 'branch';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
......@@ -581,6 +594,16 @@ describe('workers/pr', () => {
expect(prResult).toEqual(PrResult.Created);
expect(pr).toBeDefined();
});
it('should return no PR if stabilityStatus yellow', async () => {
config.automerge = true;
config.automergeType = 'branch';
config.stabilityStatus = BranchStatus.yellow;
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
git.getBranchLastCommitTime.mockResolvedValueOnce(new Date('2018-01-01'));
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.BlockedByBranchAutomerge);
expect(pr).toBeUndefined();
});
it('handles duplicate upgrades', async () => {
config.upgrades.push(config.upgrades[0]);
const { prResult, pr } = await prWorker.ensurePr(config);
......
......@@ -161,7 +161,10 @@ export async function ensurePr(
logger.debug(
`Branch is configured for branch automerge, branch status) is: ${await getBranchStatus()}`
);
if ((await getBranchStatus()) === BranchStatus.yellow) {
if (
config.stabilityStatus !== BranchStatus.yellow &&
(await getBranchStatus()) === BranchStatus.yellow
) {
logger.debug('Checking how long this branch has been pending');
const lastCommitTime = await getBranchLastCommitTime(branchName);
const currentTime = new Date();
......@@ -214,7 +217,8 @@ export async function ensurePr(
);
if (
!dependencyDashboardCheck &&
elapsedHours < config.prNotPendingHours
(config.stabilityStatus !== BranchStatus.yellow ||
elapsedHours < config.prNotPendingHours)
) {
logger.debug(
`Branch is ${elapsedHours} hours old - skipping PR creation`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment