From 63dbaf6b3719e0237f96433487f9048eefaf7c96 Mon Sep 17 00:00:00 2001 From: Ashish Keshan Date: Wed, 6 Dec 2023 12:58:45 -0800 Subject: [PATCH] try porting more from autograding v1 --- src/notify-classroom.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/notify-classroom.js b/src/notify-classroom.js index 294124a..fe90606 100644 --- a/src/notify-classroom.js +++ b/src/notify-classroom.js @@ -41,15 +41,33 @@ exports.NotifyClassroom = async function NotifyClassroom (runnerResults) { console.log(`Run ID: ${runId}`) if (Number.isNaN(runId)) return - // List check runs for the repository - const checkRunsResponse = await octokit.rest.checks.listForRef({ + // Fetch the workflow run + const workflowRunResponse = await octokit.rest.actions.getWorkflowRun({ owner, repo, - check_name: 'Autograding Tests' + run_id: runId, }) + // Find the check suite run + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const checkSuiteUrl = (workflowRunResponse.data).check_suite_url + const checkSuiteId = parseInt(checkSuiteUrl.match(/[0-9]+$/)[0], 10) + const checkRunsResponse = await octokit.rest.checks.listForSuite({ + owner, + repo, + check_name: 'Autograding Tests', + check_suite_id: checkSuiteId, + }) + + // List check runs for the repository + // const checkRunsResponse = await octokit.rest.checks.listForRef({ + // owner, + // repo, + // check_name: 'Autograding Tests' + // }) + // Filter to find the check run named "Autograding Tests" for the specific workflow run ID - const checkRun = checkRunsResponse.data.check_runs.find(cr => cr.name === 'Autograding Tests' && cr.check_suite.workflow_run_id === runId) + const checkRun = checkRunsResponse.data.total_count === 1 && checkRunsResponse.data.check_runs[0] console.log(`Check run: ${checkRun}`) if (!checkRun) return