@@ -29,8 +29,7 @@ function Invoke-GitHubOrgProjectWithFields {
2929 }
3030
3131 # Define the GraphQL query with variables
32- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath " orgprojectwithfieldsAndItems.query"
33- $query = get-content - path $qlPath | Out-String
32+ $query = Get-GraphQLString " orgprojectwithfieldsAndItems.query"
3433
3534 # Define the headers for the request
3635 $headers = @ {
@@ -102,8 +101,9 @@ function InvokeGitHubOrgProject {
102101 }
103102
104103 # Define the GraphQL query with variables
105- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath $QueryFileName
106- $query = get-content - path $qlPath | Out-String
104+ $query = Get-GraphQLString $QueryFileName
105+
106+
107107
108108 # Define the headers for the request
109109 $headers = @ {
@@ -168,8 +168,9 @@ function Invoke-GitHubUpdateItemValues{
168168 }
169169
170170 # Define the GraphQL query with variables
171- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath " updateItemValues.mutant"
172- $mutation = get-content - path $qlPath | Out-String
171+ $mutation = Get-GraphQLString " updateItemValues.mutant"
172+
173+
173174
174175 # Define the headers for the request
175176 $headers = @ {
@@ -241,8 +242,7 @@ function Invoke-GitHubClearItemValues{
241242 }
242243
243244 # Define the GraphQL query with variables
244- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath " clearItemValues.mutant"
245- $mutation = get-content - path $qlPath | Out-String
245+ $mutation = Get-GraphQLString " clearItemValues.mutant"
246246
247247 # Define the headers for the request
248248 $headers = @ {
@@ -306,8 +306,7 @@ function Invoke-GetIssueOrPullRequest{
306306 }
307307
308308 # Define the GraphQL query with variables
309- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath " getIssueOrPullRequest.query"
310- $query = get-content - path $qlPath | Out-String
309+ $query = Get-GraphQLString " getIssueOrPullRequest.query"
311310
312311 # Define the headers for the request
313312 $headers = @ {
@@ -339,56 +338,6 @@ function Invoke-GetIssueOrPullRequest{
339338 return $response
340339} Export-ModuleMember - Function Invoke-GetIssueOrPullRequest
341340
342- # function Invoke-GetIContentId {
343- # param(
344- # [Parameter(Mandatory)] [string] $Url
345- # )
346-
347- # # Use the environmentraviable
348- # $token = Get-GithubToken
349- # if(-not $token){
350- # throw "GH Cli Auth Token not available. Run 'gh auth login' in your terminal."
351- # }
352-
353- # # Define the GraphQL query with variables
354- # $qlPath = $PSScriptRoot | Join-Path -ChildPath "graphql" -AdditionalChildPath "getContentId.query"
355- # $query = get-content -path $qlPath | Out-String
356-
357- # # Define the headers for the request
358- # $headers = @{
359- # "Authorization" = "Bearer $token"
360- # "Content-Type" = "application/json"
361- # }
362-
363- # # get owner, reponame and issue number from the URL
364- # $repoOwner, $repoName, [int] $issueNumber = Get-RepoOwnerNameNumberFromUrl -Url $Url
365-
366- # # Define the variables for the request
367- # $variables = @{
368- # owner = $repoOwner
369- # name = $repoName
370- # number = $issueNumber
371- # }
372-
373- # # Define the body for the request
374- # $body = @{
375- # query = $query
376- # variables = $variables
377- # } | ConvertTo-Json
378-
379- # # Send the request
380- # $response = Invoke-RestMethod -Uri 'https://api.github.com/graphql' -Method Post -Body $body -Headers $headers
381-
382- # # Check if here are errors
383- # if($response.errors){
384- # "[$($response.errors[0].type)] $($response.errors[0].message)" | Write-MyError
385- # return
386- # }
387-
388- # # Return the field names
389- # return $response
390- # } Export-ModuleMember -Function Invoke-GetIContentId
391-
392341<#
393342. SYNOPSIS
394343Adds an item to a GitHub project
@@ -410,8 +359,9 @@ function Invoke-AddItemToProject{
410359 }
411360
412361 # Define the GraphQL query with variables
413- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath " addItemToProject.mutant"
414- $mutation = get-content - path $qlPath | Out-String
362+ $mutation = Get-GraphQLString " addItemToProject.mutant"
363+
364+
415365
416366 # Define the headers for the request
417367 $headers = @ {
@@ -469,8 +419,7 @@ function Invoke-RemoveItemFromProject{
469419 }
470420
471421 # Define the GraphQL query with variables
472- $qlPath = $PSScriptRoot | Join-Path - ChildPath " graphql" - AdditionalChildPath " removeItemFromProject.mutant"
473- $mutation = get-content - path $qlPath | Out-String
422+ $mutation = Get-GraphQLString " removeItemFromProject.mutant"
474423
475424 # Define the headers for the request
476425 $headers = @ {
@@ -527,3 +476,24 @@ function Get-GithubToken{
527476
528477 return $token
529478}
479+
480+ function Get-GraphQLString {
481+ param (
482+ [Parameter (Mandatory , Position = 0 )] [string ]$FileName
483+ )
484+
485+ Write-MyDebug - section " driver_gh" - message " Getting GraphQL string from file: $FileName "
486+
487+ $local = $PSScriptRoot
488+ $public = $local | Split-Path - Parent
489+
490+ $path = $public | Join-Path - ChildPath " graphql" - AdditionalChildPath $FileName
491+
492+ if (! (Test-Path - Path $path )){
493+ throw " GraphQL file not found at path: $path "
494+ }
495+
496+ $content = get-content - path $path | Out-String
497+
498+ return $content
499+ }
0 commit comments