Skip to content

Commit 9922ecc

Browse files
test
1 parent 9ca8690 commit 9922ecc

File tree

1 file changed

+200
-14
lines changed

1 file changed

+200
-14
lines changed

.github/workflows/Action-Test.yml

Lines changed: 200 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,74 @@ jobs:
169169
with:
170170
Token: ${{ secrets.TEST_PAT }}
171171
Script: |
172-
LogGroup 'Get-GitHubUser' {
173-
Get-GitHubUser | Format-Table -AutoSize
172+
$context = Get-GitHubContext
173+
174+
# GraphQL Endpoint
175+
$GraphQLEndpoint = 'https://api.github.com/graphql'
176+
177+
# Headers
178+
$Headers = @{
179+
'Content-Type' = 'application/json'
180+
}
181+
182+
# GraphQL Query for fetching user's organizations and repositories
183+
$Query = @'
184+
{
185+
viewer {
186+
enterprises(first: 100) {
187+
nodes {
188+
name
189+
slug
190+
id
191+
}
192+
}
193+
organizations(first: 100) {
194+
nodes {
195+
name
196+
login
197+
url
198+
}
199+
}
200+
repositories(first: 100, privacy: PUBLIC) {
201+
nodes {
202+
name
203+
url
204+
isPrivate
205+
}
206+
}
207+
}
208+
}
209+
'@
210+
211+
# Prepare the body for the HTTP POST
212+
$Body = @{
213+
query = $Query
214+
} | ConvertTo-Json -Depth 10
215+
216+
# Make the HTTP POST request
217+
$response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer
218+
219+
# Process the response
220+
if ($response) {
221+
Write-Output "User Login: $($response.data.viewer.login)"
222+
Write-Output 'Enterprises:'
223+
$response.data.viewer.enterprises.nodes | ForEach-Object {
224+
Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)"
225+
}
226+
Write-Output 'Organizations:'
227+
$response.data.viewer.organizations.nodes | ForEach-Object {
228+
Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)"
229+
if ($_.enterprise -ne $null) {
230+
Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)"
231+
}
232+
}
233+
234+
Write-Output 'Repositories:'
235+
$response.data.viewer.repositories.nodes | ForEach-Object {
236+
Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)"
237+
}
238+
} else {
239+
Write-Error 'Failed to fetch data from GitHub API.'
174240
}
175241
176242
ActionTestWithFGPAT:
@@ -186,8 +252,74 @@ jobs:
186252
with:
187253
Token: ${{ secrets.TEST_FG_PAT }}
188254
Script: |
189-
LogGroup 'Get-GitHubUser' {
190-
Get-GitHubUser | Format-Table -AutoSize
255+
$context = Get-GitHubContext
256+
257+
# GraphQL Endpoint
258+
$GraphQLEndpoint = 'https://api.github.com/graphql'
259+
260+
# Headers
261+
$Headers = @{
262+
'Content-Type' = 'application/json'
263+
}
264+
265+
# GraphQL Query for fetching user's organizations and repositories
266+
$Query = @'
267+
{
268+
viewer {
269+
enterprises(first: 100) {
270+
nodes {
271+
name
272+
slug
273+
id
274+
}
275+
}
276+
organizations(first: 100) {
277+
nodes {
278+
name
279+
login
280+
url
281+
}
282+
}
283+
repositories(first: 100, privacy: PUBLIC) {
284+
nodes {
285+
name
286+
url
287+
isPrivate
288+
}
289+
}
290+
}
291+
}
292+
'@
293+
294+
# Prepare the body for the HTTP POST
295+
$Body = @{
296+
query = $Query
297+
} | ConvertTo-Json -Depth 10
298+
299+
# Make the HTTP POST request
300+
$response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer
301+
302+
# Process the response
303+
if ($response) {
304+
Write-Output "User Login: $($response.data.viewer.login)"
305+
Write-Output 'Enterprises:'
306+
$response.data.viewer.enterprises.nodes | ForEach-Object {
307+
Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)"
308+
}
309+
Write-Output 'Organizations:'
310+
$response.data.viewer.organizations.nodes | ForEach-Object {
311+
Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)"
312+
if ($_.enterprise -ne $null) {
313+
Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)"
314+
}
315+
}
316+
317+
Write-Output 'Repositories:'
318+
$response.data.viewer.repositories.nodes | ForEach-Object {
319+
Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)"
320+
}
321+
} else {
322+
Write-Error 'Failed to fetch data from GitHub API.'
191323
}
192324
193325
ActionTestWithGitHubApp:
@@ -204,18 +336,72 @@ jobs:
204336
ClientID: ${{ secrets.TEST_APP_CLIENT_ID }}
205337
PrivateKey: ${{ secrets.TEST_APP_PRIVATE_KEY }}
206338
Script: |
207-
LogGroup 'Get-GitHubApp' {
208-
Get-GitHubApp | Format-Table -AutoSize
209-
}
339+
$context = Get-GitHubContext
210340
211-
LogGroup 'Get-GitHubAppInstallation' {
212-
Get-GitHubAppInstallation | Format-Table -AutoSize
341+
# GraphQL Endpoint
342+
$GraphQLEndpoint = 'https://api.github.com/graphql'
343+
344+
# Headers
345+
$Headers = @{
346+
'Content-Type' = 'application/json'
213347
}
214348
215-
LogGroup 'Do something as an installation' {
216-
Get-GithubAppInstallation | New-GitHubAppInstallationAccessToken | ForEach-Object {
217-
Connect-GitHub -Token $_.token -Silent
218-
Get-GitHubContext | Format-Table -AutoSize
219-
Get-GitHubGitConfig | Format-Table -AutoSize
349+
# GraphQL Query for fetching user's organizations and repositories
350+
$Query = @'
351+
{
352+
viewer {
353+
enterprises(first: 100) {
354+
nodes {
355+
name
356+
slug
357+
id
358+
}
359+
}
360+
organizations(first: 100) {
361+
nodes {
362+
name
363+
login
364+
url
365+
}
366+
}
367+
repositories(first: 100, privacy: PUBLIC) {
368+
nodes {
369+
name
370+
url
371+
isPrivate
372+
}
373+
}
220374
}
221375
}
376+
'@
377+
378+
# Prepare the body for the HTTP POST
379+
$Body = @{
380+
query = $Query
381+
} | ConvertTo-Json -Depth 10
382+
383+
# Make the HTTP POST request
384+
$response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer
385+
386+
# Process the response
387+
if ($response) {
388+
Write-Output "User Login: $($response.data.viewer.login)"
389+
Write-Output 'Enterprises:'
390+
$response.data.viewer.enterprises.nodes | ForEach-Object {
391+
Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)"
392+
}
393+
Write-Output 'Organizations:'
394+
$response.data.viewer.organizations.nodes | ForEach-Object {
395+
Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)"
396+
if ($_.enterprise -ne $null) {
397+
Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)"
398+
}
399+
}
400+
401+
Write-Output 'Repositories:'
402+
$response.data.viewer.repositories.nodes | ForEach-Object {
403+
Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)"
404+
}
405+
} else {
406+
Write-Error 'Failed to fetch data from GitHub API.'
407+
}

0 commit comments

Comments
 (0)