Skip to content
Merged
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
99 changes: 69 additions & 30 deletions public/driver/driver_gh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,74 @@ Updates item values in a GitHub project
This is an integration function that is not intended to be used directly by the user.
Updates the values of specific fields for an item in a GitHub project.
#>
# function Invoke-GitHubUpdateItemValues{
# param(
# [Parameter(Mandatory=$true)] [string]$ProjectId,
# [Parameter(Mandatory=$true)] [string]$ItemId,
# [Parameter(Mandatory=$true)] [string]$FieldId,
# [Parameter(Mandatory=$true)] [object]$Value,
# [Parameter(Mandatory=$true)] [ValidateSet("singleSelectOptionId", "text", "number", "date", "iterationId")]
# [string]$Type
# )

# "ProjectId: $ProjectId, ItemId: $ItemId, FieldId: $FieldId, Value: $Value, Type: $Type" | Write-MyDebug -section "driver_gh"

# # Use the environmentraviable
# $token = Get-GithubToken
# if(-not $token){
# throw "GH Cli Auth Token not available. Run 'gh auth login' in your terminal."
# }

# # Define the GraphQL query with variables
# $mutation = Get-GraphQLString "updateItemValues.mutant"



# # Define the headers for the request
# $headers = @{
# "Authorization" = "Bearer $token"
# "Content-Type" = "application/json"
# }

# # Ensure that if the $type is number the value is a number
# # API fails if when updaring a number the value type in the Input payload s not a number
# if($Type -eq "number"){
# $Value = [decimal]$Value
# }

# # Define the variables for the request
# $variables = @{
# input = @{
# projectId = $ProjectId
# itemId = $ItemId
# fieldId = $FieldId
# value = @{
# $Type=$Value
# }
# }
# }

# # Define the body for the request
# $body = @{
# query= $mutation
# variables = $variables
# } | ConvertTo-Json -Depth 10

# # Send the request
# $response = Invoke-RestMethod -Uri 'https://api.github.com/graphql' -Method Post -Body $body -Headers $headers

# # Check if here are errors
# if($response.errors){
# $response.errors | ForEach-Object {
# getErrrorString -Errors $response.errors | Write-MyError
# }
# return $null
# }

# # Return the field names
# return $response
# } Export-ModuleMember -Function Invoke-GitHubUpdateItemValues

function Invoke-GitHubUpdateItemValues{
param(
[Parameter(Mandatory=$true)] [string]$ProjectId,
Expand All @@ -138,23 +206,9 @@ function Invoke-GitHubUpdateItemValues{

"ProjectId: $ProjectId, ItemId: $ItemId, FieldId: $FieldId, Value: $Value, Type: $Type" | Write-MyDebug -section "driver_gh"

# Use the environmentraviable
$token = Get-GithubToken
if(-not $token){
throw "GH Cli Auth Token not available. Run 'gh auth login' in your terminal."
}

# Define the GraphQL query with variables
$mutation = Get-GraphQLString "updateItemValues.mutant"



# Define the headers for the request
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}

# Ensure that if the $type is number the value is a number
# API fails if when updaring a number the value type in the Input payload s not a number
if($Type -eq "number"){
Expand All @@ -173,22 +227,7 @@ function Invoke-GitHubUpdateItemValues{
}
}

# Define the body for the request
$body = @{
query= $mutation
variables = $variables
} | ConvertTo-Json -Depth 10

# Send the request
$response = Invoke-RestMethod -Uri 'https://api.github.com/graphql' -Method Post -Body $body -Headers $headers

# Check if here are errors
if($response.errors){
$response.errors | ForEach-Object {
getErrrorString -Errors $response.errors | Write-MyError
}
return $null
}
$response = Invoke-GraphQL -Query $mutation -Variables $variables

# Return the field names
return $response
Expand Down
Loading