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

fix(git-submodules): take git-tags and git-refs hostRules into account #24250

Merged
merged 2 commits into from
Sep 28, 2023
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
47 changes: 47 additions & 0 deletions lib/modules/manager/git-submodules/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,53 @@ describe('modules/manager/git-submodules/extract', () => {
]);
});

it('combined username+pwd from host rule is used to detect branch for git-refs and git-tags', async () => {
gitMock.listRemote.mockResolvedValueOnce(
'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD'
);
hostRules.add({
hostType: 'git-refs',
matchHost: 'gitrefs.com',
username: 'git-refs-user',
password: 'git-refs-password',
});
hostRules.add({
hostType: 'git-tags',
matchHost: 'gittags.com',
username: 'git-tags-user',
password: 'git-tags-password',
});
const res = await extractPackageFile('', '.gitmodules.2', {});
expect(res?.deps).toHaveLength(1);
expect(res?.deps[0].currentValue).toBe('main');
expect(gitMock.env).toHaveBeenCalledWith({
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_1:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_2:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_3:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_4:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_5:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitrefs.com/',
GIT_CONFIG_VALUE_1: 'git@gitrefs.com:',
GIT_CONFIG_VALUE_2: 'https://gitrefs.com/',
GIT_CONFIG_VALUE_3: 'ssh://git@gittags.com/',
GIT_CONFIG_VALUE_4: 'git@gittags.com:',
GIT_CONFIG_VALUE_5: 'https://gittags.com/',
});
expect(gitMock.listRemote).toHaveBeenCalledWith([
'--symref',
'https://github.com/PowerShell/PowerShell-Docs',
'HEAD',
]);
});

it('extracts multiple submodules', async () => {
hostRules.add({ matchHost: 'github.com', token: '123test' });
hostRules.add({
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/git-submodules/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ async function getUrl(
const headRefRe = regEx(/ref: refs\/heads\/(?<branch>\w+)\s/);

async function getDefaultBranch(subModuleUrl: string): Promise<string> {
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables();
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables([
'git-tags',
'git-refs',
]);
const gitEnv = {
// pass all existing env variables
...process.env,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/git-submodules/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Next, all `hostRules` with both a token or username/password and `matchHost` wil
Rules from this list are converted to environment variable directives if they match _any_ of the following characteristics:

- No `hostType` is defined, or
- `hostType` is `git-tags` or `git-refs`, or
- `hostType` is a platform (`github`, `gitlab`, `azure`, etc.)
44 changes: 44 additions & 0 deletions lib/modules/manager/git-submodules/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,49 @@ describe('modules/manager/git-submodules/update', () => {
GIT_CONFIG_VALUE_2: 'https://github.com/',
});
});

it('returns content on update and uses git environment variables for git-tags/git-refs', async () => {
gitMock.submoduleUpdate.mockResolvedValue('');
gitMock.checkout.mockResolvedValue('');
hostRules.add({
hostType: 'git-refs',
matchHost: 'gitrefs.com',
username: 'git-refs-user',
password: 'git-refs-password',
});
hostRules.add({
hostType: 'git-tags',
matchHost: 'gittags.com',
username: 'git-tags-user',
password: 'git-tags-password',
});

const update = await updateDependency({
fileContent: '',
upgrade,
});
expect(update).toBe('');
expect(gitMock.env).toHaveBeenCalledWith({
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_1:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_2:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_3:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_4:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_5:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitrefs.com/',
GIT_CONFIG_VALUE_1: 'git@gitrefs.com:',
GIT_CONFIG_VALUE_2: 'https://gitrefs.com/',
GIT_CONFIG_VALUE_3: 'ssh://git@gittags.com/',
GIT_CONFIG_VALUE_4: 'git@gittags.com:',
GIT_CONFIG_VALUE_5: 'https://gittags.com/',
});
});
});
});
5 changes: 4 additions & 1 deletion lib/modules/manager/git-submodules/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default async function updateDependency({
upgrade,
}: UpdateDependencyConfig): Promise<string | null> {
const localDir = GlobalConfig.get('localDir');
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables();
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables([
'git-tags',
'git-refs',
]);
const gitEnv = {
// pass all existing env variables
...process.env,
Expand Down