Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Clean up conclusion #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 53 additions & 33 deletions dist/reporting/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/reporting/index.js.map

Large diffs are not rendered by default.

79 changes: 48 additions & 31 deletions reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,53 @@ const graphQLClient = new GraphQLClient(endpoint, {
const completedSubmissionReportQuery = gql`
mutation CompletedSubmissionReport(
$submissionId: ID!
$testReport: String
$conclusion: SubmissionReportConclusion!
$report: String
$status: SubmissionReportStatus!
$reporter: String!
$heading: String
) {
concludeSubmissionReport(
submissionId: $submissionId
testReport: $testReport
conclusion: $conclusion
report: $report
status: $status
reporter: $reporter
heading: $heading
) {
success
}
}
`;

const inProgressSubmissionReportQuery = gql`
mutation InProgressSubmissionReport($submissionId: ID!, $testReport: String) {
mutation InProgressSubmissionReport(
$submissionId: ID!
$report: String
$reporter: String!
$heading: String
) {
beginProcessingSubmissionReport(
submissionId: $submissionId
testReport: $testReport
report: $report
reporter: $reporter
heading: $heading
) {
success
}
}
`;

const queuedSubmissionReportQuery = gql`
mutation QueuedSubmissionReport($submissionId: ID!, $testReport: String) {
mutation QueuedSubmissionReport(
$submissionId: ID!
$report: String
$reporter: String!
$heading: String
) {
queueSubmissionReport(
submissionId: $submissionId
testReport: $testReport
report: $report
reporter: $reporter
heading: $heading
) {
success
}
Expand All @@ -67,13 +85,10 @@ const reportFilePath = core.getInput("report_file_path");

const statusInput = core.getInput("status");

const conclusionInput = core.getInput("conclusion");

const descriptionInput = core.getInput("description");

// Check for report data
let reportData;
let reportConclusion;
let reportDescription;

if (reportFilePath != "") {
Expand All @@ -89,12 +104,12 @@ if (reportFilePath != "") {
let reportIfGraded = (reportData) => {
let grading = reportData.grading;

let testReport =
let report =
grading == "reject"
? "Submission will be eventually rejected and feedback will be shared"
: "";

return testReport;
return report;
};

let truncateReport = (reportText) => {
Expand All @@ -112,49 +127,51 @@ let truncateReport = (reportText) => {
}
};

let reportStatus = statusInput;

if (reportData != undefined) {
reportConclusion = reportData.status;
reportStatus = reportData.status;
reportDescription =
truncateReport(reportData.report) ||
descriptionInput ||
reportIfGraded(reportData) ||
"Test report unavailable";
} else {
reportConclusion = conclusionInput;
reportDescription = descriptionInput || "Test report unavailable";
}

let reportStatus = statusInput;

const validConclusions = ["success", "error", "failure"];

let validConclusion = (conclusion) => {
return validConclusions.includes(conclusion);
};

let variables = {
submissionId: submissionData.id,
testReport: reportDescription,
report: reportDescription,
status: reportStatus,
reporter: "Virtual Teaching Assistant",
};

async function run() {
let mutation;
switch (statusInput) {
case "queued":
mutation = queuedSubmissionReportQuery;
variables.heading = "Automated tests are queued";
break;
case "in_progress":
mutation = inProgressSubmissionReportQuery;
variables.heading = "Automated tests are in progress";
break;
case "completed":
case "error":
mutation = completedSubmissionReportQuery;
if (validConclusion(reportConclusion) && reportDescription != undefined) {
variables.conclusion = reportConclusion;
} else {
throw "Invalid conclusion for completed status or missing description";
}

variables.heading = "Automated tests passed";
variables.status = "error";
break;
case "failure":
mutation = completedSubmissionReportQuery;
variables.heading = "Automated tests failed";
variables.status = "failure";
break;
case "success":
mutation = completedSubmissionReportQuery;
variables.heading = "Automated tests passed";
variables.status = "success";
break;
default:
throw "Invalid submission report status";
Expand Down