From 55b494598dd49ef81505753321a86d218b053f1d Mon Sep 17 00:00:00 2001 From: Colin Loretz Date: Tue, 5 Nov 2024 09:52:11 -0800 Subject: [PATCH] Fix changelog link checker + changelog links (#7254) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * checkLinks: use frontmatter for changelog anchors * Fix entitlement migration links * link to 'in preview' no longer relevant * Tables 🙃 --- ...ser-installed-apps-general-availability.md | 2 +- ...-updates-to-entitlement-migration-guide.md | 2 +- docs/events/Gateway_Events.mdx | 2 +- .../Implementing_App_Subscriptions.mdx | 6 +++--- docs/resources/Message.md | 2 +- package-lock.json | 9 ++++++++- package.json | 2 ++ tools/checkLinks.ts | 19 ++++++++++++++++++- 8 files changed, 35 insertions(+), 9 deletions(-) diff --git a/docs/change_log/2024-06-27-user-installed-apps-general-availability.md b/docs/change_log/2024-06-27-user-installed-apps-general-availability.md index 9f99bca560..59b1a9fb75 100644 --- a/docs/change_log/2024-06-27-user-installed-apps-general-availability.md +++ b/docs/change_log/2024-06-27-user-installed-apps-general-availability.md @@ -4,7 +4,7 @@ date: "2024-06-27" breaking: true --- -Back in March, we announced [the beta for user-installed apps](#DOCS_CHANGE_LOG/user-installable-apps-preview). After listening and making updates based on feedback from developers and modmins, we're excited to announce that user-installed apps are now considered generally available and can be used in all servers (regardless of size). +Back in March, we announced [the beta for user-installed apps](#DOCS_CHANGE_LOG/userinstallable-apps-preview). After listening and making updates based on feedback from developers and modmins, we're excited to announce that user-installed apps are now considered generally available and can be used in all servers (regardless of size). With this update, there are a few API and behavioral updates for user-installed apps. diff --git a/docs/change_log/2024-10-04-updates-to-entitlement-migration-guide.md b/docs/change_log/2024-10-04-updates-to-entitlement-migration-guide.md index 3e8ca5bbd1..eb6f592b83 100644 --- a/docs/change_log/2024-10-04-updates-to-entitlement-migration-guide.md +++ b/docs/change_log/2024-10-04-updates-to-entitlement-migration-guide.md @@ -15,6 +15,6 @@ We updated our previous entitlement migration guide to provide more up-to-date i - The `ends_at` value on the [entitlement object](#DOCS_RESOURCES_ENTITLEMENT/entitlement-object) is set when the subscription ends. - To receive the value of when a subscription was canceled, you should listen for the `SUBSCRIPTION_UPDATE` events or use the [Subscription API](#DOCS_RESOURCES_SUBSCRIPTION). -View the [updated migration guide](#DOCS_CHANGE_LOG/subscription-api-and-entitlement-migration). +View the [updated migration guide](#DOCS_CHANGE_LOG/premium-apps-entitlement-migration-and-new-subscription-api). To see a full diff of the changes, refer to this pull request: [Entitlement Migration Guide Updates](https://github.com/discord/discord-api-docs/pull/7201). \ No newline at end of file diff --git a/docs/events/Gateway_Events.mdx b/docs/events/Gateway_Events.mdx index b693ee34eb..a879609849 100644 --- a/docs/events/Gateway_Events.mdx +++ b/docs/events/Gateway_Events.mdx @@ -592,7 +592,7 @@ Sent when an entitlement is created. The inner payload is an [entitlement](#DOCS #### Entitlement Update > danger -> Starting on October 1, 2024, the `ENTITLEMENT_UPDATE` event behavior will be changing. You will no longer receive an `ENTITLEMENT_UPDATE` event on successful renewal When a user cancels, you will receive an `ENTITLEMENT_UPDATE` events with an `ends_at` value when the subscription ends. See the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/subscription-api-and-entitlement-migration) for more information. +> Starting on October 1, 2024, the `ENTITLEMENT_UPDATE` event behavior will be changing. You will no longer receive an `ENTITLEMENT_UPDATE` event on successful renewal When a user cancels, you will receive an `ENTITLEMENT_UPDATE` events with an `ends_at` value when the subscription ends. See the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/premium-apps-entitlement-migration-and-new-subscription-api) for more information. Sent when an entitlement is updated. The inner payload is an [entitlement](#DOCS_RESOURCES_ENTITLEMENT/entitlement-object) object. diff --git a/docs/monetization/Implementing_App_Subscriptions.mdx b/docs/monetization/Implementing_App_Subscriptions.mdx index d588e96b61..1f09bde6a3 100644 --- a/docs/monetization/Implementing_App_Subscriptions.mdx +++ b/docs/monetization/Implementing_App_Subscriptions.mdx @@ -19,7 +19,7 @@ When creating subscriptions, you will need to choose between user or guild subsc ## How App Subscriptions Work > danger -> **Starting on October 1st, 2024**, the`ENTITLEMENT_CREATE` and `ENTITLEMENT_UPDATE` event behavior described below is changing. Please see the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/subscription-api-and-entitlement-migration) for more information on what is changing and how to prepare. +> **Starting on October 1st, 2024**, the`ENTITLEMENT_CREATE` and `ENTITLEMENT_UPDATE` event behavior described below is changing. Please see the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/premium-apps-entitlement-migration-and-new-subscription-api) for more information on what is changing and how to prepare. - When a user purchases your subscription SKU, Discord creates an [Entitlement](#DOCS_RESOURCES_ENTITLEMENT) for the user (or guild) and that specific Subscription [SKU](#DOCS_RESOURCES_SKU). - You will receive an `ENTITLEMENT_CREATE` event via the Gateway. @@ -39,7 +39,7 @@ When creating subscriptions, you will need to choose between user or guild subsc - When a user cancels their subscription, your app will not receive any entitlement events. - When a subscription ends, the entitlement to the subscription will end. Developers will receive an `ENTITLEMENT_UPDATE` event with an `ends_at` timestamp indicating when the subscription ended. - Please see the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/subscription-api-and-entitlement-migration) for more information on what is changing and how to prepare. + Please see the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/premium-apps-entitlement-migration-and-new-subscription-api) for more information on what is changing and how to prepare. ### Using Subscription Events for the Subscription Lifecycle @@ -73,7 +73,7 @@ Depending on your app's features, you can use a combination of [Gateway events]( ### Accessing Entitlements with Gateway Events > danger -> **Starting on October 1, 2024**, the `ENTITLEMENT_CREATE` and `ENTITLEMENT_UPDATE` event behavior described below is changing. Please see the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/subscription-api-and-entitlement-migration) for more information on what is changing and how to prepare. The docs will be updated on November 1, 2024 to reflect the new behavior. +> **Starting on October 1, 2024**, the `ENTITLEMENT_CREATE` and `ENTITLEMENT_UPDATE` event behavior described below is changing. Please see the [Change Log and Entitlement Migration Guide](#DOCS_CHANGE_LOG/premium-apps-entitlement-migration-and-new-subscription-api) for more information on what is changing and how to prepare. The docs will be updated on November 1, 2024 to reflect the new behavior. When users subscribe or renew a subscription with your app, Discord will emit [Entitlement Gateway events](#DOCS_EVENTS_GATEWAY_EVENTS/entitlements). diff --git a/docs/resources/Message.md b/docs/resources/Message.md index 4681808d91..1adcbe0f83 100644 --- a/docs/resources/Message.md +++ b/docs/resources/Message.md @@ -43,7 +43,7 @@ Represents a message sent in a channel within Discord. | message_reference? | [message reference](#DOCS_RESOURCES_MESSAGE/message-reference-structure) object | data showing the source of a crosspost, channel follow add, pin, or reply message | | message_snapshots? \[5\] | array of [message snapshot](#DOCS_RESOURCES_MESSAGE/message-snapshot-object) objects | the message associated with the `message_reference`. This is a minimal subset of fields in a message (e.g. `author` is excluded.) | | referenced_message? \[4\] | ?[message object](#DOCS_RESOURCES_MESSAGE/message-object) | the message associated with the message_reference | -| interaction_metadata? | [message interaction metadata object](#DOCS_RESOURCES_MESSAGE/message-interaction-metadata-object) | [In preview](#DOCS_CHANGE_LOG/user-installable-apps-preview). Sent if the message is sent as a result of an [interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/) | +| interaction_metadata? | [message interaction metadata object](#DOCS_RESOURCES_MESSAGE/message-interaction-metadata-object) | Sent if the message is sent as a result of an [interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/) | | interaction? | [message interaction object](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/message-interaction-object-message-interaction-structure) | **Deprecated in favor of `interaction_metadata`**; sent if the message is a response to an [interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/) | | thread? | [channel](#DOCS_RESOURCES_CHANNEL/channel-object) object | the thread that was started from this message, includes [thread member](#DOCS_RESOURCES_CHANNEL/thread-member-object) object | | components? \[2\] | array of [message components](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/component-object) | sent if the message contains components like buttons, action rows, or other interactive components | diff --git a/package-lock.json b/package-lock.json index 8d704df0bd..d379cdcf65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,11 +13,13 @@ "@eslint/js": "^9.2.0", "@mdx-js/mdx": "^3.0.1", "@mdx-js/react": "^3.0.1", + "@types/js-yaml": "^4.0.9", "@types/node": "^20.12.12", "chalk": "^5.3.0", "eslint": "^9.2.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", + "js-yaml": "^4.1.0", "markdown-table-formatter": "^1.6.0", "mdast-util-from-markdown": "^2.0.1", "mdast-util-to-markdown": "^2.1.0", @@ -372,6 +374,12 @@ "@types/unist": "*" } }, + "node_modules/@types/js-yaml": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz", + "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1854,7 +1862,6 @@ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, - "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, diff --git a/package.json b/package.json index 537836781f..f3cdce21e2 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,13 @@ "@eslint/js": "^9.2.0", "@mdx-js/mdx": "^3.0.1", "@mdx-js/react": "^3.0.1", + "@types/js-yaml": "^4.0.9", "@types/node": "^20.12.12", "chalk": "^5.3.0", "eslint": "^9.2.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", + "js-yaml": "^4.1.0", "markdown-table-formatter": "^1.6.0", "mdast-util-from-markdown": "^2.0.1", "mdast-util-to-markdown": "^2.1.0", diff --git a/tools/checkLinks.ts b/tools/checkLinks.ts index d7d289c4bf..089ce04503 100644 --- a/tools/checkLinks.ts +++ b/tools/checkLinks.ts @@ -2,8 +2,15 @@ import { readdirSync, statSync, readFileSync } from "node:fs"; import path from "node:path"; import chalk from "chalk"; import * as github from "@actions/core"; +import * as yaml from "js-yaml"; const cwd = process.env.GITHUB_ACTIONS ? process.env.GITHUB_WORKSPACE! : process.cwd(); +interface Frontmatter { + title?: string; + date?: string; + breaking: boolean; +} + function importDirectory(directory: string, extensions: string[], subdirectories = true) { try { const output = new Map(); @@ -110,7 +117,17 @@ for (const [name, raw] of docFiles) { // This collects all potential change-log pages, and adds them to the list of // available anchors under `/change_log`. if (name.startsWith("/change_log/")) { - changelogAnchors.push(name.split("/")[2].slice(11)); + const frontmatter = raw.split("---")[1]; + const parsedFrontmatter = yaml.load(frontmatter) as Frontmatter; + const title = parsedFrontmatter?.title; + if (title) { + const anchor = title + .replace(/[^ A-Z0-9]/gi, "") + .trim() + .replace(/ +/g, "-") + .toLowerCase(); + changelogAnchors.push(anchor); + } } let parentAnchor = "";