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 45fec25
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 3 deletions.
62 changes: 60 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6075,9 +6075,9 @@ var require_dist_node5 = __commonJS({
}
});

// node_modules/@octokit/graphql/dist-node/index.js
// node_modules/@octokit/core/node_modules/@octokit/graphql/dist-node/index.js
var require_dist_node6 = __commonJS({
"node_modules/@octokit/graphql/dist-node/index.js"(exports) {
"node_modules/@octokit/core/node_modules/@octokit/graphql/dist-node/index.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var request = require_dist_node5();
Expand Down Expand Up @@ -7820,6 +7820,61 @@ var ansiStyles = assembleStyles();
var ansi_styles_default = ansiStyles;

// src/github-api.ts
async function fetchGraphQl(octokit, params) {
const { repository: { object: { checkSuites } } } = await octokit.graphql(
`
{
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
}
);
return checkSuites;
}
function isAcceptable(conclusion) {
return conclusion === "success" || conclusion === "skipped";
}
Expand Down Expand Up @@ -7989,6 +8044,9 @@ async function run() {
const ownJobIDs = await fetchJobIDs(octokit, { ...repositoryInfo, run_id: runId });
(0, import_core.info)(JSON.stringify({ ownJobIDs: [...ownJobIDs] }, null, 2));
(0, import_core.endGroup)();
const gqlRet = await fetchGraphQl(octokit, { ...repositoryInfo, ref: commitSha });
console.info(gqlRet);
(0, import_core.info)(JSON.stringify(gqlRet));
for (; ; ) {
attempts += 1;
if (attempts > attemptLimits) {
Expand Down
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 45fec25

Please sign in to comment.