From dbbec38f94aaf7e0f8bcaa73bd026e69e012ec72 Mon Sep 17 00:00:00 2001 From: Peter Murray <681306+peter-murray@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:31:30 +0000 Subject: [PATCH] Addressing paths for the name of the POM file when submitted to the API --- src/snapshot-generator.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/snapshot-generator.ts b/src/snapshot-generator.ts index 12cc524..b62a261 100644 --- a/src/snapshot-generator.ts +++ b/src/snapshot-generator.ts @@ -16,7 +16,9 @@ export async function generateSnapshot(directory: string, context?: any, job?: a try { const mavenDependencies = new MavenDependencyGraph(depgraph); - const manifest = mavenDependencies.createManifest(path.join(directory, 'pom.xml')); + // The filepath to the POM needs to be relative to the root of the GitHub repository for the links to work once uploaded + const pomFile = getRepositoryRelativePath(path.join(directory, 'pom.xml')); + const manifest = mavenDependencies.createManifest(pomFile); const snapshot = new Snapshot(getDetector(), context, job); snapshot.addManifest(manifest); @@ -106,4 +108,16 @@ function checkForMultiModule(reactorJsonFile) { } catch (err: any) { throw new Error(`Failed to load file ${reactorJsonFile}: ${err}`); } +} + +// TODO this is assuming the checkout was made into the base path of the workspace... +function getRepositoryRelativePath(file) { + const workspaceDirectory = path.resolve(process.env.GITHUB_WORKSPACE || '.'); + const fileResolved = path.dirname(path.resolve(file)); + + if (fileResolved.startsWith(workspaceDirectory)) { + return fileResolved.substring(workspaceDirectory.length + path.sep.length); + } else { + return path.resolve(file); + } } \ No newline at end of file