Skip to content

Commit 4a64a1d

Browse files
authored
Createmeta update (#488)
* Update Get-JiraIssueCreateMetadata.ps1 https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html * Update ConvertTo-JiraCreateMetaField.ps1 https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html * Update Get-JiraIssueCreateMetadata.ps1 https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html * Update ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 Altered test data to match what is returned by new createmeta call.
1 parent 4f56b99 commit 4a64a1d

File tree

3 files changed

+84
-121
lines changed

3 files changed

+84
-121
lines changed

JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,41 @@ function ConvertTo-JiraCreateMetaField {
77
)
88

99
process {
10-
foreach ($i in $InputObject) {
10+
foreach ($i in $InputObject.values) {
1111
Write-Debug "[$($MyInvocation.MyCommand.Name)] Converting `$InputObject to custom object"
1212

13-
$fields = $i.projects.issuetypes.fields
14-
$fieldNames = (Get-Member -InputObject $fields -MemberType '*Property').Name
15-
foreach ($f in $fieldNames) {
16-
$item = $fields.$f
17-
18-
$props = @{
19-
'Id' = $f
20-
'Name' = $item.name
21-
'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue)
22-
'Required' = [System.Convert]::ToBoolean($item.required)
23-
'Schema' = $item.schema
24-
'Operations' = $item.operations
25-
}
13+
$item = $i
2614

27-
if ($item.allowedValues) {
28-
$props.AllowedValues = $item.allowedValues
29-
}
15+
$props = @{
16+
'Id' = $item.fieldId
17+
'Name' = $item.name
18+
'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue)
19+
'Required' = [System.Convert]::ToBoolean($item.required)
20+
'Schema' = $item.schema
21+
'Operations' = $item.operations
22+
}
3023

31-
if ($item.autoCompleteUrl) {
32-
$props.AutoCompleteUrl = $item.autoCompleteUrl
33-
}
24+
if ($item.allowedValues) {
25+
$props.AllowedValues = $item.allowedValues
26+
}
3427

35-
foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) {
36-
if ($null -eq $props.$extraProperty) {
37-
$props.$extraProperty = $item.$extraProperty
38-
}
39-
}
28+
if ($item.autoCompleteUrl) {
29+
$props.AutoCompleteUrl = $item.autoCompleteUrl
30+
}
4031

41-
$result = New-Object -TypeName PSObject -Property $props
42-
$result.PSObject.TypeNames.Insert(0, 'JiraPS.CreateMetaField')
43-
$result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value {
44-
Write-Output "$($this.Name)"
32+
foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) {
33+
if ($null -eq $props.$extraProperty) {
34+
$props.$extraProperty = $item.$extraProperty
4535
}
36+
}
4637

47-
Write-Output $result
38+
$result = New-Object -TypeName PSObject -Property $props
39+
$result.PSObject.TypeNames.Insert(0, 'JiraPS.CreateMetaField')
40+
$result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value {
41+
Write-Output "$($this.Name)"
4842
}
43+
44+
Write-Output $result
4945
}
5046
}
5147
}

JiraPS/Public/Get-JiraIssueCreateMetadata.ps1

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Get-JiraIssueCreateMetadata {
2222

2323
$server = Get-JiraConfigServer -ErrorAction Stop
2424

25-
$resourceURi = "$server/rest/api/2/issue/createmeta?projectIds={0}&issuetypeIds={1}&expand=projects.issuetypes.fields"
25+
$resourceURi = "$server/rest/api/2/issue/createmeta/{0}/issuetypes/{1}"
2626
}
2727

2828
process {
@@ -47,40 +47,16 @@ function Get-JiraIssueCreateMetadata {
4747
Method = "GET"
4848
Credential = $Credential
4949
}
50+
5051
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
5152
$result = Invoke-JiraMethod @parameter
5253

5354
if ($result) {
54-
if (@($result.projects).Count -eq 0) {
55-
$errorMessage = @{
56-
Category = "InvalidResult"
57-
CategoryActivity = "Validating response"
58-
Message = "No projects were found for the given project [$Project]. Use Get-JiraProject for more details."
59-
}
60-
Write-Error @errorMessage
61-
}
62-
elseif (@($result.projects).Count -gt 1) {
63-
$errorMessage = @{
64-
Category = "InvalidResult"
65-
CategoryActivity = "Validating response"
66-
Message = "Multiple projects were found for the given project [$Project]. Refine the parameters to return only one project."
67-
}
68-
Write-Error @errorMessage
69-
}
70-
71-
if (@($result.projects.issuetypes) -eq 0) {
72-
$errorMessage = @{
73-
Category = "InvalidResult"
74-
CategoryActivity = "Validating response"
75-
Message = "No issue types were found for the given issue type [$IssueType]. Use Get-JiraIssueType for more details."
76-
}
77-
Write-Error @errorMessage
78-
}
79-
elseif (@($result.projects.issuetypes).Count -gt 1) {
55+
if (@($result.values).Count -eq 0) {
8056
$errorMessage = @{
8157
Category = "InvalidResult"
8258
CategoryActivity = "Validating response"
83-
Message = "Multiple issue types were found for the given issue type [$IssueType]. Refine the parameters to return only one issue type."
59+
Message = "No values were found for the given project [$Project]. Use Get-JiraProject for more details."
8460
}
8561
Write-Error @errorMessage
8662
}

Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1

Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,71 +39,62 @@ Describe "ConvertTo-JiraCreateMetaField" -Tag 'Unit' {
3939

4040
$sampleJson = @'
4141
{
42-
"expand": "projects",
43-
"projects": [
42+
"values": [
4443
{
45-
"expand": "issuetypes",
46-
"issuetypes": [
44+
"required": true,
45+
"schema": {
46+
"type": "string",
47+
"system": "summary"
48+
},
49+
"name": "Summary",
50+
"fieldId": "summary",
51+
"hasDefaultValue": false,
52+
"operations": [
53+
"set"
54+
]
55+
},
56+
{
57+
"required": false,
58+
"schema": {
59+
"type": "priority",
60+
"system": "priority"
61+
},
62+
"name": "Priority",
63+
"fieldId": "priority",
64+
"hasDefaultValue": true,
65+
"operations": [
66+
"set"
67+
],
68+
"allowedValues": [
69+
{
70+
"self": "http://jiraserver.example.com/rest/api/2/priority/1",
71+
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/blocker.png",
72+
"name": "Block",
73+
"id": "1"
74+
},
75+
{
76+
"self": "http://jiraserver.example.com/rest/api/2/priority/2",
77+
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/critical.png",
78+
"name": "Critical",
79+
"id": "2"
80+
},
81+
{
82+
"self": "http://jiraserver.example.com/rest/api/2/priority/3",
83+
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/major.png",
84+
"name": "Major",
85+
"id": "3"
86+
},
87+
{
88+
"self": "http://jiraserver.example.com/rest/api/2/priority/4",
89+
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/minor.png",
90+
"name": "Minor",
91+
"id": "4"
92+
},
4793
{
48-
"expand": "fields",
49-
"fields": {
50-
"summary": {
51-
"required": true,
52-
"schema": {
53-
"type": "string",
54-
"system": "summary"
55-
},
56-
"name": "Summary",
57-
"hasDefaultValue": false,
58-
"operations": [
59-
"set"
60-
]
61-
},
62-
"priority": {
63-
"required": false,
64-
"schema": {
65-
"type": "priority",
66-
"system": "priority"
67-
},
68-
"name": "Priority",
69-
"hasDefaultValue": true,
70-
"operations": [
71-
"set"
72-
],
73-
"allowedValues": [
74-
{
75-
"self": "http://jiraserver.example.com/rest/api/2/priority/1",
76-
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/blocker.png",
77-
"name": "Block",
78-
"id": "1"
79-
},
80-
{
81-
"self": "http://jiraserver.example.com/rest/api/2/priority/2",
82-
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/critical.png",
83-
"name": "Critical",
84-
"id": "2"
85-
},
86-
{
87-
"self": "http://jiraserver.example.com/rest/api/2/priority/3",
88-
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/major.png",
89-
"name": "Major",
90-
"id": "3"
91-
},
92-
{
93-
"self": "http://jiraserver.example.com/rest/api/2/priority/4",
94-
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/minor.png",
95-
"name": "Minor",
96-
"id": "4"
97-
},
98-
{
99-
"self": "http://jiraserver.example.com/rest/api/2/priority/5",
100-
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/trivial.png",
101-
"name": "Trivial",
102-
"id": "5"
103-
}
104-
]
105-
}
106-
}
94+
"self": "http://jiraserver.example.com/rest/api/2/priority/5",
95+
"iconUrl": "http://jiraserver.example.com/images/icons/priorities/trivial.png",
96+
"name": "Trivial",
97+
"id": "5"
10798
}
10899
]
109100
}

0 commit comments

Comments
 (0)