| 18 | export default class Webhook { |
| 19 | #webhook |
| 20 | constructor(webhook) { |
| 21 | this.#webhook = webhook |
| 22 | this.descriptionHtml = '' |
| 23 | this.summaryHtml = '' |
| 24 | this.bodyParameters = [] |
| 25 | this.availability = webhook['x-github']['supported-webhook-types'] |
| 26 | this.action = get( |
| 27 | webhook, |
| 28 | `requestBody.content['application/json'].schema.properties.action.enum[0]`, |
| 29 | null |
| 30 | ) |
| 31 | |
| 32 | // for some webhook action types (like some pull-request webhook types) the |
| 33 | // schema properties are under a oneOf so we try and take the action from |
| 34 | // the first one (the action will be the same across oneOf items) |
| 35 | if (!this.action) { |
| 36 | this.action = get( |
| 37 | webhook, |
| 38 | `requestBody.content['application/json'].schema.oneOf[0].properties.action.enum[0]`, |
| 39 | null |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | // The OpenAPI uses hyphens for the webhook names, but the webhooks |
| 44 | // are sent using underscores (e.g. `branch_protection_rule` instead |
| 45 | // of `branch-protection-rule`) |
| 46 | this.category = webhook['x-github'].subcategory.replaceAll('-', '_') |
| 47 | return this |
| 48 | } |
| 49 | |
| 50 | async process() { |
| 51 | await Promise.all([this.renderDescription(), this.renderBodyParameterDescriptions()]) |