Skip to content

Commit

Permalink
Merge pull request #132 from ruromero/go-python-report
Browse files Browse the repository at this point in the history
feat: add report links for golang and pypi
  • Loading branch information
ruromero authored Aug 30, 2023
2 parents cc11f17 + 69741a6 commit 7a31482
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 35 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/redhat/exhort/api/PackageRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.github.packageurl.MalformedPackageURLException;
import com.github.packageurl.PackageURL;
import com.redhat.exhort.api.serialization.PackageURLSerializer;
import com.redhat.exhort.integration.Constants;

public class PackageRef {

Expand All @@ -51,10 +52,15 @@ public PackageURL purl() {
}

public String name() {
if (purl.getNamespace() == null) {
return purl.getName();
switch (purl.getType()) {
case Constants.GOLANG_PKG_MANAGER:
return new StringBuffer(purl.getNamespace()).append("/").append(purl.getName()).toString();
default:
if (purl.getNamespace() == null) {
return purl.getName();
}
return new StringBuilder(purl.getNamespace()).append(":").append(purl.getName()).toString();
}
return purl.getNamespace() + ":" + purl.getName();
}

public String version() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/freemarker/templates/generated/main.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static Stream<Arguments> getSbomUseCases() {
.namespace("github.com/fabric8-analytics")
.name("cli-tools")
.version("v0.2.6-0.20211007133944-2af417bfb988")
.pkgManager(Constants.NPM_PKG_MANAGER)
.pkgManager(Constants.GOLANG_PKG_MANAGER)
.build()));
consumer.accept(
arguments(
Expand Down
88 changes: 59 additions & 29 deletions ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,78 @@ const MAVEN_URL = 'https://central.sonatype.com/artifact/';
const NPM_PREFIX = 'pkg:npm';
const NPM_URL = 'https://www.npmjs.com/package/';

export const extractDependencyName = (name: string) => {
const PYPI_PREFIX = 'pkg:pypi';
const PYPI_URL = 'https://pypi.org/project/';

const GOLANG_PREFIX = 'pkg:golang';
const GOLANG_URL = 'https://pkg.go.dev/';

const getPrefix = (name: string) => {
if (name.startsWith(MAVEN_PREFIX)) {
return name
.substring(0, name.lastIndexOf('@')) // Remove version
.substring(MAVEN_PREFIX.length + 1, name.length) // Remove package prefix
.replace(/\//g, ':');
return MAVEN_PREFIX;
}
if (name.startsWith(NPM_PREFIX)) {
return name
.substring(0, name.lastIndexOf('@')) // Remove version
.substring(NPM_PREFIX.length + 1, name.length) // Remove package prefix
.replace(/\//g, ':');
return NPM_PREFIX;
}
if (name.startsWith(PYPI_PREFIX)) {
return PYPI_PREFIX;
}
if (name.startsWith(GOLANG_PREFIX)) {
return GOLANG_PREFIX;
}
return name;

}

const getBaseUrl = (prefix: string) => {
switch (prefix) {
case MAVEN_PREFIX:
return MAVEN_URL;
case NPM_PREFIX:
return NPM_URL;
case PYPI_PREFIX:
return PYPI_URL;
case GOLANG_PREFIX:
return GOLANG_URL;
default:
return '';
};
}

export const extractDependencyName = (name: string) => {
return name.substring(0, name.lastIndexOf('@')) // Remove version
.substring(getPrefix(name).length + 1, name.length) // Remove package prefix
.replace(/\//g, ':');
};

export const extractDependencyUrl = (name: string) => {
if (name.startsWith(MAVEN_PREFIX)) {
return (
MAVEN_URL +
name
.replace(/@([^@]*)$/, '/$1') // Replace last '@' by '/'
.substring(MAVEN_PREFIX.length + 1, name.length) // Remove package prefix
);
}
if (name.startsWith(NPM_PREFIX)) {
return (
NPM_URL +
name
.replace(/@([^@]*)$/, '/v/$1') // Replace last '@' by '/v/'
.substring(NPM_PREFIX.length + 1, name.length + 2) // Remove package prefix
);
let prefix = getPrefix(name);
switch(prefix) {
case MAVEN_PREFIX:
case PYPI_PREFIX:
return (
getBaseUrl(prefix) +
name
.replace(/@([^@]*)$/, '/$1') // Replace last '@' by '/'
.substring(prefix.length + 1, name.length) // Remove package prefix
);
case NPM_PREFIX:
return (
getBaseUrl(prefix) +
name
.replace(/@([^@]*)$/, '/v/$1') // Replace last '@' by '/v/'
.substring(prefix.length + 1, name.length + 2) // Remove package prefix
);
case GOLANG_PREFIX:
return (getBaseUrl(prefix) +
name
.substring(prefix.length + 1, name.length) // Remove package prefix
);
}
return name;
};

export const extractDependencyVersion = (name: string) => {
if (name.startsWith(MAVEN_PREFIX) || name.startsWith(NPM_PREFIX)) {
return name.substring(name.lastIndexOf('@') + 1, name.length);
}
return name;
return name.substring(name.lastIndexOf('@') + 1, name.length).replace(/\?.*/,'');
};

export const issueLink = (provider: 'snyk' | 'oss-index', issueId: string) => {
Expand Down

0 comments on commit 7a31482

Please sign in to comment.