| 166 | } |
| 167 | |
| 168 | async function createStaticWebhookFiles(webhookSchemas) { |
| 169 | if (!Object.keys(webhookSchemas).length) { |
| 170 | console.log( |
| 171 | '🟡 No webhooks exist in the dereferenced files. No static webhook files will be generated.\n' |
| 172 | ) |
| 173 | return |
| 174 | } |
| 175 | // Create a map of webhooks (e.g. check_run, issues, release) to the |
| 176 | // webhook's actions (e.g. created, deleted, etc.). |
| 177 | // |
| 178 | // Some webhooks like the ping webhook have no action types -- in cases |
| 179 | // like this we set a default action of 'default'. |
| 180 | // |
| 181 | // Example: |
| 182 | /* |
| 183 | { |
| 184 | 'branch-protection-rule': { |
| 185 | created: Webhook { |
| 186 | descriptionHtml: '<p>A branch protection rule was created.</p>', |
| 187 | summaryHtml: '<p>This event occurs when there is activity relating to branch protection rules. For more information, see "<a href="https://docs.github.com/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches">About protected branches</a>." For information about the Branch protection APIs, see <a href="https://docs.github.com/graphql/reference/objects#branchprotectionrule">the GraphQL documentation</a> and <a href="https://docs.github.com/rest/branches/branch-protection">the REST API documentation</a>.</p>\n' + |
| 188 | '<p>In order to install this event on a GitHub App, the app must have <code>read-only</code> access on repositories administration.</p>', |
| 189 | bodyParameters: [Array], |
| 190 | availability: [Array], |
| 191 | action: 'created', |
| 192 | category: 'branch-protection-rule' |
| 193 | }, |
| 194 | deleted: Webhook { |
| 195 | descriptionHtml: '<p>A branch protection rule was deleted.</p>', |
| 196 | summaryHtml: '<p>This event occurs when there is activity relating to branch protection rules. For more information, see "<a href="https://docs.github.com/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches">About protected branches</a>." For information about the Branch protection APIs, see <a href="https://docs.github.com/graphql/reference/objects#branchprotectionrule">the GraphQL documentation</a> and <a href="https://docs.github.com/rest/branches/branch-protection">the REST API documentation</a>.</p>\n' + |
| 197 | '<p>In order to install this event on a GitHub App, the app must have <code>read-only</code> access on repositories administration.</p>', |
| 198 | bodyParameters: [Array], |
| 199 | availability: [Array], |
| 200 | action: 'deleted', |
| 201 | category: 'branch-protection-rule' |
| 202 | }, |
| 203 | ... |
| 204 | } |
| 205 | */ |
| 206 | const categorizedWebhooks = {} |
| 207 | for (const [schemaName, webhooks] of Object.entries(webhookSchemas)) { |
| 208 | webhooks.forEach((webhook) => { |
| 209 | if (!webhook.action) webhook.action = 'default' |
| 210 | |
| 211 | if (categorizedWebhooks[webhook.category]) { |
| 212 | categorizedWebhooks[webhook.category][webhook.action] = webhook |
| 213 | } else { |
| 214 | categorizedWebhooks[webhook.category] = {} |
| 215 | categorizedWebhooks[webhook.category][webhook.action] = webhook |
| 216 | } |
| 217 | }) |
| 218 | const webhooksFilename = path |
| 219 | .join(WEBHOOK_DECORATED_DIR, `${schemaName}.json`) |
| 220 | .replace('.deref', '') |
| 221 | if (Object.keys(categorizedWebhooks).length > 0) { |
| 222 | if (!existsSync(WEBHOOK_DECORATED_DIR)) { |
| 223 | mkdirSync(WEBHOOK_DECORATED_DIR) |
| 224 | } |
| 225 | await writeFile(webhooksFilename, JSON.stringify(categorizedWebhooks, null, 2)) |