Skip to content

Commit

Permalink
added more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Amitla Vannikumar committed Oct 15, 2023
1 parent 8331bbf commit 06cc66c
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet
this.Description = description;
this.DownloadLocation = downloadLocation;

if (downloadLocation.ToLower().Contains("https://github.com/"))
if (!string.IsNullOrEmpty(downloadLocation) && downloadLocation.ToLower().Contains("https://github.com/"))
{
this.SetGitRepoProperties();
}
Expand All @@ -48,17 +48,6 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet

public override ComponentType Type => ComponentType.Vcpkg;

private void SetGitRepoProperties()
{
/* example download locations
* "git+https://github.com/leethomason/tinyxml2@9.0.0"
* "git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json"
*/
var locationArr = this.DownloadLocation.Split('/');
this.GitRepositoryOwner = locationArr[2];
this.GitRepositoryName = locationArr[3].TakeWhile(ch => char.IsLetterOrDigit(ch)).ToString();
}

public override string Id
{
get
Expand Down Expand Up @@ -92,4 +81,22 @@ public override PackageURL PackageUrl
}
}
}

private void SetGitRepoProperties()
{
/* example download locations
* "git+https://github.com/leethomason/tinyxml2@9.0.0"
* "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 06cc66c

Please sign in to comment.