@jsenv/github-check-run 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/github-check-run",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Interact with GitHub check rest API",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -74,6 +74,8 @@ export const startGithubCheckRun = async ({
74
74
  return { progress: () => {}, fail: () => {}, pass: () => {} };
75
75
  }
76
76
 
77
+ let checkConclusion;
78
+
77
79
  const update = async ({
78
80
  status,
79
81
  conclusion,
@@ -87,6 +89,9 @@ export const startGithubCheckRun = async ({
87
89
  if (typeof summary !== "string") {
88
90
  throw new TypeError(`summary must be a string, got ${summary}`);
89
91
  }
92
+ if (conclusion) {
93
+ checkConclusion = conclusion;
94
+ }
90
95
 
91
96
  let annotationsSent = 0;
92
97
  const annotationsBatch = annotations.slice(annotationsSent, 50);
@@ -152,6 +157,12 @@ ${JSON.stringify(body, null, " ")}`);
152
157
 
153
158
  return {
154
159
  progress: async ({ title, summary, annotations = [] }) => {
160
+ if (checkConclusion === "failure") {
161
+ throw new Error(`cannot progress() after fail()`);
162
+ }
163
+ if (checkConclusion === "success") {
164
+ throw new Error(`cannot progress() after pass()`);
165
+ }
155
166
  const nowMs = Date.now();
156
167
  const isFirstCall = !lastProgressCall;
157
168
  lastProgressCall = nowMs;
@@ -196,9 +207,17 @@ ${JSON.stringify(body, null, " ")}`);
196
207
  });
197
208
  },
198
209
  fail: ({ title, summary, annotations } = {}) => {
210
+ if (checkConclusion === "failure") {
211
+ throw new Error(`already failed`);
212
+ }
213
+ if (checkConclusion === "success") {
214
+ throw new Error(`cannot fail() after pass()`);
215
+ }
216
+
199
217
  if (pendingAbortController) {
200
218
  pendingAbortController.abort();
201
219
  }
220
+ // TODO: wait to any update before PATCH
202
221
  return update({
203
222
  status: "completed",
204
223
  conclusion: "failure",
@@ -208,9 +227,17 @@ ${JSON.stringify(body, null, " ")}`);
208
227
  });
209
228
  },
210
229
  pass: ({ title, summary, annotations } = {}) => {
230
+ if (checkConclusion === "success") {
231
+ throw new Error(`already passed`);
232
+ }
233
+ if (checkConclusion === "failure") {
234
+ throw new Error(`cannot pass() after fail()`);
235
+ }
236
+
211
237
  if (pendingAbortController) {
212
238
  pendingAbortController.abort();
213
239
  }
240
+ // TODO: wait to any pending update before PATCH
214
241
  return update({
215
242
  status: "completed",
216
243
  conclusion: "success",