Skip to content

Commit

Permalink
feat: includeMirrors (#23110)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
3 people committed Jul 9, 2023
1 parent 9d3d7a9 commit 12e8935
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ Use the `extends` field instead of this if, for example, you need the ability fo
When Renovate resolves `globalExtends` it does not fully process the configuration.
This means that Renovate does not have the authentication it needs to fetch private things.

## includeMirrors

By default, Renovate does not autodiscover repositories that are mirrors.

Change this setting to `true` to include repositories that are mirrors as Renovate targets.

## logContext

`logContext` is included with each log entry only if `logFormat="json"` - it is not included in the pretty log output.
Expand Down
9 changes: 9 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ const options: RenovateOptions[] = [
allowedValues: ['auto', 'enabled', 'disabled'],
default: 'auto',
},
{
name: 'includeMirrors',
description:
'Whether to process repositories that are mirrors. By default, repositories that are mirrors are skipped.',
type: 'boolean',
default: false,
supportedPlatforms: ['gitlab'],
globalOnly: true,
},
{
name: 'forkToken',
description: 'Set a personal access token here to enable "fork mode".',
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface RepoGlobalConfig {
containerbaseDir?: string;
platform?: PlatformId;
endpoint?: string;
includeMirrors?: boolean;
}

export interface LegacyAdminConfig {
Expand Down
42 changes: 42 additions & 0 deletions lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ describe('modules/platform/gitlab/index', () => {
expect(repos).toEqual(['a/b', 'c/d']);
});

it('should return an array of repos including mirrors', async () => {
httpMock
.scope(gitlabApiHost)
.get(
'/api/v4/projects?membership=true&per_page=100&with_merge_requests_enabled=true&min_access_level=30&archived=false'
)
.reply(200, [
{
path_with_namespace: 'a/b',
},
{
path_with_namespace: 'c/d',
},
{
path_with_namespace: 'c/f',
mirror: true,
},
]);
const repos = await gitlab.getRepos({ includeMirrors: true });
expect(repos).toEqual(['a/b', 'c/d', 'c/f']);
});

it('should encode the requested topics into the URL', async () => {
httpMock
.scope(gitlabApiHost)
Expand Down Expand Up @@ -262,6 +284,26 @@ describe('modules/platform/gitlab/index', () => {
).rejects.toThrow(REPOSITORY_MIRRORED);
});

it('should not throw an error if repository is a mirror when includeMirrors option is set', async () => {
httpMock
.scope(gitlabApiHost)
.get('/api/v4/projects/some%2Frepo')
.reply(200, {
default_branch: 'master',
mirror: true,
});
expect(
await gitlab.initRepo({
repository: 'some/repo',
includeMirrors: true,
})
).toEqual({
defaultBranch: 'master',
isFork: false,
repoFingerprint: expect.any(String),
});
});

it('should throw an error if repository access is disabled', async () => {
httpMock
.scope(gitlabApiHost)
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export async function getRepos(config?: AutodiscoverConfig): Promise<string[]> {
});
logger.debug(`Discovered ${res.body.length} project(s)`);
return res.body
.filter((repo) => !repo.mirror)
.filter((repo) => !repo.mirror || config?.includeMirrors)
.map((repo) => repo.path_with_namespace);
} catch (err) {
logger.error({ err }, `GitLab getRepos error`);
Expand Down Expand Up @@ -267,6 +267,7 @@ export async function initRepo({
ignorePrAuthor,
gitUrl,
endpoint,
includeMirrors,
}: RepoParams): Promise<RepoResult> {
config = {} as any;
config.repository = urlEscape(repository);
Expand All @@ -284,7 +285,8 @@ export async function initRepo({
);
throw new Error(REPOSITORY_ARCHIVED);
}
if (res.body.mirror) {

if (res.body.mirror && includeMirrors !== true) {
logger.debug(
'Repository is a mirror - throwing error to abort renovation'
);
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface RepoParams {
cloneSubmodules?: boolean;
ignorePrAuthor?: boolean;
bbUseDevelopmentBranch?: boolean;
includeMirrors?: boolean;
}

export interface PrDebugData {
Expand Down Expand Up @@ -166,6 +167,7 @@ export type EnsureIssueResult = 'updated' | 'created';

export interface AutodiscoverConfig {
topics?: string[];
includeMirrors?: boolean;
}

export interface Platform {
Expand Down
1 change: 1 addition & 0 deletions lib/workers/global/autodiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function autodiscoverRepositories(
// Autodiscover list of repositories
let discovered = await platform.getRepos({
topics: config.autodiscoverTopics,
includeMirrors: config.includeMirrors,
});
if (!discovered?.length) {
// Soft fail (no error thrown) if no accessible repositories
Expand Down

0 comments on commit 12e8935

Please sign in to comment.