|
40 | 40 | uses: ./ |
41 | 41 | with: |
42 | 42 | Script: | |
43 | | - LogGroup 'Get-GitHubZen' { |
44 | | - Get-GitHubZen |
| 43 | + $context = Get-GitHubContext |
| 44 | +
|
| 45 | + # GraphQL Endpoint |
| 46 | + $GraphQLEndpoint = 'https://api.github.com/graphql' |
| 47 | +
|
| 48 | + # Headers |
| 49 | + $Headers = @{ |
| 50 | + 'Content-Type' = 'application/json' |
| 51 | + } |
| 52 | +
|
| 53 | + # GraphQL Query for fetching user's organizations and repositories |
| 54 | + $Query = @' |
| 55 | + { |
| 56 | + viewer { |
| 57 | + enterprises(first: 100) { |
| 58 | + nodes { |
| 59 | + name |
| 60 | + slug |
| 61 | + id |
| 62 | + } |
| 63 | + } |
| 64 | + organizations(first: 100) { |
| 65 | + nodes { |
| 66 | + name |
| 67 | + login |
| 68 | + url |
| 69 | + } |
| 70 | + } |
| 71 | + repositories(first: 100, privacy: PUBLIC) { |
| 72 | + nodes { |
| 73 | + name |
| 74 | + url |
| 75 | + isPrivate |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + '@ |
| 81 | +
|
| 82 | + # Prepare the body for the HTTP POST |
| 83 | + $Body = @{ |
| 84 | + query = $Query |
| 85 | + } | ConvertTo-Json -Depth 10 |
| 86 | +
|
| 87 | + # Make the HTTP POST request |
| 88 | + $response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer |
| 89 | +
|
| 90 | + # Process the response |
| 91 | + if ($response) { |
| 92 | + Write-Output "User Login: $($response.data.viewer.login)" |
| 93 | + Write-Output 'Enterprises:' |
| 94 | + $response.data.viewer.enterprises.nodes | ForEach-Object { |
| 95 | + Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)" |
| 96 | + } |
| 97 | + Write-Output 'Organizations:' |
| 98 | + $response.data.viewer.organizations.nodes | ForEach-Object { |
| 99 | + Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)" |
| 100 | + if ($_.enterprise -ne $null) { |
| 101 | + Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)" |
| 102 | + } |
| 103 | + } |
| 104 | +
|
| 105 | + Write-Output 'Repositories:' |
| 106 | + $response.data.viewer.repositories.nodes | ForEach-Object { |
| 107 | + Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)" |
| 108 | + } |
| 109 | + } else { |
| 110 | + Write-Error 'Failed to fetch data from GitHub API.' |
45 | 111 | } |
46 | 112 |
|
47 | 113 | ActionTestCommands: |
|
0 commit comments