Skip to content

Commit

Permalink
Merge branch 'develop' into fix/329-FixComponentInput
Browse files Browse the repository at this point in the history
  • Loading branch information
lipkau committed Jan 11, 2019
2 parents 9db4972 + 18e876d commit 34ec197
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [NEXT VERSION] - YYYY-MM-DD

### Added

- Parameter for retrieving information about a specific user with `Get-JiraUser` (#328, [@michalporeba])
- this implementations will be changed with the next major update in favor of #306

## [2.9] - 2018-12-12

### Added
Expand All @@ -21,7 +28,6 @@
- Fixed missing properties on `Get-JiraUser` (#321, [@lipkau])
- Fixed `-DateStarted` on `Add-JiraIssueWorklog` (#324, [@lipkau])


## [2.8] - 2018-06-28

More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.8.html).
Expand Down Expand Up @@ -311,6 +317,7 @@ which is in turn inspired by the [Vagrant](https://github.com/mitchellh/vagrant/
[@LiamLeane]: https://github.com/LiamLeane
[@lipkau]: https://github.com/lipkau
[@lukhase]: https://github.com/lukhase
[@michalporeba]: https://github.com/michalporeba
[@padgers]: https://github.com/padgers
[@ThePSAdmin]: https://github.com/ThePSAdmin
[@tuxgoose]: https://github.com/tuxgoose
Expand Down
7 changes: 6 additions & 1 deletion JiraPS/Public/Get-JiraUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function Get-JiraUser {
[Parameter( Position = 0, Mandatory, ParameterSetName = 'ByInputObject' )]
[Object[]] $InputObject,

[Parameter( ParameterSetName = 'ByInputObject' )]
[Parameter( ParameterSetName = 'ByUserName' )]
[Switch]$Exact,

[Switch]
$IncludeInactive,

Expand All @@ -37,6 +41,7 @@ function Get-JiraUser {

$selfResourceUri = "$server/rest/api/latest/myself"
$searchResourceUri = "$server/rest/api/latest/user/search?username={0}"
$exactResourceUri = "$server/rest/api/latest/user?username={0}"

if ($IncludeInactive) {
$searchResourceUri += "&includeInactive=true"
Expand Down Expand Up @@ -80,7 +85,7 @@ function Get-JiraUser {
$PsCmdlet.ParameterSetName = "ByUserName"
}
"ByUserName" {
$resourceURi = $searchResourceUri
$resourceURi = if ($Exact) { $exactResourceUri } else { $searchResourceUri }

foreach ($user in $UserName) {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Processing [$user]"
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Set-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function Set-JiraIssue {
$validAssignee = $true
}
else {
if ($assigneeObj = Get-JiraUser -UserName $Assignee -Credential $Credential) {
if ($assigneeObj = Get-JiraUser -UserName $Assignee -Credential $Credential -Exact) {
Write-Debug "[$($MyInvocation.MyCommand.Name)] User found (name=[$($assigneeObj.Name)],RestUrl=[$($assigneeObj.RestUrl)])"
$assigneeString = $assigneeObj.Name
$validAssignee = $true
Expand Down
16 changes: 16 additions & 0 deletions Tests/Functions/Get-JiraUser.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ Describe "Get-JiraUser" -Tag 'Unit' {
ConvertFrom-Json -InputObject $restResult
}

# Get exact user
Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user?username=$testUsername"} {
ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri'
ConvertFrom-Json -InputObject $restResult
}

# Viewing a specific user. The main difference here is that this includes groups, and the first does not.
Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"} {
ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri'
Expand Down Expand Up @@ -138,6 +144,16 @@ Describe "Get-JiraUser" -Tag 'Unit' {

$getResult | Should Not BeNullOrEmpty

Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user/search?*username=$testUsername*"}
Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"}
}

It "Gets information about a provided Jira exact user" {
$getResult = Get-JiraUser -UserName $testUsername -Exact

$getResult | Should Not BeNullOrEmpty

Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user?username=$testUsername"}
Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"}
}

Expand Down
30 changes: 27 additions & 3 deletions docs/en-US/commands/Get-JiraUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ Get-JiraUser [-Credential <PSCredential>] [<CommonParameters>]
### ByUserName

```powershell
Get-JiraUser [-UserName] <String[]> [-IncludeInactive] [[-MaxResults] <UInt32>] [[-Skip] <UInt64>] [-Credential <PSCredential>] [<CommonParameters>]
Get-JiraUser [-UserName] <String[]> [-IncludeInactive] [[-MaxResults] <UInt32>] [[-Skip] <UInt64>] [-Credential <PSCredential>] [-Exact] [<CommonParameters>]
```

### ByInputObject

```powershell
Get-JiraUser [-InputObject] <Object[]> [-IncludeInactive] [-Credential <PSCredential>] [<CommonParameters>]
Get-JiraUser [-InputObject] <Object[]> [-IncludeInactive] [-Credential <PSCredential>] [-Exact] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -45,7 +45,7 @@ This function returns information regarding a specified user from Jira.
Get-JiraUser -UserName user1
```

Returns information about the user user1
Returns information about all users with username like user1

### EXAMPLE 2

Expand All @@ -63,6 +63,14 @@ Get-JiraUser -Credential $cred

This example returns the JIRA user that is executing the command.

### EXAMPLE 4

```powershell
Get-JiraUser -UserName user1 -Exact
```

Returns information about user user1

## PARAMETERS

### -UserName
Expand Down Expand Up @@ -97,6 +105,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Exact
Limits the search to users where the username is exactly the term searched for.
```yaml
Type: Switch
Parameter Sets: ByUserName, ByInputObject
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -IncludeInactive
Include inactive users in the search
Expand Down

0 comments on commit 34ec197

Please sign in to comment.