Skip to content

Commit

Permalink
Attempt to get GraphQL result with octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Aug 30, 2023
1 parent ed4bd08 commit eb0a03f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
67 changes: 67 additions & 0 deletions src/github-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,73 @@
import type { getOctokit } from '@actions/github';
import type { Endpoints } from '@octokit/types';

import { graphql } from '@octokit/graphql';
import schema from '@octokit/graphql-schema';

export async function fetchGraphQl(
octokit: Octokit,
params: { 'owner': string; 'repo': string; ref: string },
): Promise<object | undefined | null> {
const { repository: { object: { checkSuites } } } = await octokit.graphql<
{ repository: { object: { checkSuites: schema.Commit['checkSuites'] } } }
>(
`
{
repository(owner: $owner, name: $repo) {
object(expression: $commitSha) {
... on Commit {
__typename
checkSuites(first: 10) {
edges {
node {
id
status
conclusion
workflowRun {
id
databaseId
createdAt
workflow {
id
databaseId
name
resourcePath
url
}
}
checkRuns(first: 10) {
edges {
node {
id
databaseId
name
status
conclusion
startedAt
completedAt
}
}
}
}
}
}
}
}
}
}
`,
{
owner: params.owner,
repo: params.repo,
commitSha: params.ref,
},
);

// checkSuites?.edges[0]?.node;
// console.info(checkSuites);
return checkSuites;
}

type Octokit = ReturnType<typeof getOctokit>;

// REST: https://docs.github.com/en/rest/reference/actions#list-jobs-for-a-workflow-run
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const errorMessage = (body: string) => (`${styles.red.open}${body}${styles.red.c
const succeededMessage = (body: string) => (`${styles.green.open}${body}${styles.green.close}`);
const colorize = (body: string, ok: boolean) => (ok ? succeededMessage(body) : errorMessage(body));

import { fetchJobIDs, fetchOtherRunStatus } from './github-api.js';
import { fetchGraphQl, fetchJobIDs, fetchOtherRunStatus } from './github-api.js';
import { readableDuration, wait, isRetryMethod, retryMethods, getIdleMilliseconds } from './wait.js';

async function run(): Promise<void> {
Expand Down Expand Up @@ -103,6 +103,10 @@ async function run(): Promise<void> {

endGroup();

const gqlRet = await fetchGraphQl(octokit, { ...repositoryInfo, ref: commitSha });
console.info(gqlRet);
info(JSON.stringify(gqlRet));

for (;;) {
attempts += 1;
if (attempts > attemptLimits) {
Expand Down

0 comments on commit eb0a03f

Please sign in to comment.