@jsenv/github-check-run 0.0.3 → 0.0.4
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.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Interact with GitHub check rest API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@jsenv/fetch": "1.1.40",
|
|
38
|
-
"@jsenv/log": "3.4.
|
|
38
|
+
"@jsenv/log": "3.4.1"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -6,7 +6,9 @@ export const GET = ({ url, githubToken, headers }) => {
|
|
|
6
6
|
method: "GET",
|
|
7
7
|
headers: {
|
|
8
8
|
...tokenToHeaders(githubToken),
|
|
9
|
-
|
|
9
|
+
"accept": "application/vnd.github+json",
|
|
10
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
11
|
+
...headers,
|
|
10
12
|
},
|
|
11
13
|
responseStatusHandlers: {
|
|
12
14
|
200: async (response) => {
|
|
@@ -24,7 +26,9 @@ export const POST = ({ url, body, githubToken, headers }) => {
|
|
|
24
26
|
method: "POST",
|
|
25
27
|
headers: {
|
|
26
28
|
...tokenToHeaders(githubToken),
|
|
27
|
-
|
|
29
|
+
"accept": "application/vnd.github+json",
|
|
30
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
31
|
+
...headers,
|
|
28
32
|
},
|
|
29
33
|
body: JSON.stringify(body),
|
|
30
34
|
responseStatusHandlers: {
|
|
@@ -43,7 +47,9 @@ export const PATCH = ({ signal, url, body, githubToken, headers }) => {
|
|
|
43
47
|
method: "PATCH",
|
|
44
48
|
headers: {
|
|
45
49
|
...tokenToHeaders(githubToken),
|
|
46
|
-
|
|
50
|
+
"accept": "application/vnd.github+json",
|
|
51
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
52
|
+
...headers,
|
|
47
53
|
},
|
|
48
54
|
body: JSON.stringify(body),
|
|
49
55
|
responseStatusHandlers: {
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* https://github.com/IgnusG/jest-report-action/blob/c006b890ba3c3b650e6c55916a643ca82b64133b/tasks/github-api.js#L12
|
|
4
|
+
* https://docs.github.com/fr/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
|
-
import { createLogger } from "@jsenv/log";
|
|
7
|
+
import { createLogger, UNICODE, createDetailedMessage } from "@jsenv/log";
|
|
7
8
|
|
|
8
9
|
import { POST, PATCH } from "./internal/github_rest_api.js";
|
|
9
10
|
|
|
10
|
-
/*
|
|
11
|
-
annotation object contains the following:
|
|
12
|
-
{path: filePath,
|
|
13
|
-
title: `${ describe } > ${ test }`,
|
|
14
|
-
start_line: location.start.line,
|
|
15
|
-
end_line: location.end.line,
|
|
16
|
-
annotation_level: 'failure',
|
|
17
|
-
message: `${ title }\n${ expectations }\n\n${ stacktrace }`
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// https://docs.github.com/fr/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
|
|
21
11
|
export const startGithubCheckRun = async ({
|
|
22
12
|
logLevel,
|
|
23
13
|
githubToken,
|
|
@@ -52,23 +42,37 @@ export const startGithubCheckRun = async ({
|
|
|
52
42
|
}
|
|
53
43
|
|
|
54
44
|
const logger = createLogger({ logLevel });
|
|
55
|
-
logger.debug("create check on");
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
summary: checkSummary,
|
|
46
|
+
logger.debug(`create check for commit ${commitSha}`);
|
|
47
|
+
let check;
|
|
48
|
+
try {
|
|
49
|
+
check = await POST({
|
|
50
|
+
url: `https://api.github.com/repos/${repositoryOwner}/${repositoryName}/check-runs`,
|
|
51
|
+
githubToken,
|
|
52
|
+
headers: {
|
|
53
|
+
"accept": "application/vnd.github+json",
|
|
54
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
67
55
|
},
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
body: {
|
|
57
|
+
head_sha: commitSha,
|
|
58
|
+
status: checkStatus,
|
|
59
|
+
name: checkName,
|
|
60
|
+
output: {
|
|
61
|
+
title: checkTitle,
|
|
62
|
+
summary: checkSummary,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
logger.debug(`${UNICODE.OK} check created (id: ${check.id})`);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
logger.error(
|
|
69
|
+
createDetailedMessage(`${UNICODE.FAILURE} failed to create check`, {
|
|
70
|
+
"error stack": e.stack,
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
return { progress: () => {}, fail: () => {}, pass: () => {} };
|
|
74
|
+
}
|
|
70
75
|
|
|
71
|
-
let previousUpdatePromise;
|
|
72
76
|
const update = async ({
|
|
73
77
|
status,
|
|
74
78
|
conclusion,
|
|
@@ -76,18 +80,15 @@ export const startGithubCheckRun = async ({
|
|
|
76
80
|
summary,
|
|
77
81
|
annotations = [],
|
|
78
82
|
}) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let annotationsSent = 0;
|
|
84
|
-
const annotationsBatch = annotations.slice(annotationsSent, 50);
|
|
83
|
+
let annotationsSent = 0;
|
|
84
|
+
const annotationsBatch = annotations.slice(annotationsSent, 50);
|
|
85
|
+
logger.debug(`update check run ${check.id}`);
|
|
86
|
+
try {
|
|
85
87
|
await PATCH({
|
|
86
|
-
url:
|
|
88
|
+
url: check.url,
|
|
87
89
|
githubToken,
|
|
88
90
|
body: {
|
|
89
91
|
head_sha: commitSha,
|
|
90
|
-
check_run_id: check.id,
|
|
91
92
|
...(status ? { status } : {}),
|
|
92
93
|
...(conclusion ? { conclusion } : {}),
|
|
93
94
|
output: {
|
|
@@ -97,36 +98,40 @@ export const startGithubCheckRun = async ({
|
|
|
97
98
|
},
|
|
98
99
|
},
|
|
99
100
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
logger.debug(`${UNICODE.OK} check updated`);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
logger.error(
|
|
104
|
+
createDetailedMessage(`${UNICODE.FAILURE} failed to update check`, {
|
|
105
|
+
"error stack": e.stack,
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (status) {
|
|
111
|
+
checkStatus = status;
|
|
112
|
+
}
|
|
113
|
+
if (title) {
|
|
114
|
+
checkTitle = title;
|
|
115
|
+
}
|
|
116
|
+
if (summary) {
|
|
117
|
+
checkSummary = summary;
|
|
118
|
+
}
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
annotations: annotationsBatch,
|
|
121
|
-
},
|
|
120
|
+
annotationsSent += annotationsBatch.length;
|
|
121
|
+
while (annotationsSent < annotations.length) {
|
|
122
|
+
const annotationsBatch = annotations.slice(annotationsSent, 50);
|
|
123
|
+
await PATCH({
|
|
124
|
+
url: check.url,
|
|
125
|
+
githubToken,
|
|
126
|
+
body: {
|
|
127
|
+
head_sha: commitSha,
|
|
128
|
+
output: {
|
|
129
|
+
annotations: annotationsBatch,
|
|
122
130
|
},
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
previousUpdatePromise = null;
|
|
128
|
-
})();
|
|
129
|
-
return previousUpdatePromise;
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
annotationsSent += annotationsBatch.length;
|
|
134
|
+
}
|
|
130
135
|
};
|
|
131
136
|
|
|
132
137
|
let lastProgressCall;
|