Skip to content

Commit 8b61fec

Browse files
authored
Merge pull request #145 from rulasg/Convertto-ItemTransformedValue
feat(Edit-ProjectItem): Allow using fields values on new values through tags
2 parents b689d12 + 9aa8e6a commit 8b61fec

11 files changed

Lines changed: 163 additions & 40 deletions

Test/private/MockCall_Project700.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function Get-Mock_Project_700 {
5353
id = $issue.id
5454
contentId = $issue.content.id
5555
title = $issue.content.title
56+
repositoryName = $issue.content.repository.name
5657
status = ($issue.fieldValues.nodes | Where-Object { $_.field.name -eq "Status" }).name
5758
fieldtext = ($issue.fieldValues.nodes | Where-Object { $_.field.id -eq $($fieldtext.id) }).text
5859
fieldsingleselect = @{
@@ -68,6 +69,7 @@ function Get-Mock_Project_700 {
6869
id = $pullRequest.id
6970
contentId = $pullRequest.content.id
7071
title = $pullRequest.content.title
72+
repositoryName = $pullRequest.content.repository.name
7173
status = ($pullRequest.fieldValues.nodes | Where-Object { $_.field.name -eq "Status" }).name
7274
fieldtext = ($pullRequest.fieldValues.nodes | Where-Object { $_.field.id -eq $($fieldtext.id) }).text
7375
fieldsingleselect = @{
@@ -119,7 +121,7 @@ function Get-Mock_Project_700 {
119121

120122
# All items except Drafts that do not have repository
121123
$project.searchInAnyField."rulasg-dev-1" = @{}
122-
$i = $content.data.organization.projectV2.items.nodes.content | Where-Object { $_.repository.nameWithOwner -like "$($project.owner)/rulasg-dev-1" }
124+
$i = $content.data.organization.projectV2.items.nodes.content | Where-Object { $_.repository.name -like "rulasg-dev-1" }
123125
$project.searchInAnyField."rulasg-dev-1".totalCount = $i.Count
124126
$project.searchInAnyField."rulasg-dev-1".Titles = $i.title
125127

Test/private/mocks/invoke-GitHubOrgProjectWithFields-octodemo-700.json

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
"url": "https://github.com/octodemo/rulasg-dev-1/issues/13",
3636
"state": "CLOSED",
3737
"repository": {
38-
"nameWithOwner": "octodemo/rulasg-dev-1"
38+
"name": "rulasg-dev-1",
39+
"owner": {
40+
"login": "octodemo"
41+
}
3942
}
4043
},
4144
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8pU",
@@ -208,7 +211,10 @@
208211
"url": "https://github.com/octodemo/rulasg-dev-1/issues/12",
209212
"state": "OPEN",
210213
"repository": {
211-
"nameWithOwner": "octodemo/rulasg-dev-1"
214+
"name": "rulasg-dev-1",
215+
"owner": {
216+
"login": "octodemo"
217+
}
212218
}
213219
},
214220
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8pY",
@@ -381,7 +387,10 @@
381387
"url": "https://github.com/octodemo/rulasg-dev-1/issues/11",
382388
"state": "OPEN",
383389
"repository": {
384-
"nameWithOwner": "octodemo/rulasg-dev-1"
390+
"name": "rulasg-dev-1",
391+
"owner": {
392+
"login": "octodemo"
393+
}
385394
}
386395
},
387396
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8pc",
@@ -554,7 +563,10 @@
554563
"url": "https://github.com/octodemo/rulasg-dev-1/issues/10",
555564
"state": "OPEN",
556565
"repository": {
557-
"nameWithOwner": "octodemo/rulasg-dev-1"
566+
"name": "rulasg-dev-1",
567+
"owner": {
568+
"login": "octodemo"
569+
}
558570
}
559571
},
560572
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8pg",
@@ -743,7 +755,10 @@
743755
"url": "https://github.com/octodemo/rulasg-dev-1/issues/9",
744756
"state": "CLOSED",
745757
"repository": {
746-
"nameWithOwner": "octodemo/rulasg-dev-1"
758+
"name": "rulasg-dev-1",
759+
"owner": {
760+
"login": "octodemo"
761+
}
747762
}
748763
},
749764
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8pk",
@@ -932,7 +947,10 @@
932947
"url": "https://github.com/octodemo/rulasg-dev-1/issues/8",
933948
"state": "OPEN",
934949
"repository": {
935-
"nameWithOwner": "octodemo/rulasg-dev-1"
950+
"name": "rulasg-dev-1",
951+
"owner": {
952+
"login": "octodemo"
953+
}
936954
}
937955
},
938956
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8po",
@@ -1124,7 +1142,10 @@
11241142
"url": "https://github.com/octodemo/rulasg-dev-1/issues/7",
11251143
"state": "OPEN",
11261144
"repository": {
1127-
"nameWithOwner": "octodemo/rulasg-dev-1"
1145+
"name": "rulasg-dev-1",
1146+
"owner": {
1147+
"login": "octodemo"
1148+
}
11281149
}
11291150
},
11301151
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8ps",
@@ -1303,7 +1324,10 @@
13031324
"url": "https://github.com/octodemo/rulasg-dev-1/issues/6",
13041325
"state": "OPEN",
13051326
"repository": {
1306-
"nameWithOwner": "octodemo/rulasg-dev-1"
1327+
"name": "rulasg-dev-1",
1328+
"owner": {
1329+
"login": "octodemo"
1330+
}
13071331
}
13081332
},
13091333
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8pw",
@@ -1482,7 +1506,10 @@
14821506
"url": "https://github.com/octodemo/rulasg-dev-1/issues/5",
14831507
"state": "OPEN",
14841508
"repository": {
1485-
"nameWithOwner": "octodemo/rulasg-dev-1"
1509+
"name": "rulasg-dev-1",
1510+
"owner": {
1511+
"login": "octodemo"
1512+
}
14861513
}
14871514
},
14881515
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8p0",
@@ -1661,7 +1688,10 @@
16611688
"url": "https://github.com/octodemo/rulasg-dev-1/issues/4",
16621689
"state": "OPEN",
16631690
"repository": {
1664-
"nameWithOwner": "octodemo/rulasg-dev-1"
1691+
"name": "rulasg-dev-1",
1692+
"owner": {
1693+
"login": "octodemo"
1694+
}
16651695
}
16661696
},
16671697
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8p8",
@@ -1840,7 +1870,10 @@
18401870
"url": "https://github.com/octodemo/rulasg-dev-1/pull/1",
18411871
"state": "OPEN",
18421872
"repository": {
1843-
"nameWithOwner": "octodemo/rulasg-dev-1"
1873+
"name": "rulasg-dev-1",
1874+
"owner": {
1875+
"login": "octodemo"
1876+
}
18441877
}
18451878
},
18461879
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8qA",
@@ -2016,7 +2049,10 @@
20162049
"url": "https://github.com/octodemo/rulasg-dev-1/pull/3",
20172050
"state": "OPEN",
20182051
"repository": {
2019-
"nameWithOwner": "octodemo/rulasg-dev-1"
2052+
"name": "rulasg-dev-1",
2053+
"owner": {
2054+
"login": "octodemo"
2055+
}
20202056
}
20212057
},
20222058
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8qE",
@@ -2168,7 +2204,10 @@
21682204
"url": "https://github.com/octodemo/rulasg-dev-1/issues/2",
21692205
"state": "OPEN",
21702206
"repository": {
2171-
"nameWithOwner": "octodemo/rulasg-dev-1"
2207+
"name": "rulasg-dev-1",
2208+
"owner": {
2209+
"login": "octodemo"
2210+
}
21722211
}
21732212
},
21742213
"id": "PVTI_lADOAlIw4c4BCe3Vzgec8qI",
@@ -2816,7 +2855,10 @@
28162855
"url": "https://github.com/octodemo/rulasg-dev-1/issues/14",
28172856
"state": "CLOSED",
28182857
"repository": {
2819-
"nameWithOwner": "octodemo/rulasg-dev-1"
2858+
"name": "rulasg-dev-1",
2859+
"owner": {
2860+
"login": "octodemo"
2861+
}
28202862
}
28212863
},
28222864
"id": "PVTI_lADOAlIw4c4BCe3VzgedAUw",
@@ -2989,7 +3031,10 @@
29893031
"url": "https://github.com/octodemo/rulasg-dev-1/issues/15",
29903032
"state": "OPEN",
29913033
"repository": {
2992-
"nameWithOwner": "octodemo/rulasg-dev-1"
3034+
"name": "rulasg-dev-1",
3035+
"owner": {
3036+
"login": "octodemo"
3037+
}
29933038
}
29943039
},
29953040
"id": "PVTI_lADOAlIw4c4BCe3VzgedAVU",
@@ -3162,7 +3207,10 @@
31623207
"url": "https://github.com/octodemo/rulasg-dev-1/issues/16",
31633208
"state": "CLOSED",
31643209
"repository": {
3165-
"nameWithOwner": "octodemo/rulasg-dev-1"
3210+
"name": "rulasg-dev-1",
3211+
"owner": {
3212+
"login": "octodemo"
3213+
}
31663214
}
31673215
},
31683216
"id": "PVTI_lADOAlIw4c4BCe3VzgedAWU",
@@ -3335,7 +3383,10 @@
33353383
"url": "https://github.com/octodemo/rulasg-dev-1/issues/17",
33363384
"state": "OPEN",
33373385
"repository": {
3338-
"nameWithOwner": "octodemo/rulasg-dev-1"
3386+
"name": "rulasg-dev-1",
3387+
"owner": {
3388+
"login": "octodemo"
3389+
}
33393390
}
33403391
},
33413392
"id": "PVTI_lADOAlIw4c4BCe3VzgedAWs",
@@ -3508,7 +3559,10 @@
35083559
"url": "https://github.com/octodemo/rulasg-dev-1/issues/18",
35093560
"state": "OPEN",
35103561
"repository": {
3511-
"nameWithOwner": "octodemo/rulasg-dev-1"
3562+
"name": "rulasg-dev-1",
3563+
"owner": {
3564+
"login": "octodemo"
3565+
}
35123566
}
35133567
},
35143568
"id": "PVTI_lADOAlIw4c4BCe3VzgedAwI",
@@ -3577,7 +3631,10 @@
35773631
"url": "https://github.com/octodemo/rulasg-dev-1/pull/25",
35783632
"state": "OPEN",
35793633
"repository": {
3580-
"nameWithOwner": "octodemo/rulasg-dev-1"
3634+
"name": "rulasg-dev-1",
3635+
"owner": {
3636+
"login": "octodemo"
3637+
}
35813638
}
35823639
},
35833640
"id": "PVTI_lADOAlIw4c4BCe3VzgeioBY",
@@ -3859,7 +3916,10 @@
38593916
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26",
38603917
"state": "OPEN",
38613918
"repository": {
3862-
"nameWithOwner": "octodemo/rulasg-dev-1"
3919+
"name": "rulasg-dev-1",
3920+
"owner": {
3921+
"login": "octodemo"
3922+
}
38633923
}
38643924
},
38653925
"id": "PVTI_lADOAlIw4c4BCe3Vzgeio4o",

Test/public/project_item.test.ps1

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function Test_EditProjetItems_SUCCESS{
5555
Mock_DatabaseRoot
5656

5757
$Owner = "octodemo" ; $ProjectNumber = 700 ;
58-
#$itemsCount = 12 ; $fieldsCount = 18
59-
# MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2.json'
6058
MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'invoke-GitHubOrgProjectWithFields-octodemo-700.json'
6159

6260
$before = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber
@@ -100,6 +98,31 @@ function Test_EditProjetItems_SUCCESS{
10098
Assert-AreEqual -Expected $fieldTitleValue -Presented $result.$itemId.$title_fieldid.Value
10199
}
102100

101+
function Test_EditProjetItems_SUCCESS_Transformations{
102+
Reset-InvokeCommandMock
103+
Mock_DatabaseRoot
104+
105+
$p = Get-Mock_Project_700 ; $Owner = $p.owner ; $ProjectNumber = $p.number
106+
MockCall_GetProject -MockProject $p -Cache
107+
108+
$i = $p.issue
109+
$fieldTitle = "title"
110+
111+
$itemId = $i.id
112+
$actualTitle = $i.title
113+
$actualRepoName = $i.repositoryName
114+
115+
$newValue ="(*) [{{RepositoryName}}] {{Title}}"
116+
$finalValue = $newValue -replace '{{RepositoryName}}', $actualRepoName -replace '{{Title}}', $actualTitle
117+
118+
# Act
119+
Edit-ProjectItem -Owner $owner -ProjectNumber $projectNumber $i.id $fieldTitle $newValue
120+
121+
$staged = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
122+
Assert-AreEqual -Expected $finalValue -Presented $staged.$itemId.$fieldTitle.Value
123+
124+
}
125+
103126
function Test_EditProjectItems_SameValue{
104127
Reset-InvokeCommandMock
105128
Mock_DatabaseRoot

private/item/convertItemToHash.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function Convert-NodeItemToHash {
2424
$item.number = $NodeItem.content.number
2525
$item.state = $NodeItem.content.state
2626
$item.urlContent = $NodeItem.content.url
27+
$item.RepositoryName = $NodeItem.content.repository.name
28+
$item.RepositoryOwner = $NodeItem.content.repository.owner.login
2729
$item.createdAt = GetDateTime -DateTimeString $NodeItem.content.createdAt
2830
$item.updatedAt = GetDateTime -DateTimeString $NodeItem.content.updatedAt
2931

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Convertto-ItemTransformedValue{
2+
param(
3+
[Parameter(Mandatory=$true)][hashtable]$Item,
4+
[Parameter()][string]$Value
5+
)
6+
7+
# Check if the Value contains any {{tag}} patterns
8+
if ($Value -match '\{\{[^}]+\}\}') {
9+
10+
# Find all {{tag}} patterns in the value
11+
$m = [regex]::Matches($Value, '\{\{([^}]+)\}\}')
12+
13+
$transformedValue = $Value
14+
15+
foreach ($match in $m) {
16+
$fullTag = $match.Value # The full {{tag}} including braces
17+
$fieldName = $match.Groups[1].Value # Just the tag name without braces
18+
19+
# Check if the item has this field
20+
if (! [string]::IsNullOrEmpty($Item.$fieldName)) {
21+
$fieldValue = $Item.$fieldName
22+
# Replace the {{tag}} with the actual field value
23+
$transformedValue = $transformedValue -replace [regex]::Escape($fullTag), $fieldValue
24+
}
25+
else {
26+
# Field not found - could either leave as is or replace with empty string
27+
# Leaving as is for now to make it obvious when a field doesn't exist
28+
Write-Warning "Field '$fieldName' not found in item. Tag '$fullTag' will remain unchanged."
29+
}
30+
}
31+
32+
return $transformedValue
33+
}
34+
35+
# No {{tag}} patterns found, return original value
36+
return $Value
37+
}

public/graphql/addItemToProject.mutant

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ id, type,
55
project{ id, url},
66
content{__typename,
77
... on DraftIssue {id,body,title,updatedAt,createdAt},
8-
... on PullRequest{id,body,title,updatedAt,createdAt,number,url,state,repository{nameWithOwner}},
9-
... on Issue{id,body,title,updatedAt,createdAt,number,url,state,repository{nameWithOwner}
8+
... on PullRequest{id,body,title,updatedAt,createdAt,number,url,state,repository{name,owner{login}}},
9+
... on Issue{id,body,title,updatedAt,createdAt,number,url,state,repository{name,owner{login}}
1010
},
1111
}
1212
fieldValues(first: 100){

public/graphql/clearItemValues.mutant

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
mutation ClearItemValues($input:ClearProjectV2ItemFieldValueInput!){clearProjectV2ItemFieldValue(input:$input){projectV2Item{content{__typename,... on DraftIssue{id,body,title
2-
},... on PullRequest{body,title,number,url,repository{nameWithOwner
3-
}
4-
},... on Issue{body,title,number,url,repository{nameWithOwner
5-
}
2+
},... on PullRequest{body,title,number,url,repository{name,owner{login}}
3+
},... on Issue{body,title,number,url,repository{name,owner{login}}
64
}
75
},id,fieldValues(first: 100){nodes{__typename,... on ProjectV2ItemFieldDateValue{date,field{__typename,... on ProjectV2Field{id,name,dataType
86
},... on ProjectV2IterationField{id,name,dataType

public/graphql/getProjectV2Item.query

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ query($itemId: ID!) {
55
project{ id, url},
66
content{__typename,
77
... on DraftIssue {id,body,title,updatedAt,createdAt},
8-
... on PullRequest{id,body,title,updatedAt,createdAt,number,url,state,repository{nameWithOwner}},
9-
... on Issue{id,body,title,updatedAt,createdAt,number,url,state,repository{nameWithOwner}
8+
... on PullRequest{id,body,title,updatedAt,createdAt,number,url,state,repository{name,owner{login}}},
9+
... on Issue{id,body,title,updatedAt,createdAt,number,url,state,repository{name,owner{login}}
1010
},
1111
}
1212
fieldValues(first: 100){

public/graphql/orgprojectwithfieldsAndItems.query

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ query OrgProjectWithFields($afterFields:String$afterItems:String$firstFields:Int
44
project{ id, number, title, url},
55
content{__typename
66
,... on DraftIssue {id,body,title,updatedAt,createdAt
7-
},... on PullRequest{id,body,title,updatedAt,createdAt,number,url,state,repository{nameWithOwner}
8-
},... on Issue{id,body,title,updatedAt,createdAt,number,url,state,repository{nameWithOwner}
7+
},... on PullRequest{id,body,title,updatedAt,createdAt,number,url,state,repository{name,owner{login}}
8+
},... on Issue{id,body,title,updatedAt,createdAt,number,url,state,repository{name,owner{login}}
99
}
1010
},id,fullDatabaseId,
1111
fieldValues(first: 100){nodes{__typename,... on ProjectV2ItemFieldDateValue{date,field{__typename,... on ProjectV2Field{id,name,dataType

0 commit comments

Comments
 (0)