Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,7 @@
"id": "I_kwDOPrRnkc7KkwSq",
"body": "Body of issue for development",
"title": "Issue for development",
"updatedAt": "2025-09-30T05:42:49Z",
"updatedAt": "2025-10-15T21:30:02Z",
"createdAt": "2025-09-09T14:01:17Z",
"number": 26,
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26",
Expand All @@ -4035,29 +4035,29 @@
"nodes": [
{
"createdAt": "2025-09-23T17:51:06Z",
"updatedAt": "2025-09-23T17:51:06Z",
"updatedAt": "2025-10-15T21:29:45Z",
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3324995787",
"body": "sample comment 1",
"body": "Sample comment 1",
"fullDatabaseId": "3324995787",
"author": {
"login": "rulasg"
}
},
{
"createdAt": "2025-09-24T08:29:13Z",
"updatedAt": "2025-09-24T08:29:13Z",
"updatedAt": "2025-10-15T21:29:55Z",
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3327194303",
"body": "commetn added",
"body": "Sample comment 2",
"fullDatabaseId": "3327194303",
"author": {
"login": "rulasg"
}
},
{
"createdAt": "2025-09-30T05:42:49Z",
"updatedAt": "2025-09-30T05:42:49Z",
"updatedAt": "2025-10-15T21:30:02Z",
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3350059109",
"body": "New comment",
"body": "Sample comment 3",
"fullDatabaseId": "3350059109",
"author": {
"login": "rulasg"
Expand Down
66 changes: 52 additions & 14 deletions Test/private/mocks/invoke-getitem-PVTI_lADOAlIw4c4BCe3Vzgeio4o.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,51 @@
"id": "I_kwDOPrRnkc7KkwSq",
"body": "Body of issue for development",
"title": "Issue for development",
"updatedAt": "2025-09-11T13:06:24Z",
"updatedAt": "2025-10-15T21:30:02Z",
"createdAt": "2025-09-09T14:01:17Z",
"number": 26,
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26",
"state": "OPEN",
"repository": {
"nameWithOwner": "octodemo/rulasg-dev-1"
"name": "rulasg-dev-1",
"owner": {
"login": "octodemo"
}
},
"comments": {
"totalCount": 3,
"nodes": [
{
"createdAt": "2025-09-23T17:51:06Z",
"updatedAt": "2025-10-15T21:29:45Z",
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3324995787",
"body": "Sample comment 1",
"fullDatabaseId": "3324995787",
"author": {
"login": "rulasg"
}
},
{
"createdAt": "2025-09-24T08:29:13Z",
"updatedAt": "2025-10-15T21:29:55Z",
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3327194303",
"body": "Sample comment 2",
"fullDatabaseId": "3327194303",
"author": {
"login": "rulasg"
}
},
{
"createdAt": "2025-09-30T05:42:49Z",
"updatedAt": "2025-10-15T21:30:02Z",
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3350059109",
"body": "Sample comment 3",
"fullDatabaseId": "3350059109",
"author": {
"login": "rulasg"
}
}
]
}
},
"fieldValues": {
Expand Down Expand Up @@ -94,6 +132,18 @@
"dataType": "NUMBER"
}
},
{
"__typename": "ProjectV2ItemFieldIterationValue",
"title": "field-iteration 3",
"startDate": "2025-10-05",
"duration": 14,
"field": {
"__typename": "ProjectV2IterationField",
"id": "PVTIF_lADOAlIw4c4BCe3Vzg0rhqQ",
"name": "field-iteration",
"dataType": "ITERATION"
}
},
{
"__typename": "ProjectV2ItemFieldTextValue",
"text": "text3",
Expand Down Expand Up @@ -127,18 +177,6 @@
}
]
}
},
{
"__typename": "ProjectV2ItemFieldIterationValue",
"title": "field-iteration 3",
"startDate": "2025-10-05",
"duration": 14,
"field": {
"__typename": "ProjectV2IterationField",
"id": "PVTIF_lADOAlIw4c4BCe3Vzg0rhqQ",
"name": "field-iteration",
"dataType": "ITERATION"
}
}
]
}
Expand Down
37 changes: 33 additions & 4 deletions Test/public/edit-sync-projectitem-comments.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,52 @@
$p = Get-Mock_Project_700 ; $owner = $p.owner ; $projectNumber = $p.number
$i = $p.issue

$comment = "New comment"
$comment = "New comment"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$comment2 = "Another comment2"

MockCall_GetProject -MockProject $p -skipItems
MockCall_GetItem $i.id

MockCall_GetProject -MockProject $p -SkipItems
MockCall_GetItem $i.id

MockCallJson -Command "Invoke-AddComment -SubjectId $($i.contentId) -Comment ""New comment""" -filename "invoke-addcomment-$($i.contentId).json"
MockCallJson -Command "Invoke-AddComment -SubjectId $($i.contentId) -Comment ""Another comment2""" -filename "invoke-addcomment-$($i.contentId).json"

# Check the status of comments
# $i = Get-projectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id


# Act the edit part
Edit-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id -FieldName "AddComment" -Value $comment

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Assert the Edit part
$staged = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
Assert-AreEqual -Expected $comment -Presented $staged.$($i.id).addcomment.Value

# Confirm that staged values are merged on GetItem
$item = Get-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id
Assert-AreEqual -Expected $comment -Presented $item.comments[-1].body
Assert-AreEqual -Expected $comment -Presented $item.commentLast.body

# Act the sync part
Sync-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber

$staged = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
Assert-Count -Expected 0 -Presented $staged.Count

# Assert comment is commited to database
$item = Get-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id
Assert-AreEqual -Expected $comment -Presented $item.comments[-1].body
Assert-AreEqual -Expected $comment -Presented $item.commentLast.body

# Act more comments on a item with already has comments
Edit-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id -FieldName "AddComment" -Value $comment2

$item = Get-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id

Sync-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
$staged = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
Assert-Count -Expected 0 -Presented $staged.Count
$item = Get-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id
Assert-AreEqual -Expected $comment2 -Presented $item.comments[-1].body
Assert-AreEqual -Expected $comment2 -Presented $item.commentLast.body
}
3 changes: 2 additions & 1 deletion Test/public/issues/Add-IssuePullRequestComment.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ function Test_AddComment_SUCCESS_Using_Cache{
$contentId = $i.contentId
$comment = "sample comment 1"

MockCall_GetProject_700
MockCall_GetProject -MockProject $p -SkipItems
MockCall_GetItem -ItemId $i.id

Set-ProjectHelperEnvironment -Owner $owner -ProjectNumber $projectNumber -DisplayFields @("Status","FieldText")

Expand Down
12 changes: 8 additions & 4 deletions Test/public/project_item.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
$itemFieldCommentValue = $projectFieldCommentValue + " updated"

# allow get project
MockCall_GetProject_700
MockCall_GetProject -MockProject $p -cache
MockCall_GetProject -MockProject $p -SkipItems

MockCall_GetItem -ItemId $itemId

# Even if id is in project we make a direct call when with Force
MockCallJson -Command "Invoke-GetItem -itemid $itemId" -FileName "invoke-getitem-$itemId-updated.json"
Expand Down Expand Up @@ -256,11 +259,12 @@
Reset-InvokeCommandMock
Mock_DatabaseRoot

MockCall_GetProject_700

$p = Get-Mock_Project_700; $Owner = "octodemo" ; $ProjectNumber = 700

$i = $p.issue

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
MockCall_GetProject -MockProject $p -SkipItems
MockCall_GetItem -ItemId $i.id

$id = $i.Id
$title = $i.title
$status = $i.status
Expand Down
59 changes: 59 additions & 0 deletions private/projectDatabase/project_database_Item.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@

# Check if is staged
if($database.Staged.$ItemId){


Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Update ret with all staged fields values
foreach($fieldKey in $database.Staged.$ItemId.keys){

$value = $database.Staged.$ItemId.$fieldKey.Value

if($fieldKey -eq "AddComment"){
Set-LastComment -Database $database -Item $ret -comment $value
continue
}

# Get fieldname
$fieldname = $database.Staged.$ItemId.$fieldKey.Field.name
# Make type conversions to string
$ret.$fieldname = $database.Staged.$ItemId.$fieldKey.Value
Expand All @@ -36,6 +47,29 @@
}
}

function Set-LastComment{

Check warning

Code scanning / PSScriptAnalyzer

Function 'Set-LastComment' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Set-LastComment' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
[OutputType([string])]
param(
[Parameter(Position = 0)][object[]]$Database,

Check warning

Code scanning / PSScriptAnalyzer

The parameter 'Database' has been declared but not used. Warning

The parameter 'Database' has been declared but not used.
[Parameter(ValueFromPipeline, Position = 1)][hashtable]$Item,

Check warning

Code scanning / PSScriptAnalyzer

Command accepts pipeline input but has not defined a process block. Warning

Command accepts pipeline input but has not defined a process block.
[Parameter()][string]$comment
)

$commentobj = @{
body = $comment
}

# init comments array if needed
if($null -eq $Item.comments){
$Item.comments = @()
}

# Update commentLast field
$Item.commentLast = $commentobj
$Item.comments += $commentobj
}

function Find-Item {
[CmdletBinding()]
param(
Expand Down Expand Up @@ -117,6 +151,11 @@

$item = $db | AddHashLink items | AddHashLink $ItemId

# Special case for comments
if($FieldName -eq "AddComment"){
Set-LastComment -Database $db -Item $item -comment $Value
}

$item.$FieldName = $Value
}

Expand Down Expand Up @@ -148,6 +187,26 @@
}
}

function Remove-ItemStaged{

Check warning

Code scanning / PSScriptAnalyzer

Function 'Remove-ItemStaged' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Remove-ItemStaged' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
param(
[Parameter(Position = 0)][object]$Database,
[Parameter(Position = 1)][string]$ItemId,
[Parameter(Position = 2)][string]$FieldId
)

$db = $Database

if ($db.Staged.$ItemId.$FieldId) {
$db.Staged.$ItemId.Remove($FieldId)
}

# If no more fields in item remove item
if ($db.Staged.$ItemId.Count -eq 0) {
$db.Staged.Remove($ItemId)
}
}

<#
.SYNOPSIS
Stage a change to the database
Expand Down
20 changes: 0 additions & 20 deletions private/projectDatabase/project_database_Sync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,4 @@ function Sync-Project{
}

return $db
}

function Remove-ItemStaged{
[CmdletBinding()]
param(
[Parameter(Position = 0)][object]$Database,
[Parameter(Position = 1)][string]$ItemId,
[Parameter(Position = 2)][string]$FieldId
)

$db = $Database

if ($db.Staged.$ItemId.$FieldId) {
$db.Staged.$ItemId.Remove($FieldId)
}

# If no more fields in item remove item
if ($db.Staged.$ItemId.Count -eq 0) {
$db.Staged.Remove($ItemId)
}
}
4 changes: 1 addition & 3 deletions public/items/project_item.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ function Get-ProjectItem {
($Owner, $ProjectNumber) = Get-OwnerAndProjectNumber -Owner $Owner -ProjectNumber $ProjectNumber
if ([string]::IsNullOrWhiteSpace($owner) -or [string]::IsNullOrWhiteSpace($ProjectNumber)) { "Owner and ProjectNumber are required" | Write-MyError; return $null }


# Get Item from Project database
$db = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber
$db = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber -SkipItems

if(! $db){ "Project not found for Owner [$Owner] and ProjectNumber [$ProjectNumber]" | Write-MyError; return $null}

Expand Down