Skip to content

Commit b689d12

Browse files
authored
Merge pull request #144 from rulasg/rulasg/issue141
Version 3.0 - New small features, fix bugs and refactor
2 parents 2d93ddf + 0e6272d commit b689d12

66 files changed

Lines changed: 8860 additions & 1036 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode/**
2-
.DS_Store
2+
.DS_Store
3+
*.patch
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# CALL PRIVATE FUNCTIONS
2+
#
3+
# This file enables tests to invoke private (non-exported) functions
4+
# defined inside the main module by evaluating a provided scriptblock
5+
# in the module context.
6+
#
7+
# It relies on variables initialized by module.helper.ps1.
8+
# REQUIRED:
9+
# $MODULE_PATH - Full path to the module .psm1 file (or a file inside its folder)
10+
#
11+
# THIS INCLUDE REQUIRES module.helper.ps1
12+
if(-not $MODULE_PATH){ throw "Missing MODULE_PATH variable initialization. Check for module.helper.ps1 file." }
13+
14+
function Invoke-PrivateContext {
15+
param (
16+
[Parameter(Mandatory, Position = 0)]
17+
[scriptblock]$ScriptBlock
18+
)
19+
20+
$modulePath = $MODULE_PATH | Split-Path -Parent
21+
$module = Import-Module -Name $modulePath -PassThru
22+
23+
if ($null -eq $module) {
24+
throw "Failed to import the main module."
25+
}
26+
27+
& $module $ScriptBlock
28+
} Export-ModuleMember -Function Invoke-PrivateContext
29+

Test/private/MockCall_GitHubOrgProjectWithFields.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
function MockCall_GitHubOrgProjectWithFields{
2+
function MockCall_GitHubOrgProjectWithFields {
33
Param(
44
[string]$Owner,
55
[string]$ProjectNumber,
@@ -23,7 +23,7 @@ function MockCall_GitHubOrgProjectWithFields{
2323
MockCallJson -Command $cmd -Filename $FileName
2424
}
2525

26-
function MockCall_GitHubOrgProjectWithFields_Null{
26+
function MockCall_GitHubOrgProjectWithFields_Null {
2727
Param(
2828
[string]$Owner,
2929
[string]$ProjectNumber
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function MockCall_GitHubUpdateItemValues {
2+
[CmdletBinding()]
3+
param(
4+
[parameter(Mandatory)][string]$ProjectId,
5+
[parameter(Mandatory)][string]$ItemId,
6+
[parameter(Mandatory)][string]$FieldId,
7+
[parameter(Mandatory)][string]$Value,
8+
[parameter(Mandatory)][string]$Type,
9+
[parameter()][switch]$Async
10+
)
11+
12+
$resultFile = "invoke-GitHubUpdateItemValue-$ItemId-$FieldId.json"
13+
14+
$command = 'Invoke-GitHubUpdateItemValues -ProjectId {ProjectId} -ItemId {ItemId} -FieldId {FieldId} -Value "{Value}" -Type text'
15+
16+
if ($Async) {
17+
$modulePath = $MODULE_PATH | split-path -Parent
18+
$moduleTestPath = Join-Path -Path $modulePath -ChildPath 'Test'
19+
20+
$command = 'Import-Module {modulepath} ; ' + $command
21+
$command = $command -replace '{modulepath}', $modulePath
22+
}
23+
24+
$command = $command -replace '{ProjectId}', $ProjectId
25+
$command = $command -replace '{ItemId}', $ItemId
26+
$command = $command -replace '{FieldId}', $FieldId
27+
$command = $command -replace '{Value}', $Value
28+
29+
Set-InvokeCommandMock -Command "Import-Module $moduleTestPath ; Get-MockFileContentJson -filename $($ResultFile)" -Alias $command
30+
31+
}
32+
33+
function MockCall_GetItem{
34+
[cmdletbinding()]
35+
param(
36+
[parameter(Mandatory)][string]$ItemId
37+
)
38+
39+
$command = "Invoke-GetItem -ItemId $ItemId"
40+
$resultFile = "invoke-getitem-$ItemId.json"
41+
42+
Set-InvokeCommandMock -Command "Get-MockFileContentJson -filename $($ResultFile)" -Alias $command
43+
}

Test/private/MockCall_Project.ps1

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
function Get-Mock_Project_625 {
2+
3+
$project = @{}
4+
5+
<#
6+
Reset-InvokeCommandMock
7+
Enable-InvokeCommandAliasModule
8+
$cmd = 'Invoke-GitHubOrgProjectWithFields -Owner octodemo -ProjectNumber 625 -afterFields "" -afterItems ""'
9+
save-invokeAsMockFile $cmd "invoke-GitHubOrgProjectWithFields-octodemo-625.json"
10+
#>
11+
12+
$name = "invoke-GitHubOrgProjectWithFields-octodemo-625"
13+
$project.projectFile = $name + ".json"
14+
$project.projectFile_skipitems = $name + "-skipitems.json"
15+
16+
$content = Get-MockFileContentJson -FileName $project.projectFile
17+
$p = $content.data.organization.projectV2
18+
19+
# Project info
20+
$project.id = $p.id
21+
$project.owner = $p.owner.login
22+
$project.number = $p.number
23+
$project.url = $p.url
24+
25+
# Add Items to mock
26+
Add-ItemsToMock -project $project
27+
28+
#############################
29+
# Update Status on DueDate #
30+
#############################
31+
<#
32+
$prj = Get-Project -Owner octodemo -ProjectNumber 625
33+
$prj.items.values | Select id,title,DueDate,Status,Comment | Sort-Object title | ft
34+
35+
id Title DueDate Status Comment
36+
-- ----- ------- ------ -------
37+
PVTI_lADOAlIw4c4A0Lf4zgYNTyM draft0 2025-03-01 Planned Change AR Past
38+
PVTI_lADOAlIw4c4A0Lf4zgYVsJc draft1 9999-12-12 Planned Ignore as Future
39+
PVTI_lADOAlIw4c4A0Lf4zgfNuvM draft2 9999-12-12 ActionRequired Change to P as AR+Future
40+
PVTI_lADOAlIw4c4A0Lf4zgfNum4 draft3 2025-03-03 ActionRequired Ignore as Past and AR
41+
PVTI_lADOAlIw4c4A0Lf4zgYNTxI draft4 2025-03-09 In Progress (ignore not P) | (Changed AR as Past)
42+
PVTI_lADOAlIw4c4A0Lf4zgfN77A draft5 2025-03-15 Todo (ignore not P) | (Change AR as Today)
43+
PVTI_lADOAlIw4c4A0Lf4zgfN-44 draft6 2025-03-15 Planned Change to AR as P and Today
44+
PVTI_lADOAlIw4c4A0Lf4zgYNTc0 draft7 2025-03-05 Done Ignore as Done | (Change AR as Past)
45+
PVTI_lADOAlIw4c4A0Lf4zgYNTwo draft8 9999-12-12 In Progress Ignore future
46+
PVTI_lADOAlIw4c4A0Lf4zgfOmpo draft9 9999-12-12 Todo (Ignore not P)
47+
PVTI_lADOAlIw4c4A0Lf4zgfJYv4 Issue for development skip no DueDate
48+
PVTI_lADOAlIw4c4A0Lf4zgfJYvk PullRequest for development skip no DueDate
49+
50+
#>
51+
$statusFieldName = "Status"
52+
$dateFieldName = "DueDate"
53+
$statusAction = "ActionRequired"
54+
$statusPlanned = "Planned"
55+
56+
$sf = ($content.data.organization.projectV2.fields.nodes | Where-Object { $_.name -eq $statusFieldName })
57+
$df = ($content.data.organization.projectV2.fields.nodes | Where-Object { $_.name -eq $dateFieldName })
58+
$project.updateStatusOnDueDate = @{
59+
statusAction = $statusAction
60+
statusPlanned = $statusPlanned
61+
statusDoneOther = "Todo"
62+
fields = @{ status = $sf ; dueDate = $df }
63+
staged = @{
64+
"PVTI_lADOAlIw4c4A0Lf4zgYNTyM" = @{ $($sf.id) = $statusAction } # draft0
65+
"PVTI_lADOAlIw4c4A0Lf4zgfN-44" = @{ $($sf.id) = $statusAction } # draft5
66+
"PVTI_lADOAlIw4c4A0Lf4zgfNuvM" = @{ $($sf.id) = $statusPlanned } # draft2
67+
}
68+
anyStatus = @{
69+
"PVTI_lADOAlIw4c4A0Lf4zgYNTxI" = @{ $($sf.id) = $statusAction } # draft4
70+
"PVTI_lADOAlIw4c4A0Lf4zgfN77A" = @{ $($sf.id) = $statusAction } # draft9
71+
72+
}
73+
includeDone = @{
74+
"PVTI_lADOAlIw4c4A0Lf4zgYNTc0" = @{ $($df.id) = "" } # draft8
75+
76+
}
77+
includeDoneOther = @{
78+
"PVTI_lADOAlIw4c4A0Lf4zgfN77A" = @{ $($df.id) = "" } # draft5
79+
"PVTI_lADOAlIw4c4A0Lf4zgfOmpo" = @{ $($df.id) = "" } # draft9
80+
}
81+
anyStatus_and_includeDoneOther = @{
82+
"PVTI_lADOAlIw4c4A0Lf4zgYNTxI" = @{ $($sf.id) = $statusAction } # draft4
83+
"PVTI_lADOAlIw4c4A0Lf4zgfN77A" = @{ $($df.id) = "" } # draft5
84+
"PVTI_lADOAlIw4c4A0Lf4zgfOmpo" = @{ $($df.id) = "" } # draft9
85+
}
86+
}
87+
88+
#############################
89+
# Update With Integration #
90+
#############################
91+
92+
$project.updateWithIntegration = @{
93+
fieldSlug = "sf_"
94+
integrationField = "sfUrl"
95+
fields = @("sf_Int2","sf_Text1")
96+
97+
integrationCommand = "Get-SfAccount"
98+
99+
mockdata1 = @{
100+
command = 'Get-SfAccount "https://some.com/1234/viuew"'
101+
data = @{
102+
"Text1" = "value11"
103+
"Text2" = "value12"
104+
"Number1" = 11
105+
"Int2" = 111
106+
}
107+
}
108+
109+
mockdata2 = @{
110+
command = 'Get-SfAccount "https://some.com/4321/viuew"'
111+
data = @{
112+
"Text1" = "value21"
113+
"Text2" = "value22"
114+
"Number1" = 22
115+
"Int2" = 222
116+
}
117+
}
118+
119+
staged =@{
120+
PVTI_lADOAlIw4c4A0Lf4zgfJYv4 = @{
121+
PVTF_lADOAlIw4c4A0Lf4zg15NKg = 222
122+
PVTF_lADOAlIw4c4A0Lf4zg15NMg = "value21"
123+
}
124+
PVTI_lADOAlIw4c4A0Lf4zgfJYvk = @{
125+
PVTF_lADOAlIw4c4A0Lf4zg15NKg = 111
126+
PVTF_lADOAlIw4c4A0Lf4zg15NMg = "value11"
127+
}
128+
129+
}
130+
}
131+
132+
#############################
133+
# Update With Injection #
134+
#############################
135+
136+
$project.updateWithInjection = @{
137+
item1 = @{
138+
id = "PVTI_lADOAlIw4c4A0Lf4zgYNTxI"
139+
fieldName = "sf_Text1"
140+
}
141+
item2 = @{
142+
id = "PVTI_lADOAlIw4c4A0Lf4zgYNTc0"
143+
fieldName = "Text1"
144+
}
145+
field1 = @{
146+
id = "PVTF_lADOAlIw4c4A0Lf4zg15NMg"
147+
name = "sf_Text1"
148+
}
149+
field2 = @{
150+
id = "PVTF_lADOAlIw4c4A0Lf4zgp6aFk"
151+
name = "Text1"
152+
}
153+
}
154+
155+
156+
157+
return $project
158+
159+
}
160+
161+
162+
function Get-Mock_Project_626 {
163+
164+
$project = @{}
165+
166+
$project.projectFile = "invoke-GitHubOrgProjectWithFields-octodemo-626.json"
167+
$project.projectFile_skipitems = "invoke-GitHubOrgProjectWithFields-octodemo-626-skipitems.json"
168+
169+
$content = Get-MockFileContentJson -FileName $project.projectFile
170+
$p = $content.data.organization.projectV2
171+
172+
# Project info
173+
$project.id = $p.id
174+
$project.owner = $p.owner.login
175+
$project.number = $p.number
176+
$project.url = $p.url
177+
178+
# Add Items to mock
179+
Add-ItemsToMock -project $project
180+
181+
# Sync with 625
182+
183+
$project.syncBtwPrj_625 = @{}
184+
$project.syncBtwPrj_625.staged = @{
185+
PVTI_lADOAlIw4c4A0QAozgfJYqo = @{
186+
PVTF_lADOAlIw4c4A0QAozgqofEM = 33
187+
PVTF_lADOAlIw4c4A0QAozgqoeOo = "Issue Text1 Value"
188+
}
189+
PVTI_lADOAlIw4c4A0QAozgfJYqk = @{
190+
PVTF_lADOAlIw4c4A0QAozgqofEM = 11
191+
PVTF_lADOAlIw4c4A0QAozgqoeOo = "PR Text1 Value"
192+
}
193+
}
194+
195+
196+
return $project
197+
}
198+
199+
function MockCall_GetProject {
200+
[CmdletBinding()]
201+
param(
202+
[parameter(Position = 0)][object]$MockProject,
203+
[parameter()][switch]$SkipItems,
204+
[parameter()][switch]$Cache
205+
)
206+
207+
$p = $MockProject ; $owner = $p.owner ; $projectNumber = $p.number
208+
209+
if ( $SkipItems ) {
210+
$filename = $p.projectFile_skipitems
211+
}
212+
else {
213+
$filename = $p.projectFile
214+
}
215+
216+
MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName $filename -SkipItems:$SkipItems
217+
218+
if ($Cache) {
219+
$null = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber -SkipItems:$SkipItems
220+
}
221+
}
222+
223+
function Add-ItemsToMock {
224+
[CmdletBinding()]
225+
param(
226+
[parameter(Mandatory, Position = 0)][object] $project
227+
)
228+
229+
# Items
230+
$project.items = @{}
231+
$project.items.totalCount = $pActual.items.totalcount
232+
$project.items.doneCount = 6 # too complicated to read from structure
233+
234+
# Issues to find
235+
$project.issueToFind = @{}
236+
$project.issueToFind.Ids = ($pActual.items.nodes | Where-Object { $_.content.title -eq "Issue to find" }).Id
237+
238+
# Issue for developer
239+
$issue = $pActual.items.nodes | Where-Object { $_.content.title -eq "Issue for development" }
240+
$project.issue = @{
241+
id = $issue.id
242+
contentId = $issue.content.id
243+
title = $issue.content.title
244+
status = ($issue.fieldValues.nodes | Where-Object { $_.field.name -eq "Status" }).name
245+
fieldtext = ($issue.fieldValues.nodes | Where-Object { $_.field.id -eq $($fieldtext.id) }).text
246+
}
247+
248+
# PullRequest for developer
249+
$pullRequest = $pActual.items.nodes | Where-Object { $_.content.title -eq "PullRequest for development" }
250+
$project.pullrequest = @{
251+
id = $pullRequest.id
252+
contentId = $pullRequest.content.id
253+
title = $pullRequest.content.title
254+
status = ($pullRequest.fieldValues.nodes | Where-Object { $_.field.name -eq "Status" }).name
255+
fieldtext = ($pullRequest.fieldValues.nodes | Where-Object { $_.field.id -eq $($fieldtext.id) }).text
256+
}
257+
258+
# DraftIssue for developer
259+
$draftIssue = $pActual.items.nodes | Where-Object { $_.content.title -eq "DraftIssue for development" }
260+
$project.draftissue = @{
261+
id = $draftIssue.id
262+
contentId = $draftIssue.content.id
263+
title = $draftIssue.content.title
264+
status = ($draftIssue.fieldValues.nodes | Where-Object { $_.field.name -eq "Status" }).name
265+
fieldtext = ($draftIssue.fieldValues.nodes | Where-Object { $_.field.id -eq $($fieldtext.id) }).text
266+
267+
}
268+
}

0 commit comments

Comments
 (0)