Repository navigation
Add blocking relationships between project items #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rulasg
wants to merge
1
commit into
main
Choose a base branch
from
rulasg-project-item-blocked
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "data": { | ||
| "addBlockedBy": { | ||
| "issue": { "id": "I_kwDOPrRnkc7KkwSq" }, | ||
| "blockingIssue": { "id": "I_kwDOPrRnkc7KJAvo" } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "data": { | ||
| "addBlockedBy": { | ||
| "issue": { "id": "I_kwDOPrRnkc7KkwSq" }, | ||
| "blockingIssue": { "id": "I_kwDOPrRnkc7KJAku" } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| function Test_InvokeAddBlockedBy_SUCCESS { | ||
| # Arrange | ||
| Reset-InvokeCommandMock | ||
|
|
||
| # Act | ||
| $request = Invoke-PrivateContext { | ||
| function Invoke-GraphQL { | ||
| param($Query, $Variables) | ||
| return @{ Query = $Query; Variables = $Variables } | ||
| } | ||
|
|
||
| Invoke-AddBlockedBy -IssueId I_blocked -BlockingIssueId I_blocker | ||
| } -ModulePath (Get-Module ProjectHelper).Path | ||
|
|
||
| # Assert | ||
| Assert-AreEqual -Expected "I_blocked" -Presented $request.Variables.input.issueId | ||
| Assert-AreEqual -Expected "I_blocker" -Presented $request.Variables.input.blockingIssueId | ||
| Assert-IsTrue -Condition ($request.Query.Contains('addBlockedBy(input: $input)')) | ||
| Assert-IsTrue -Condition ($request.Query.Contains('AddBlockedByInput!')) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| function Test_AddProjectItemBlocked_SUCCESS_Pipeline { | ||
| # Arrange | ||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
| $p = Get-Mock_Project_700 | ||
| MockCall_GetProject $p -Cache | ||
| $item = $p.issue | ||
| $blocker = Get-ProjectItem -ItemId $p.subIssueToShow.id -Owner $p.owner -ProjectNumber $p.number | ||
| $secondBlocker = Get-ProjectItemByUrl -Url $p.subIssuesToAdd[0].url -Owner $p.owner -ProjectNumber $p.number -PassThru | ||
| MockCallJson -Command "Invoke-AddBlockedBy -IssueId $($item.contentId) -BlockingIssueId $($blocker.contentId)" -File "invoke-addBlockedBy-success.json" | ||
| MockCallJson -Command "Invoke-AddBlockedBy -IssueId $($item.contentId) -BlockingIssueId $($secondBlocker.contentId)" -File "invoke-addBlockedBy-second-blocker.json" | ||
|
|
||
| # Act | ||
| $result = @($blocker.id, $secondBlocker.id) | Add-ProjectItemBlocked -ItemId $item.id -Owner $p.owner -ProjectNumber $p.number | ||
|
|
||
| # Assert | ||
| Assert-Count -Expected 2 -Presented $result | ||
| Assert-IsTrue -Condition $result[0] | ||
| Assert-IsTrue -Condition $result[1] | ||
| } | ||
|
|
||
| function Test_AddProjectItemBlocked_NotFound { | ||
| # Arrange | ||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
| $p = Get-Mock_Project_700 | ||
| MockCall_GetProject $p -Cache | ||
| MockCallToNull -Command "Invoke-GetItem -ItemId missing" | ||
|
|
||
| # Act | ||
| $missingItem = Add-ProjectItemBlocked -ItemId missing -BlockingItemId $p.issue.id -Owner $p.owner -ProjectNumber $p.number -InformationVariable itemMessages | ||
| $missingBlocker = Add-ProjectItemBlocked -ItemId $p.issue.id -BlockingItemId missing -Owner $p.owner -ProjectNumber $p.number -InformationVariable blockerMessages | ||
|
|
||
| # Assert | ||
| Assert-IsNull -Object $missingItem | ||
| Assert-IsNull -Object $missingBlocker | ||
| Assert-IsTrue -Condition (($itemMessages.MessageData.Message -join "`n").Contains("ItemId [missing] not found on project")) | ||
| Assert-IsTrue -Condition (($blockerMessages.MessageData.Message -join "`n").Contains("BlockingItemId [missing] not found on project")) | ||
| } | ||
|
|
||
| function Test_AddProjectItemBlocked_InvalidInput { | ||
| # Arrange | ||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
| $p = Get-Mock_Project_700 | ||
| MockCall_GetProject $p -Cache | ||
| $params = @{ Owner = $p.owner; ProjectNumber = $p.number } | ||
|
|
||
| # Act | ||
| $draft = Add-ProjectItemBlocked -ItemId $p.draftissue.id -BlockingItemId $p.issue.id @params -InformationVariable draftMessages | ||
| $pullRequest = Add-ProjectItemBlocked -ItemId $p.issue.id -BlockingItemId $p.pullrequest.id @params -InformationVariable pullRequestMessages | ||
| $self = Add-ProjectItemBlocked -ItemId $p.issue.id -BlockingItemId $p.issue.id @params -InformationVariable selfMessages | ||
|
|
||
| # Assert | ||
| Assert-IsNull -Object $draft | ||
| Assert-IsNull -Object $pullRequest | ||
| Assert-IsNull -Object $self | ||
| Assert-IsTrue -Condition (($draftMessages.MessageData.Message -join "`n").Contains("must be a GitHub Issue")) | ||
| Assert-IsTrue -Condition (($pullRequestMessages.MessageData.Message -join "`n").Contains("must be a GitHub Issue")) | ||
| Assert-IsTrue -Condition (($selfMessages.MessageData.Message -join "`n").Contains("cannot be blocked by itself")) | ||
| } | ||
|
|
||
| function Test_AddProjectItemBlocked_ERROR { | ||
| # Arrange | ||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
| $p = Get-Mock_Project_700 | ||
| MockCall_GetProject $p -Cache | ||
| $blocker = Get-ProjectItem -ItemId $p.subIssueToShow.id -Owner $p.owner -ProjectNumber $p.number | ||
| $command = "Invoke-AddBlockedBy -IssueId $($p.issue.contentId) -BlockingIssueId $($blocker.contentId)" | ||
| $params = @{ ItemId = $p.issue.id; BlockingItemId = $blocker.id; Owner = $p.owner; ProjectNumber = $p.number } | ||
| MockCallThrow -Command $command -ExceptionMessage "Relationship would create a cycle" | ||
|
|
||
| # Act | ||
| $result = Add-ProjectItemBlocked @params -InformationVariable messages | ||
|
|
||
| # Assert | ||
| Assert-IsNull -Object $result | ||
| Assert-IsTrue -Condition (($messages.MessageData.Message -join "`n").Contains("Relationship would create a cycle")) | ||
| } | ||
|
|
||
| function Test_AddProjectItemBlocked_ERROR_Response { | ||
| # Arrange | ||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
| $p = Get-Mock_Project_700 | ||
| MockCall_GetProject $p -Cache | ||
| $blocker = Get-ProjectItem -ItemId $p.subIssueToShow.id -Owner $p.owner -ProjectNumber $p.number | ||
| $command = "Invoke-AddBlockedBy -IssueId $($p.issue.contentId) -BlockingIssueId $($blocker.contentId)" | ||
| $params = @{ ItemId = $p.issue.id; BlockingItemId = $blocker.id; Owner = $p.owner; ProjectNumber = $p.number } | ||
| $success = Get-MockFileContentJson -FileName "invoke-addBlockedBy-success.json" -AsHashtable | ||
| $responses = @( | ||
| $null, | ||
| @{ data = @{ addBlockedBy = @{ issue = @{ id = $p.issue.contentId } } } }, | ||
| @{ data = @{ addBlockedBy = @{ issue = @{ id = $blocker.contentId }; blockingIssue = @{ id = $p.issue.contentId } } } }, | ||
| @{ data = $success.data; errors = @(@{ message = "Permission denied" }) } | ||
| ) | ||
|
|
||
| foreach ($response in $responses) { | ||
| MockCallToObject -Command $command -OutObject $response | ||
|
|
||
| # Act | ||
| $result = Add-ProjectItemBlocked @params | ||
|
|
||
| # Assert | ||
| Assert-IsNull -Object $result | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <# | ||
| .DESCRIPTION | ||
| Integration function not intended for direct user use. | ||
| #> | ||
| function Invoke-AddBlockedBy { | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory)][string]$IssueId, | ||
| [Parameter(Mandatory)][string]$BlockingIssueId | ||
| ) | ||
|
|
||
| $query = Get-GraphQLString "addBlockedBy.mutant" | ||
| $variables = @{ | ||
| input = @{ | ||
| issueId = $IssueId | ||
| blockingIssueId = $BlockingIssueId | ||
| } | ||
| } | ||
|
|
||
| return Invoke-GraphQL -Query $query -Variables $variables | ||
| } Export-ModuleMember -Function Invoke-AddBlockedBy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| mutation AddBlockedBy($input: AddBlockedByInput!) { | ||
| addBlockedBy(input: $input) { | ||
| issue { id } | ||
| blockingIssue { id } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| Set-MyInvokeCommandAlias -Alias AddBlockedBy -Command 'Invoke-AddBlockedBy -IssueId {issueid} -BlockingIssueId {blockingissueid}' | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Mark a project item as blocked by another project item. | ||
| .DESCRIPTION | ||
| Both items must be backed by GitHub issues in the selected project. | ||
| ItemId is the blocked item; BlockingItemId identifies its blocker. | ||
| Returns true when the relationship is created, or null on failure. | ||
| .EXAMPLE | ||
| Add-ProjectItemBlocked -ItemId PVTI_blocked -BlockingItemId PVTI_blocker -Owner octodemo -ProjectNumber 700 | ||
| .LINK | ||
| https://docs.github.com/en/graphql/reference/issues#addblockedby---mutation | ||
| #> | ||
| function Add-ProjectItemBlocked { | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory, Position = 0)][string]$ItemId, | ||
| [Parameter(Mandatory, ValueFromPipeline, Position = 1)][string]$BlockingItemId, | ||
| [Parameter()][string]$Owner, | ||
| [Parameter()][string]$ProjectNumber | ||
| ) | ||
|
|
||
| begin { | ||
| ($Owner, $ProjectNumber) = Resolve-ProjectParameters -Owner $Owner -ProjectNumber $ProjectNumber | ||
| } | ||
|
|
||
| process { | ||
| $item = Get-ProjectItem -ItemId $ItemId -Owner $Owner -ProjectNumber $ProjectNumber | ||
| if (!$item) { | ||
| "ItemId [$ItemId] not found on project $Owner/$ProjectNumber" | Write-MyError | ||
| return $null | ||
| } | ||
|
|
||
| $blockingItem = Get-ProjectItem -ItemId $BlockingItemId -Owner $Owner -ProjectNumber $ProjectNumber | ||
| if (!$blockingItem) { | ||
| "BlockingItemId [$BlockingItemId] not found on project $Owner/$ProjectNumber" | Write-MyError | ||
| return $null | ||
| } | ||
|
|
||
| foreach ($issueItem in @($item, $blockingItem)) { | ||
| if ($issueItem.type -ne "Issue" -or [string]::IsNullOrWhiteSpace($issueItem.contentId)) { | ||
| "ItemId [$($issueItem.id)] must be a GitHub Issue. Type is [$($issueItem.type)]" | Write-MyError | ||
| return $null | ||
| } | ||
| } | ||
|
|
||
| if ($item.contentId -ceq $blockingItem.contentId) { | ||
| "ItemId [$ItemId] cannot be blocked by itself" | Write-MyError | ||
| return $null | ||
| } | ||
|
|
||
| $parameters = @{ | ||
| issueid = $item.contentId | ||
| blockingissueid = $blockingItem.contentId | ||
| } | ||
|
|
||
| try { | ||
| $response = Invoke-MyCommand -Command AddBlockedBy -Parameters $parameters | ||
| } catch { | ||
| "Failed to block ItemId [$ItemId] by BlockingItemId [$BlockingItemId] - $($_.Exception.Message)" | Write-MyError | ||
| return $null | ||
| } | ||
|
|
||
| if ($response.errors) { | ||
| "Failed to block ItemId [$ItemId] by BlockingItemId [$BlockingItemId] - $($response.errors.message -join '; ')" | Write-MyError | ||
| return $null | ||
| } | ||
|
|
||
| if ($response.data.addBlockedBy.issue.id -cne $item.contentId -or | ||
| $response.data.addBlockedBy.blockingIssue.id -cne $blockingItem.contentId) { | ||
| "Failed to block ItemId [$ItemId] by BlockingItemId [$BlockingItemId]: unexpected mutation response" | Write-MyError | ||
| return $null | ||
| } | ||
|
|
||
| return $true | ||
| } | ||
| } Export-ModuleMember -Function Add-ProjectItemBlocked | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.