-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added properties * changed download location parsing to sanitize better * added more checks --------- Co-authored-by: Amitla Vannikumar <[email protected]>
- Loading branch information
Showing
1 changed file
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
namespace Microsoft.ComponentDetection.Contracts.TypedComponent; | ||
namespace Microsoft.ComponentDetection.Contracts.TypedComponent; | ||
|
||
using System.Linq; | ||
using PackageUrl; | ||
|
||
public class VcpkgComponent : TypedComponent | ||
|
@@ -20,6 +21,11 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet | |
this.Triplet = triplet; | ||
this.Description = description; | ||
this.DownloadLocation = downloadLocation; | ||
|
||
if (!string.IsNullOrEmpty(downloadLocation) && downloadLocation.ToLower().Contains("https://github.com/")) | ||
{ | ||
this.SetGitRepoProperties(); | ||
} | ||
} | ||
|
||
public string SPDXID { get; set; } | ||
|
@@ -36,6 +42,10 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet | |
|
||
public int PortVersion { get; set; } | ||
|
||
public string GitRepositoryOwner { get; set; } | ||
|
||
public string GitRepositoryName { get; set; } | ||
|
||
public override ComponentType Type => ComponentType.Vcpkg; | ||
|
||
public override string Id | ||
|
@@ -71,4 +81,22 @@ public override PackageURL PackageUrl | |
} | ||
} | ||
} | ||
|
||
private void SetGitRepoProperties() | ||
{ | ||
/* example download locations | ||
* "git+https://github.com/leethomason/[email protected]" | ||
* "git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json" | ||
*/ | ||
var locationArr = this.DownloadLocation.Split('/'); | ||
if (!string.IsNullOrEmpty(locationArr[2])) | ||
{ | ||
this.GitRepositoryOwner = locationArr[2]; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(locationArr[3])) | ||
{ | ||
this.GitRepositoryName = locationArr[3].TakeWhile(ch => char.IsLetterOrDigit(ch)).ToString(); | ||
} | ||
} | ||
} |