Skip to content

Commit

Permalink
feat(config): expose topLevelOrg, templateOrg to templates (#27997)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 18, 2024
1 parent e2aa68f commit e500e50
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/util/template/index.ts
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
@@ -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
Expand Up @@ -38,6 +38,10 @@ export async function getRepositoryConfig(
globalConfig,
is.string(repository) ? { repository } : repository,
);
const repoParts = repoConfig.repository.split('/');
repoParts.pop();
repoConfig.parentOrg = repoParts.join('/');
repoConfig.topLevelOrg = repoParts.shift();
// TODO: types (#22198)
const platform = GlobalConfig.get('platform')!;
repoConfig.localDir =
Expand Down

0 comments on commit e500e50

Please sign in to comment.