Skip to content

Commit

Permalink
Add Properties VCPKG (#855)
Browse files Browse the repository at this point in the history
* added properties

* changed download location parsing to sanitize better

* added more checks

---------

Co-authored-by: Amitla Vannikumar <[email protected]>
  • Loading branch information
amitla1 and Amitla Vannikumar committed Oct 16, 2023
1 parent 25e572f commit a54cb7c
Showing 1 changed file with 29 additions and 1 deletion.
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
Expand All @@ -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; }
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit a54cb7c

Please sign in to comment.