Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(platform/azure): handle disabled repos without exit #13225

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/platform/azure/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GitStatusState,
PullRequestStatus,
} from 'azure-devops-node-api/interfaces/GitInterfaces';
import { REPOSITORY_ARCHIVED } from '../../constants/error-messages';
import { logger as _logger } from '../../logger';
import { BranchStatus, PrState } from '../../types';
import * as _git from '../../util/git';
Expand Down Expand Up @@ -144,6 +145,13 @@ describe('platform/azure/index', () => {
name: 'prj2',
},
},
{
name: 'repo3',
project: {
name: 'some',
},
isDisabled: true,
},
]),
} as any)
);
Expand All @@ -168,6 +176,14 @@ describe('platform/azure/index', () => {
expect(azureApi.gitApi.mock.calls).toMatchSnapshot();
expect(config).toMatchSnapshot();
});

it(`throws if repo is disabled`, async () => {
await expect(
initRepo({
repository: 'some/repo3',
})
).rejects.toThrow(REPOSITORY_ARCHIVED);
});
});

describe('getRepoForceRebase', () => {
Expand Down
9 changes: 8 additions & 1 deletion lib/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
import delay from 'delay';
import JSON5 from 'json5';
import { PlatformId } from '../../constants';
import { REPOSITORY_EMPTY } from '../../constants/error-messages';
import {
REPOSITORY_ARCHIVED,
REPOSITORY_EMPTY,
} from '../../constants/error-messages';
import { logger } from '../../logger';
import { BranchStatus, PrState, VulnerabilityAlert } from '../../types';
import * as git from '../../util/git';
Expand Down Expand Up @@ -170,6 +173,10 @@ export async function initRepo({
const repos = await azureApiGit.getRepositories();
const repo = getRepoByName(repository, repos);
logger.debug({ repositoryDetails: repo }, 'Repository details');
if (repo.isDisabled) {
logger.debug('Repository is disabled- throwing error to abort renovation');
throw new Error(REPOSITORY_ARCHIVED);
}
// istanbul ignore if
if (!repo.defaultBranch) {
logger.debug('Repo is empty');
Expand Down