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

feat(importCDX): enhance component VCS naming convention for improved consistency #2744

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class CycloneDxBOMImporter {
"github.com", "https://github.com/%s/%s",
"gitlab.com", "https://gitlab.com/%s/%s",
"bitbucket.org", "https://bitbucket.org/%s/%s",
"cs.opensource.google", "https://cs.opensource.google/%s/%s",
"cs.opensource.google", "https://cs.opensource.google/%s/%s/%s",
"go.googlesource.com", "https://go.googlesource.com/%s",
"pypi.org", "https://pypi.org/project/%s"
);
Expand Down Expand Up @@ -982,6 +982,51 @@ private String getComponentNameFromVCS(String vcsUrl, boolean isGetVendorandName
String compName = vcsUrl.replaceAll(SCHEMA_PATTERN, "$1");
String[] parts = compName.split("/");

String domain = parts[0];
String[] pathParts = Arrays.copyOfRange(parts, 1, parts.length);

if (VCS_HOSTS.containsKey(domain)) {
switch (domain) {
case "github.com":
case "bitbucket.org":
if(pathParts.length >= 2){
if(isGetVendorandName){
return String.join("/", Arrays.copyOfRange(pathParts, 0, pathParts.length));
}else{
return pathParts[pathParts.length - 1];
}
}

case "gitlab.com":
case "cs.opensource.google":
if(pathParts.length >= 2){
if(isGetVendorandName){
return String.join("/", Arrays.copyOfRange(pathParts, 0, pathParts.length));
}else{
return String.join("/", Arrays.copyOfRange(pathParts, 1, pathParts.length));
}
}

case"go.googlesource.com":
if(pathParts.length >= 1){
if(isGetVendorandName){
return String.join("/", domain, pathParts[pathParts.length - 1]);
}else{
return pathParts[pathParts.length - 1];
}
}

case"pypi.org":
if(pathParts.length >= 2){
if(isGetVendorandName){
return String.join("/", domain, pathParts[pathParts.length - 1]);
}else{
return pathParts[pathParts.length - 1];
}
}
}
}

if (parts.length >= 2) {
if (isGetVendorandName) {
return String.join("/", Arrays.copyOfRange(parts, 1, parts.length));
Expand Down