Skip to content

Commit

Permalink
NuGet fixes (#3679)
Browse files Browse the repository at this point in the history
Fixes #3678 Use authenticated request to get user type

Only include dependencies in NuGet package if dependency template is set

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Sep 24, 2024
1 parent 018def4 commit 19a209c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
58 changes: 30 additions & 28 deletions NuGet/New-BcNuGetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -217,41 +217,43 @@ Function New-BcNuGetPackage {
$XmlObjectWriter.WriteAttributeString("url", $githubRepository)
$XmlObjectWriter.WriteEndElement()
}
$XmlObjectWriter.WriteStartElement("dependencies")
if ($appJson.PSObject.Properties.Name -eq 'dependencies') {
$appJson.dependencies | ForEach-Object {
if ($_.PSObject.Properties.name -eq 'id') {
$dependencyId = $_.id
} else {
$dependencyId = $_.appId
if ($dependencyIdTemplate) {
$XmlObjectWriter.WriteStartElement("dependencies")
if ($appJson.PSObject.Properties.Name -eq 'dependencies') {
$appJson.dependencies | ForEach-Object {
if ($_.PSObject.Properties.name -eq 'id') {
$dependencyId = $_.id
} else {
$dependencyId = $_.appId
}
$id = Get-BcNuGetPackageId -packageIdTemplate $dependencyIdTemplate -publisher $_.publisher -name $_.name -id $dependencyId -version $_.version.replace('.','-')
$XmlObjectWriter.WriteStartElement("dependency")
$XmlObjectWriter.WriteAttributeString("id", $id)
$XmlObjectWriter.WriteAttributeString("version", (GetDependencyVersionStr -template $dependencyVersionTemplate -version ([System.Version]::Parse($_.version))))
$XmlObjectWriter.WriteEndElement()
}
$id = Get-BcNuGetPackageId -packageIdTemplate $dependencyIdTemplate -publisher $_.publisher -name $_.name -id $dependencyId -version $_.version.replace('.','-')
}
if ($applicationDependency) {
$XmlObjectWriter.WriteStartElement("dependency")
$XmlObjectWriter.WriteAttributeString("id", $applicationDependencyId)
$XmlObjectWriter.WriteAttributeString("version", $applicationDependency)
$XmlObjectWriter.WriteEndElement()
}
if ($platformDependency) {
$XmlObjectWriter.WriteStartElement("dependency")
$XmlObjectWriter.WriteAttributeString("id", $platformDependencyId)
$XmlObjectWriter.WriteAttributeString("version", $platformDependency)
$XmlObjectWriter.WriteEndElement()
}
if ($isIndirectPackage.IsPresent) {
$XmlObjectWriter.WriteStartElement("dependency")
$id = Get-BcNuGetPackageId -packageIdTemplate $runtimeDependencyId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-')
$XmlObjectWriter.WriteAttributeString("id", $id)
$XmlObjectWriter.WriteAttributeString("version", (GetDependencyVersionStr -template $dependencyVersionTemplate -version ([System.Version]::Parse($_.version))))
$XmlObjectWriter.WriteAttributeString("version", '1.0.0.0')
$XmlObjectWriter.WriteEndElement()
}
}
if ($applicationDependency) {
$XmlObjectWriter.WriteStartElement("dependency")
$XmlObjectWriter.WriteAttributeString("id", $applicationDependencyId)
$XmlObjectWriter.WriteAttributeString("version", $applicationDependency)
$XmlObjectWriter.WriteEndElement()
}
if ($platformDependency) {
$XmlObjectWriter.WriteStartElement("dependency")
$XmlObjectWriter.WriteAttributeString("id", $platformDependencyId)
$XmlObjectWriter.WriteAttributeString("version", $platformDependency)
$XmlObjectWriter.WriteEndElement()
}
if ($isIndirectPackage.IsPresent) {
$XmlObjectWriter.WriteStartElement("dependency")
$id = Get-BcNuGetPackageId -packageIdTemplate $runtimeDependencyId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-')
$XmlObjectWriter.WriteAttributeString("id", $id)
$XmlObjectWriter.WriteAttributeString("version", '1.0.0.0')
$XmlObjectWriter.WriteEndElement()
}
$XmlObjectWriter.WriteEndElement()
$XmlObjectWriter.WriteEndElement()
if (!$isIndirectPackage.IsPresent) {
$XmlObjectWriter.WriteStartElement("files")
Expand Down
18 changes: 11 additions & 7 deletions NuGet/NuGetFeedClass.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class NuGetFeed {
[string] $packagePublishUrl
[string] $packageBaseAddressUrl

[hashtable] $orgType = @{}

NuGetFeed([string] $nuGetServerUrl, [string] $nuGetToken, [string[]] $patterns, [string[]] $fingerprints) {
$this.url = $nuGetServerUrl
$this.token = $nuGetToken
Expand Down Expand Up @@ -95,14 +97,16 @@ class NuGetFeed {
"Authorization" = "Bearer $($this.token)"
}
}
$orgMetadata = Invoke-RestMethod -Method GET -Uri "https://api.github.com/users/$organization"
if ($orgMetadata.type -eq 'Organization') {
$orgType = 'orgs'
}
else {
$orgType = 'users'
if (-not $this.orgType.ContainsKey($organization)) {
$orgMetadata = Invoke-RestMethod -Method GET -Headers $headers -Uri "https://api.github.com/users/$organization"
if ($orgMetadata.type -eq 'Organization') {
$this.orgType[$organization] = 'orgs'
}
else {
$this.orgType[$organization] = 'users'
}
}
$queryUrl = "https://api.github.com/$orgType/$organization/packages?package_type=nuget&per_page=100&page="
$queryUrl = "https://api.github.com/$($this.orgType[$organization])/$organization/packages?package_type=nuget&per_page=100&page="
$page = 1
Write-Host -ForegroundColor Yellow "Search package using $queryUrl$page"
$matching = @()
Expand Down

0 comments on commit 19a209c

Please sign in to comment.