Skip to content

Commit 6452c0e

Browse files
authored
Merge pull request #77 from rulasg:improvements
Enhance issue listing and access functions with role filtering
2 parents c527928 + 1778195 commit 6452c0e

4 files changed

Lines changed: 45 additions & 13 deletions

File tree

public/addRepoIssueComment.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function Get-RepoIssue{
6363
return $null
6464
}
6565

66-
$param = @{ owner = $Owner ; repo = $Repo; attributes="number,title,url" }
66+
$param = @{ owner = $Owner ; repo = $Repo; attributes="number,title,state,url" }
6767

6868
# Return the URL of the comment
6969
$result = Invoke-MyCommandJson -Command ListRepoIssues -Parameters $param

public/getRepoAccess.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function Get-RepoAccess{
1010
[OutputType([hashtable])]
1111
param(
1212
[Parameter()] [string]$Owner,
13-
[Parameter()] [string]$Repo
13+
[Parameter()] [string]$Repo,
14+
[Parameter()] [string]$Role
1415
)
1516

1617
# Resolve repo name from parameters or environment
@@ -33,6 +34,11 @@ function Get-RepoAccess{
3334
# no need to unique the list as github makes them exclusive
3435
$ret = $access + $invitations
3536

37+
if($Role){
38+
"Filtering by role: $Role" | Write-Verbose
39+
$ret = $ret.GetEnumerator() | Where-Object { $_.Value -like "$Role*" }
40+
}
41+
3642
"Found $($ret.Count) users with access or invitations" | Write-Verbose
3743

3844
return $ret

public/getRepoAccessTeam.ps1

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ function Get-RepoAccessTeam{
3333
}
3434

3535
# Get access Control
36-
$accessList = Get-RepoAccess -Owner $owner -Repo $repo
37-
38-
if($Role){
39-
"Filtering by role: $Role" | Write-Verbose
40-
$accessList = $accessList.GetEnumerator() | Where-Object { $_.Value -like "$Role*" }
41-
}
36+
$accessList = Get-RepoAccess -Owner $owner -Repo $repo -Role:$Role
4237

38+
4339
# Sort by access
4440
$accessList = $accessList.GetEnumerator() | Sort-Object -Property Value
4541

@@ -109,13 +105,13 @@ function Get-RepoUser{
109105
)
110106

111107
process{
112-
113-
$parameters = @{
114-
login = $Login
115-
}
116108

117-
$result = Invoke-MyCommandJson -Command GetUser -Parameters $parameters
109+
$result = Get-UserInfo -Login $Login
118110

111+
if($null -eq $result){
112+
"Error: $Login not found" | Write-Error
113+
return
114+
}
119115
$ret = [PSCustomObject]@{
120116
login = $result.login
121117
name = $result.name
@@ -131,3 +127,22 @@ function Get-RepoUser{
131127
}
132128
} Export-ModuleMember -Function Get-RepoUser
133129

130+
function Get-UserInfo{
131+
[CmdletBinding()]
132+
[OutputType([PSCustomObject])]
133+
param(
134+
[Parameter(Position=0,ValueFromPipeline)][string]$Login
135+
)
136+
137+
process{
138+
$user = Invoke-MyCommandJson -Command GetUser -Parameters @{login = $Login}
139+
140+
if($user.login -ne $Login){
141+
"Error: $login not found" | Write-Error
142+
return $null
143+
}
144+
145+
return $user
146+
}
147+
} Export-ModuleMember -Function Get-UserInfo
148+

public/hashtable.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Convert-HashtableToObject {
2+
param (
3+
[hashtable]$Hashtable
4+
)
5+
$Hashtable.GetEnumerator() | ForEach-Object {
6+
[PSCustomObject]@{
7+
Handle=$_.Key
8+
Role=$_.Value
9+
}
10+
}
11+
} Export-ModuleMember -Function Convert-HashtableToObject

0 commit comments

Comments
 (0)