This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporting.js
175 lines (146 loc) · 4.03 KB
/
reporting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const core = require("@actions/core");
const fs = require("fs");
const path = require("path");
const GraphQLClient = require("graphql-request").GraphQLClient;
const gql = require("graphql-request").gql;
const endpoint = process.env.REVIEW_END_POINT;
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: `Bearer ${process.env.REVIEW_BOT_USER_TOKEN}`,
},
});
const completedSubmissionReportQuery = gql`
mutation CompletedSubmissionReport(
$submissionId: ID!
$testReport: String
$conclusion: SubmissionReportConclusion!
) {
concludeSubmissionReport(
submissionId: $submissionId
testReport: $testReport
conclusion: $conclusion
) {
success
}
}
`;
const inProgressSubmissionReportQuery = gql`
mutation InProgressSubmissionReport($submissionId: ID!, $testReport: String) {
beginProcessingSubmissionReport(
submissionId: $submissionId
testReport: $testReport
) {
success
}
}
`;
const queuedSubmissionReportQuery = gql`
mutation QueuedSubmissionReport($submissionId: ID!, $testReport: String) {
queueSubmissionReport(
submissionId: $submissionId
testReport: $testReport
) {
success
}
}
`;
// Parse student submission data
let submissionData;
try {
submissionData = JSON.parse(
fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, "submission.json"))
);
} catch (error) {
throw error;
}
// Parse inputs to the action
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 != "") {
try {
reportData = JSON.parse(
fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, reportFilePath))
);
} catch (error) {
throw error;
}
}
let reportIfGraded = (reportData) => {
let grading = reportData.grading;
let testReport =
grading == "reject"
? "Submission will be eventually rejected and feedback will be shared"
: "";
return testReport;
};
let truncateReport = (reportText) => {
if (typeof reportText !== "string") {
return reportText;
}
if (reportText.length > 10000) {
return (
"Report has been truncated because it was longer than 10,000 chars:\n\n---\n\n" +
reportText.substring(0, 9900)
);
} else {
return reportText;
}
};
if (reportData != undefined) {
reportConclusion = 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,
status: reportStatus,
};
async function run() {
let mutation;
switch (statusInput) {
case "queued":
mutation = queuedSubmissionReportQuery;
break;
case "in_progress":
mutation = inProgressSubmissionReportQuery;
break;
case "completed":
mutation = completedSubmissionReportQuery;
if (validConclusion(reportConclusion) && reportDescription != undefined) {
variables.conclusion = reportConclusion;
} else {
throw "Invalid conclusion for completed status or missing description";
}
break;
default:
throw "Invalid submission report status";
}
const data = await graphQLClient.request(mutation, variables);
console.log(JSON.stringify(data, undefined, 2));
}
let testMode = core.getBooleanInput("test_mode");
if (testMode) {
console.log(reportData);
console.log(submissionData);
} else {
console.log(reportData);
run().catch((error) => console.log(error));
}