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(config): expose topLevelOrg, templateOrg to templates #27997

Merged
merged 1 commit into from
Mar 18, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/util/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const allowedFields = {
packageScope: 'The scope of the package name. Supports Maven group ID only',
parentDir:
'The name of the directory that the dependency was found in, without full path',
parentOrg: 'The name of the parent organization for the current repository',
platform: 'VCS platform in use, e.g. "github", "gitlab", etc.',
prettyDepType: 'Massaged depType',
prettyNewMajor: 'The new major value with v prepended to it.',
Expand All @@ -144,6 +145,8 @@ export const allowedFields = {
sourceRepoOrg: 'The repository organization in the sourceUrl, if present',
sourceRepoSlug: 'The slugified pathname of the sourceUrl, if present',
sourceUrl: 'The source URL for the package',
topLevelOrg:
'The name of the top-level organization for the current repository',
updateType:
'One of digest, pin, rollback, patch, minor, major, replacement, pinDigest',
upgrades: 'An array of upgrade objects in the branch',
Expand Down
31 changes: 30 additions & 1 deletion lib/workers/global/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ERROR, WARN } from 'bunyan';
import fs from 'fs-extra';
import { logger, mocked } from '../../../test/util';
import { RenovateConfig, logger, mocked } from '../../../test/util';
import { GlobalConfig } from '../../config/global';
import * as _presets from '../../config/presets';
import { CONFIG_PRESETS_INVALID } from '../../constants/error-messages';
import { DockerDatasource } from '../../modules/datasource/docker';
Expand Down Expand Up @@ -46,6 +47,34 @@ describe('workers/global/index', () => {
delete process.env.AWS_SESSION_TOKEN;
});

describe('getRepositoryConfig', () => {
const globalConfig: RenovateConfig = { baseDir: '/tmp/base' };

GlobalConfig.set({ platform: 'gitlab' });

it('should generate correct topLevelOrg/parentOrg with multiple levels', async () => {
const repository = 'a/b/c/d';
const repoConfig = await globalWorker.getRepositoryConfig(
globalConfig,
repository,
);
expect(repoConfig.topLevelOrg).toBe('a');
expect(repoConfig.parentOrg).toBe('a/b/c');
expect(repoConfig.repository).toBe('a/b/c/d');
});

it('should generate correct topLevelOrg/parentOrg with two levels', async () => {
const repository = 'a/b';
const repoConfig = await globalWorker.getRepositoryConfig(
globalConfig,
repository,
);
expect(repoConfig.topLevelOrg).toBe('a');
expect(repoConfig.parentOrg).toBe('a');
expect(repoConfig.repository).toBe('a/b');
});
});

it('handles config warnings and errors', async () => {
parseConfigs.mockResolvedValueOnce({
repositories: [],
Expand Down
4 changes: 4 additions & 0 deletions lib/workers/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export async function getRepositoryConfig(
globalConfig,
is.string(repository) ? { repository } : repository,
);
const repoParts = repoConfig.repository.split('/');
rarkins marked this conversation as resolved.
Show resolved Hide resolved
repoParts.pop();
repoConfig.parentOrg = repoParts.join('/');
repoConfig.topLevelOrg = repoParts.shift();
// TODO: types (#22198)
const platform = GlobalConfig.get('platform')!;
repoConfig.localDir =
Expand Down