mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 22:48:06 +00:00
2abd139cd2
* feat(config): add github to gitUrl supportedPlatforms Declare GitHub as a supported platform for the gitUrl option so users can configure ssh/endpoint URL resolution on github.com and GHES. Wiring in the github platform module follows in subsequent commits. Refs: renovatebot/renovate#43086 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(platform/github): fetch sshUrl from repoInfoQuery Add sshUrl to the GraphQL repository query and to the GhRepo type so the platform can resolve SSH-based git remotes. Typed as nullable to match the gitlab pattern and to allow a missing-field error path. Refs: renovatebot/renovate#43086 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(platform/github): add getRepoUrl helper Introduce a getRepoUrl helper that returns the repository git URL based on the gitUrl option: - 'ssh' uses the sshUrl from the GraphQL repo response; throws CONFIG_GIT_URL_UNAVAILABLE if not available - 'default' and 'endpoint' build an https URL from the configured endpoint with credentials embedded (current behavior) The helper is unused in this commit; initRepo wiring follows. Refs: renovatebot/renovate#43086 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(platform/github): support gitUrl in initRepo Destructure gitUrl from RepoParams and replace the inline URL construction with getRepoUrl calls. The working URL uses the fork's ssh_url when running in fork mode, otherwise the GraphQL repo.sshUrl. The upstream URL (used when forkCreation and a parentRepo is set) uses repo.sshUrl, which is the parent's URL because the GraphQL query runs before the fork swap. GhRestRepo gains an ssh_url field so findFork/createFork responses can carry the fork's SSH URL forward. Refs: renovatebot/renovate#43086 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * test(platform/github): cover gitUrl branches Add unit tests for getRepoUrl in utils.spec.ts and three integration tests in index.spec.ts that exercise initRepo with gitUrl=ssh: - ssh URL is forwarded to git.initRepo - missing sshUrl with gitUrl=ssh throws CONFIG_GIT_URL_UNAVAILABLE - fork mode uses the fork's ssh_url for url and the parent's sshUrl for upstreamUrl initRepoMock and forkInitRepoMock now include sshUrl in the GraphQL response so existing tests continue to populate the field that the new code path reads. Refs: renovatebot/renovate#43086 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * docs: note github-specific gitUrl behavior Document that 'default' and 'endpoint' produce the same URL on GitHub, that 'ssh' uses the repository's sshUrl, and that fork mode propagates SSH selection to both the working URL and the upstream URL. Refs: renovatebot/renovate#43086 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * refactor(platform/github): pass parsed URL to getRepoUrl Accept a pre-parsed URL in getRepoUrl instead of re-parsing the endpoint string inside the helper. The endpoint is validated during initPlatform so the helper no longer needs its own null check. The caller now parses once and passes the URL to both initRepo call sites; the helper clones it before mutating. Also assert config.repository as non-null at the initRepo call site, fixing the TS2345 error reported by the lint-other job. * Update docs/usage/self-hosted-configuration.md Co-authored-by: Michael Kriese <michael.kriese@gmx.de> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { CONFIG_GIT_URL_UNAVAILABLE } from '../../../constants/error-messages.ts';
|
|
import { parseUrl } from '../../../util/url.ts';
|
|
import { getRepoUrl } from './utils.ts';
|
|
|
|
describe('modules/platform/github/utils', () => {
|
|
describe('getRepoUrl()', () => {
|
|
it('returns sshUrl when gitUrl is ssh', () => {
|
|
expect(
|
|
getRepoUrl(
|
|
'some/repo',
|
|
'ssh',
|
|
'git@github.com:some/repo.git',
|
|
parseUrl('https://api.github.com')!,
|
|
'token',
|
|
),
|
|
).toBe('git@github.com:some/repo.git');
|
|
});
|
|
|
|
it('throws when gitUrl is ssh but sshUrl is missing', () => {
|
|
expect(() =>
|
|
getRepoUrl(
|
|
'some/repo',
|
|
'ssh',
|
|
null,
|
|
parseUrl('https://api.github.com')!,
|
|
'token',
|
|
),
|
|
).toThrow(CONFIG_GIT_URL_UNAVAILABLE);
|
|
});
|
|
|
|
it('builds an endpoint URL with embedded credentials by default', () => {
|
|
expect(
|
|
getRepoUrl(
|
|
'some/repo',
|
|
undefined,
|
|
'git@github.com:some/repo.git',
|
|
parseUrl('https://api.github.com')!,
|
|
'x-access-token:abc123',
|
|
),
|
|
).toBe('https://x-access-token:abc123@github.com/some/repo.git');
|
|
});
|
|
|
|
it('builds an endpoint URL when gitUrl is endpoint', () => {
|
|
expect(
|
|
getRepoUrl(
|
|
'some/repo',
|
|
'endpoint',
|
|
'git@github.com:some/repo.git',
|
|
parseUrl('https://api.github.com')!,
|
|
'token',
|
|
),
|
|
).toBe('https://token@github.com/some/repo.git');
|
|
});
|
|
|
|
it('omits credentials when authToken is null', () => {
|
|
expect(
|
|
getRepoUrl(
|
|
'some/repo',
|
|
undefined,
|
|
null,
|
|
parseUrl('https://api.github.com')!,
|
|
null,
|
|
),
|
|
).toBe('https://github.com/some/repo.git');
|
|
});
|
|
|
|
it('preserves a GHES endpoint host', () => {
|
|
expect(
|
|
getRepoUrl(
|
|
'some/repo',
|
|
undefined,
|
|
null,
|
|
parseUrl('https://ghe.example.com/api/v3')!,
|
|
'token',
|
|
),
|
|
).toBe('https://token@ghe.example.com/some/repo.git');
|
|
});
|
|
});
|
|
});
|