Skip to content

Commit 816c0c0

Browse files
mckrakennvuillam
andauthored
Add support for ssh remotes (#6899)
* fixes: #6511 - add support for ssh remotes * add CHANGELOG entry --------- Co-authored-by: Nicolas Vuillamy <[email protected]>
1 parent c54c613 commit 816c0c0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image
1010

1111
- Core
12+
- Add support for SSH remote origins when building custom flavors (fixes: #6511)
1213

1314
- New linters
1415

mega-linter-runner/generators/mega-linter-custom-flavor/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,24 @@ Example: 'megalinter-custom-flavor-python-light'
115115
this.customFlavorAuthor = user.value;
116116
// Get remote repo
117117
const remote = await git.getRemotes(true);
118-
this.customFlavorRepo = remote[0].refs.fetch.replace('https://github.com/', '').replace('.git', '');
119-
this.customFlavorRepoUrl = remote[0].refs.fetch.replace('.git', '');
118+
const remoteUrl = remote[0].refs.fetch;
119+
120+
// Handle both HTTPS and SSH git origins
121+
let repoPath, repoUrl;
122+
if (remoteUrl.startsWith('https://github.com/')) {
123+
// HTTPS format: https://github.com/user/repo.git
124+
repoPath = remoteUrl.replace('https://github.com/', '').replace('.git', '');
125+
repoUrl = remoteUrl.replace('.git', '');
126+
} else if (remoteUrl.startsWith('[email protected]:')) {
127+
// SSH format: git@github.com:user/repo.git
128+
repoPath = remoteUrl.replace('[email protected]:', '').replace('.git', '');
129+
repoUrl = `https://github.com/${repoPath}`;
130+
} else {
131+
throw new Error(`Unsupported git remote format: ${remoteUrl}. Only GitHub HTTPS and SSH formats are supported.`);
132+
}
133+
134+
this.customFlavorRepo = repoPath;
135+
this.customFlavorRepoUrl = repoUrl;
120136
// Custom flavor docker image version
121137
this.customFlavorDockerImageVersion = `ghcr.io/${this.customFlavorRepo}/megalinter-custom-flavor:latest`;
122138
}

0 commit comments

Comments
 (0)