@jsenv/github-check-run 0.0.3 → 0.0.5
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.5",
|
|
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,38 @@ export const startGithubCheckRun = async ({
|
|
|
52
42
|
}
|
|
53
43
|
|
|
54
44
|
const logger = createLogger({ logLevel });
|
|
55
|
-
logger.debug("create check on");
|
|
56
45
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
46
|
+
const checkApiURL = `https://api.github.com/repos/${repositoryOwner}/${repositoryName}/check-runs`;
|
|
47
|
+
logger.debug(`POST ${checkApiURL} (for commit ${commitSha})`);
|
|
48
|
+
let check;
|
|
49
|
+
try {
|
|
50
|
+
check = await POST({
|
|
51
|
+
url: checkApiURL,
|
|
52
|
+
githubToken,
|
|
53
|
+
headers: {
|
|
54
|
+
"accept": "application/vnd.github+json",
|
|
55
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
67
56
|
},
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
body: {
|
|
58
|
+
head_sha: commitSha,
|
|
59
|
+
status: checkStatus,
|
|
60
|
+
name: checkName,
|
|
61
|
+
output: {
|
|
62
|
+
title: checkTitle,
|
|
63
|
+
summary: checkSummary,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
logger.debug(`${UNICODE.OK} check created (id: ${check.id})`);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
logger.error(
|
|
70
|
+
createDetailedMessage(`${UNICODE.FAILURE} failed to create check`, {
|
|
71
|
+
"error stack": e.stack,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
return { progress: () => {}, fail: () => {}, pass: () => {} };
|
|
75
|
+
}
|
|
70
76
|
|
|
71
|
-
let previousUpdatePromise;
|
|
72
77
|
const update = async ({
|
|
73
78
|
status,
|
|
74
79
|
conclusion,
|
|
@@ -76,18 +81,15 @@ export const startGithubCheckRun = async ({
|
|
|
76
81
|
summary,
|
|
77
82
|
annotations = [],
|
|
78
83
|
}) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let annotationsSent = 0;
|
|
84
|
-
const annotationsBatch = annotations.slice(annotationsSent, 50);
|
|
84
|
+
let annotationsSent = 0;
|
|
85
|
+
const annotationsBatch = annotations.slice(annotationsSent, 50);
|
|
86
|
+
logger.debug(`update check run ${check.id}`);
|
|
87
|
+
try {
|
|
85
88
|
await PATCH({
|
|
86
|
-
url:
|
|
89
|
+
url: check.url,
|
|
87
90
|
githubToken,
|
|
88
91
|
body: {
|
|
89
92
|
head_sha: commitSha,
|
|
90
|
-
check_run_id: check.id,
|
|
91
93
|
...(status ? { status } : {}),
|
|
92
94
|
...(conclusion ? { conclusion } : {}),
|
|
93
95
|
output: {
|
|
@@ -97,36 +99,40 @@ export const startGithubCheckRun = async ({
|
|
|
97
99
|
},
|
|
98
100
|
},
|
|
99
101
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
logger.debug(`${UNICODE.OK} check updated`);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
logger.error(
|
|
105
|
+
createDetailedMessage(`${UNICODE.FAILURE} failed to update check`, {
|
|
106
|
+
"error stack": e.stack,
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (status) {
|
|
112
|
+
checkStatus = status;
|
|
113
|
+
}
|
|
114
|
+
if (title) {
|
|
115
|
+
checkTitle = title;
|
|
116
|
+
}
|
|
117
|
+
if (summary) {
|
|
118
|
+
checkSummary = summary;
|
|
119
|
+
}
|
|
109
120
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
annotations: annotationsBatch,
|
|
121
|
-
},
|
|
121
|
+
annotationsSent += annotationsBatch.length;
|
|
122
|
+
while (annotationsSent < annotations.length) {
|
|
123
|
+
const annotationsBatch = annotations.slice(annotationsSent, 50);
|
|
124
|
+
await PATCH({
|
|
125
|
+
url: check.url,
|
|
126
|
+
githubToken,
|
|
127
|
+
body: {
|
|
128
|
+
head_sha: commitSha,
|
|
129
|
+
output: {
|
|
130
|
+
annotations: annotationsBatch,
|
|
122
131
|
},
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
previousUpdatePromise = null;
|
|
128
|
-
})();
|
|
129
|
-
return previousUpdatePromise;
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
annotationsSent += annotationsBatch.length;
|
|
135
|
+
}
|
|
130
136
|
};
|
|
131
137
|
|
|
132
138
|
let lastProgressCall;
|