mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 01:30:10 +08:00
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import { createAppAuth } from "@octokit/auth-app";
|
|
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
|
|
import { Webhooks } from "@octokit/webhooks";
|
|
function webhooks(appOctokit, options) {
|
|
return new Webhooks({
|
|
secret: options.secret,
|
|
transform: async (event) => {
|
|
if (!("installation" in event.payload) || typeof event.payload.installation !== "object") {
|
|
const octokit2 = new appOctokit.constructor({
|
|
authStrategy: createUnauthenticatedAuth,
|
|
auth: {
|
|
reason: `"installation" key missing in webhook event payload`
|
|
}
|
|
});
|
|
return {
|
|
...event,
|
|
octokit: octokit2
|
|
};
|
|
}
|
|
const installationId = event.payload.installation.id;
|
|
const octokit = await appOctokit.auth({
|
|
type: "installation",
|
|
installationId,
|
|
factory(auth) {
|
|
return new auth.octokit.constructor({
|
|
...auth.octokitOptions,
|
|
authStrategy: createAppAuth,
|
|
...{
|
|
auth: {
|
|
...auth,
|
|
installationId
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
octokit.hook.before("request", (options2) => {
|
|
options2.headers["x-github-delivery"] = event.id;
|
|
});
|
|
return {
|
|
...event,
|
|
octokit
|
|
};
|
|
}
|
|
});
|
|
}
|
|
export {
|
|
webhooks
|
|
};
|