Skip to content

Commit

Permalink
Get-VSTeamFeed: distinguish between project and organization level sc…
Browse files Browse the repository at this point in the history
…ope feeds

Fixes #487
  • Loading branch information
SebastianSchuetze committed Sep 18, 2022
1 parent 406ec8f commit 2d9b389
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 84 deletions.
11 changes: 11 additions & 0 deletions .docs/Get-VSTeamFeed.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,20 @@ Specifies the ID of the feed.
```yaml
Type: Guid
Aliases: ID
Parameter Sets: ByID
Accept pipeline input: true (ByPropertyName)
```
### Scope
Specifies the scope of the feed. Valid values are 'organization' or 'project'.
```yaml
Type: String
Parameter Sets: ByScope
Accepted values: organization, project
```
<!-- #include "./params/projectName.md" -->
## INPUTS
Expand Down
47 changes: 30 additions & 17 deletions Source/Public/Get-VSTeamFeed.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
function Get-VSTeamFeed {
[CmdletBinding(DefaultParameterSetName = 'List',
HelpUri='https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Get-VSTeamFeed')]
HelpUri = 'https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Get-VSTeamFeed')]
param (
[Parameter(ParameterSetName = 'ByID', Position = 0)]
[Alias('FeedId')]
[string[]] $Id,

[Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = 'ByScope', Position = 1)]
[ValidateSet('organization', 'project')]
[string] $Scope,

[Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)]
[vsteam_lib.ProjectValidateAttribute($false)]
[ArgumentCompleter([vsteam_lib.ProjectCompleter])]
[string] $ProjectName
Expand All @@ -22,31 +26,40 @@ function Get-VSTeamFeed {

if ($ProjectName) {
$commonArgs.ProjectName = $ProjectName
}else{
}
else {
$commonArgs.NoProject = $true
}

if ($id) {
if ($PSCmdlet.ParameterSetName -eq 'ByID') {
foreach ($item in $id) {
$resp = _callAPI @commonArgs -Id $item

Write-Verbose $resp
$item = [vsteam_lib.Feed]::new($resp)

Write-Output $item
$resp += _callAPI @commonArgs -Id $item
}
}
else {
$resp = _callAPI @commonArgs
$resp = (_callAPI @commonArgs).value
}

$objs = @()
$feeds = @()
foreach ($feed in $resp) {
Write-Verbose $feed
$feeds += [vsteam_lib.Feed]::new($feed)
}

foreach ($item in $resp.value) {
Write-Verbose $item
$objs += [vsteam_lib.Feed]::new($item)
}
if ($PSCmdlet.ParameterSetName -eq 'ByScope') {

$orgFeedApiUrl = ("$env:TEAM_ACCT/_apis/packaging/feeds/") -replace 'dev.azure.com', 'feeds.dev.azure.com'
if ($Scope -eq 'organization') {
# this part of the url can only be used with the organization scope
$feeds = $feeds | Where-Object {

Write-Output $objs
}
}
else {
$feeds = $feeds | Where-Object { $_.Url -notmatch $orgFeedApiUrl }
}
}

Write-Output $feeds
}
}
195 changes: 129 additions & 66 deletions Tests/SampleFiles/Get-VSTeamFeed.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,131 @@
{
"count": 1,
"value": [
{
"description": null,
"url": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000",
"_links": {
"self": {
"href": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000"
},
"packages": {
"href": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000/Packages"
},
"permissions": {
"href": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000/Permissions"
}
"count": 1,
"value": [
{
"description": null,
"url": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000",
"_links": {
"self": {
"href": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000"
},
"packages": {
"href": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000/Packages"
},
"permissions": {
"href": "https://feeds.dev.azure.com/Test/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000/Permissions"
}
},
"hideDeletedPackageVersions": true,
"defaultViewId": "00000000-0000-0000-0000-000000000000",
"id": "00000000-0000-0000-0000-000000000001",
"name": "ber",
"upstreamEnabled": true,
"viewId": null,
"viewName": null,
"fullyQualifiedName": "ber",
"fullyQualifiedId": "00000000-0000-0000-0000-000000000000",
"upstreamSources": [
{
"id": "00000000-0000-0000-0000-000000000010",
"name": "npmjs",
"protocol": "npm",
"location": "https://registry.npmjs.org/",
"displayLocation": "https://registry.npmjs.org/",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "NuGet Gallery",
"protocol": "nuget",
"location": "https://api.nuget.org/v3/index.json",
"displayLocation": "https://api.nuget.org/v3/index.json",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "PyPI",
"protocol": "pypi",
"location": "https://pypi.org/",
"displayLocation": "https://pypi.org/",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "Maven Central",
"protocol": "Maven",
"location": "https://repo.maven.apache.org/maven2/",
"displayLocation": "https://repo.maven.apache.org/maven2/",
"upstreamSourceType": "public",
"status": "ok"
}
],
"capabilities": "defaultCapabilities"
},
"hideDeletedPackageVersions": true,
"defaultViewId": "00000000-0000-0000-0000-000000000000",
"id": "00000000-0000-0000-0000-000000000001",
"name": "ber",
"upstreamEnabled": true,
"viewId": null,
"viewName": null,
"fullyQualifiedName": "ber",
"fullyQualifiedId": "00000000-0000-0000-0000-000000000000",
"upstreamSources": [
{
"id": "00000000-0000-0000-0000-000000000010",
"name": "npmjs",
"protocol": "npm",
"location": "https://registry.npmjs.org/",
"displayLocation": "https://registry.npmjs.org/",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "NuGet Gallery",
"protocol": "nuget",
"location": "https://api.nuget.org/v3/index.json",
"displayLocation": "https://api.nuget.org/v3/index.json",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "PyPI",
"protocol": "pypi",
"location": "https://pypi.org/",
"displayLocation": "https://pypi.org/",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "Maven Central",
"protocol": "Maven",
"location": "https://repo.maven.apache.org/maven2/",
"displayLocation": "https://repo.maven.apache.org/maven2/",
"upstreamSourceType": "public",
"status": "ok"
}
],
"capabilities": "defaultCapabilities"
}
]
}
{
"description": null,
"url": "https://feeds.dev.azure.com/Test/5f438b59-28eb-43af-a876-2059441d943a/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000",
"_links": {
"self": {
"href": "https://feeds.dev.azure.com/Test/5f438b59-28eb-43af-a876-2059441d943a/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000"
},
"packages": {
"href": "https://feeds.dev.azure.com/Test/5f438b59-28eb-43af-a876-2059441d943a/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000/Packages"
},
"permissions": {
"href": "https://feeds.dev.azure.com/Test/5f438b59-28eb-43af-a876-2059441d943a/_apis/Packaging/Feeds/00000000-0000-0000-0000-000000000000/Permissions"
}
},
"hideDeletedPackageVersions": true,
"defaultViewId": "00000000-0000-0000-0000-000000000000",
"id": "00000000-0000-0000-0000-000000000001",
"name": "ber",
"upstreamEnabled": true,
"viewId": null,
"viewName": null,
"fullyQualifiedName": "ber",
"fullyQualifiedId": "00000000-0000-0000-0000-000000000000",
"upstreamSources": [
{
"id": "00000000-0000-0000-0000-000000000010",
"name": "npmjs",
"protocol": "npm",
"location": "https://registry.npmjs.org/",
"displayLocation": "https://registry.npmjs.org/",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "NuGet Gallery",
"protocol": "nuget",
"location": "https://api.nuget.org/v3/index.json",
"displayLocation": "https://api.nuget.org/v3/index.json",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "PyPI",
"protocol": "pypi",
"location": "https://pypi.org/",
"displayLocation": "https://pypi.org/",
"upstreamSourceType": "public",
"status": "ok"
},
{
"id": "00000000-0000-0000-0000-000000000000",
"name": "Maven Central",
"protocol": "Maven",
"location": "https://repo.maven.apache.org/maven2/",
"displayLocation": "https://repo.maven.apache.org/maven2/",
"upstreamSourceType": "public",
"status": "ok"
}
],
"capabilities": "defaultCapabilities"
}
]
}
Loading

0 comments on commit 2d9b389

Please sign in to comment.