Skip to content

Commit 5fb4a60

Browse files
committed
fix: add eclipse normalize
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent ed269a3 commit 5fb4a60

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

services/apps/packages_worker/src/maven/__tests__/normalize.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,29 @@ describe('normalizeScmUrl', () => {
236236
expect(normalizeScmUrl('https://gitbox.apache.org/some/other/path')).toBeNull()
237237
})
238238

239+
it('recovers git.eclipse.org cgit URLs, keeping the /c/ prefix and dropping trailing tree paths', () => {
240+
expect(normalizeScmUrl('http://git.eclipse.org/c/eclipselink/javax.persistence.git')).toBe(
241+
'https://git.eclipse.org/c/eclipselink/javax.persistence',
242+
)
243+
expect(
244+
normalizeScmUrl('https://git.eclipse.org/c/eclipsescada/org.eclipse.scada.utils.git'),
245+
).toBe('https://git.eclipse.org/c/eclipsescada/org.eclipse.scada.utils')
246+
expect(
247+
normalizeScmUrl('http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree'),
248+
).toBe('https://git.eclipse.org/c/jetty/org.eclipse.jetty.project')
249+
expect(
250+
normalizeScmUrl(
251+
'http://git.eclipse.org/c/jetty/org.eclipse.jetty.orbit.git/tree/jetty-orbit',
252+
),
253+
).toBe('https://git.eclipse.org/c/jetty/org.eclipse.jetty.orbit')
254+
})
255+
256+
it('returns null for git.eclipse.org URLs with no recoverable repo path', () => {
257+
expect(normalizeScmUrl('https://git.eclipse.org/')).toBeNull()
258+
expect(normalizeScmUrl('https://git.eclipse.org/c/')).toBeNull()
259+
expect(normalizeScmUrl('https://git.eclipse.org/c/onlyowner')).toBeNull()
260+
})
261+
239262
// SCP colon form: "host:owner/repo" where the colon is a path separator, not a port
240263
it('recovers bare host:owner/repo SCP colon form', () => {
241264
expect(normalizeScmUrl('github.com:japgolly/scalacss.git')).toBe(

services/apps/packages_worker/src/maven/extract.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,28 @@ function normalizeApacheGitwebUrl(host: string, pathname: string, search: string
551551
return `https://${host}/repos/asf/${name}`
552552
}
553553

554+
/**
555+
* Eclipse's cgit instance serves repos as /c/<owner>/<repo>[.git][/tree/...], the
556+
* same owner/repo shape as the generic hosts but under a fixed /c/ prefix that
557+
* cgit requires for a working link (unlike GitHub-style hosts, a bare
558+
* https://git.eclipse.org/<owner>/<repo> does not resolve) — so the prefix is
559+
* kept in the output rather than stripped like the generic path logic would.
560+
*/
561+
const ECLIPSE_CGIT_HOSTS = new Set(['git.eclipse.org'])
562+
563+
function normalizeEclipseCgitUrl(host: string, pathname: string): string | null {
564+
if (!pathname.startsWith('/c/')) return null
565+
566+
const segments = pathname.slice('/c/'.length).split('/').filter(Boolean)
567+
if (segments.length < 2) return null
568+
569+
const owner = segments[0]
570+
const name = segments[1].replace(/\.git$/, '')
571+
if (!owner || !name || /\$\{|%7B/i.test(owner) || /\$\{|%7B/i.test(name)) return null
572+
573+
return `https://${host}/c/${owner}/${name}`
574+
}
575+
554576
/**
555577
* Converts the raw SCM URL from a POM (declared_repository_url) into a clean,
556578
* canonical `https://<host>/<owner>/<repo>` repository URL suitable for storage
@@ -621,6 +643,10 @@ export function normalizeScmUrl(raw: string | null): string | null {
621643
return normalizeApacheGitwebUrl(host, parsed.pathname, parsed.search)
622644
}
623645

646+
if (ECLIPSE_CGIT_HOSTS.has(host)) {
647+
return normalizeEclipseCgitUrl(host, parsed.pathname)
648+
}
649+
624650
if (!SCM_HOSTS.has(host)) return null
625651

626652
// Require at least owner + repo path segments

0 commit comments

Comments
 (0)