Skip to content

Commit

Permalink
refactor(update-webhooks): remove classes from elements (#646)
Browse files Browse the repository at this point in the history
This change will remove all the classes from the cached HTML, except for classes which we actually look for in our code in order to extract payload examples

Fixes #642

Co-authored-by: Gareth Jones <Jones258@Gmail.com>
Co-authored-by: Oscar Dominguez <dominguez.celada@gmail.com>
  • Loading branch information
3 people committed Jun 28, 2022
1 parent 4034b69 commit 7560770
Show file tree
Hide file tree
Showing 10 changed files with 17,996 additions and 26,354 deletions.
3,026 changes: 600 additions & 2,426 deletions cache/api.github.com/webhook-events-and-payloads.html

Large diffs are not rendered by default.

13,915 changes: 6,927 additions & 6,988 deletions cache/ghes-221/webhook-events-and-payloads.html

Large diffs are not rendered by default.

17,117 changes: 8,134 additions & 8,983 deletions cache/ghes-222/webhook-events-and-payloads.html

Large diffs are not rendered by default.

2,034 changes: 480 additions & 1,554 deletions cache/ghes-30/webhook-events-and-payloads.html

Large diffs are not rendered by default.

2,094 changes: 467 additions & 1,627 deletions cache/ghes-31/webhook-events-and-payloads.html

Large diffs are not rendered by default.

2,094 changes: 467 additions & 1,627 deletions cache/ghes-32/webhook-events-and-payloads.html

Large diffs are not rendered by default.

2,184 changes: 486 additions & 1,698 deletions cache/ghes-33/webhook-events-and-payloads.html

Large diffs are not rendered by default.

1,835 changes: 413 additions & 1,422 deletions cache/github.ae/webhook-events-and-payloads.html

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion lib/get-html.ts
Expand Up @@ -29,7 +29,28 @@ export const getHtml = async (

// get only the HTML we care about to avoid unnecessary cache updates
$('[data-testid="callout"]').remove();
const html = $("#article-contents").parent().parent().html() ?? "";
const data = $("#article-contents").parent().parent();
// Remove all classes from the HTML, except the ones that are actively used in the code to get payload examples.
// This is done to avoid unnecessary cache updates in order to reduce noise from automated Pull Requests
// https://github.com/octokit/webhooks/issues/642
data.find("*").each((i, el) => {
const classes = $(el).attr("class");

if (classes) {
const filteredClasses = classes
.split(" ")
.filter((classSelector) =>
["language-json", "warning"].includes(classSelector)
);

if (filteredClasses.length) {
$(el).attr("class", filteredClasses.join(" "));
} else {
$(el).removeAttr("class");
}
}
});
const html = data.html() ?? "";

await cache.write(cacheFilePath, prettier.format(html, { parser: "html" }));

Expand Down
28 changes: 0 additions & 28 deletions payload-examples/api.github.com/index.json
Expand Up @@ -56415,34 +56415,6 @@
}
]
},
{
"name": "security_and_analysis",
"description": "Activity related to enabling or disabling code security and analysis features for a repository or organization.",
"properties": {
"changes": {
"type": "object",
"description": "The changes that were made to the code security and analysis features."
},
"repository": {
"type": "object",
"description": "The [`repository`](https://docs.github.com/en/rest/reference/repos#get-a-repository) where the event occurred."
},
"organization": {
"type": "object",
"description": "Webhook payloads contain the [`organization`](https://docs.github.com/en/rest/reference/orgs#get-an-organization) object when the webhook is configured for an organization or the event occurs from activity in a repository owned by an organization."
},
"installation": {
"type": "object",
"description": "The GitHub App installation. Webhook payloads contain the `installation` property when the event is configured for and sent to a GitHub App."
},
"sender": {
"type": "object",
"description": "The user that triggered the event."
}
},
"actions": [],
"examples": []
},
{
"name": "sponsorship",
"description": "Activity related to a sponsorship listing. The type of activity is specified in the `action` property of the payload object. For more information, see \"[About GitHub Sponsors](https://docs.github.com/en/sponsors/getting-started-with-github-sponsors/about-github-sponsors)\".\n\nYou can only create a sponsorship webhook on GitHub. For more information, see \"[Configuring webhooks for events in your sponsored account](https://docs.github.com/en/sponsors/integrating-with-github-sponsors/configuring-webhooks-for-events-in-your-sponsored-account)\".",
Expand Down

0 comments on commit 7560770

Please sign in to comment.