-
Notifications
You must be signed in to change notification settings - Fork 2
/
notify.js
56 lines (48 loc) · 1.62 KB
/
notify.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
import { inspect } from "util";
import core from "@actions/core";
import { App } from "octokit";
main();
async function main() {
try {
const app = new App({
appId: +process.env.GITHUB_APP_ID,
privateKey: process.env.GITHUB_APP_PRIVATE_KEY,
});
const eventType = `all-contributors-import:update`;
const eventPayload = {
startSeq: process.env.START_SEQ,
endSeq: process.env.END_SEQ,
};
core.info(`ℹ️ Repository dispatch event type: "${eventType}"`);
core.debug(
`ℹ️ event client payload: ${inspect(eventPayload, { depth: Infinity })}`
);
const { data: appInfo } = await app.octokit.request("GET /app");
core.info(`ℹ️ Authenticated as ${appInfo.slug} (${appInfo.html_url})`);
await app.eachRepository(async ({ octokit, repository }) => {
const owner = repository.owner.login;
const repoUrl = repository.private
? `${owner}/[private]`
: repository.html_url;
core.debug(`ℹ️ Dispatching event for ${repoUrl} (id: ${repository.id})`);
try {
await octokit.request("POST /repos/{owner}/{repo}/dispatches", {
owner,
repo: repository.name,
event_type: eventType,
client_payload: eventPayload,
});
core.info(
`✅ Event dispatched successfully for ${repoUrl} (id: ${repository.id})`
);
} catch (error) {
core.warning(
`⚠️ Dispatch error: ${inspect(error, { depth: Infinity })}`
);
}
});
} catch (error) {
core.debug(inspect(error, { depth: Infinity }));
core.setFailed(error.message);
}
}