Skip to content

Commit b8a3069

Browse files
committed
Limit issue creation to one per bad image, rather than one per affected extension
1 parent 3b90da1 commit b8a3069

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.idea/workspace.xml
22
.idea/checkstyle-idea.xml
33

4+
site-validation/.idea/
5+
site-validation/site-validation.iml
6+
47
bad-image-check-results.json
58

69
# Logs

gatsby-node.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { rewriteGuideUrl } = require("./src/components/util/guide-url-rewriter")
1313
const ESLintPlugin = require("eslint-webpack-plugin")
1414
const { validate } = require("./src/data/image-validation")
1515
const fs = require("fs/promises")
16-
let badImages = []
16+
let badImages = { }
1717

1818
exports.sourceNodes = async ({
1919
actions,
@@ -111,7 +111,13 @@ exports.sourceNodes = async ({
111111
if (!isValid || isGitHubBlobPage) {
112112
console.warn("Not a valid image in", node.artifact, ". Image link is:", iconUrl)
113113
delete node.metadata.icon
114-
badImages.push({ url: iconUrl, artifact: node.artifact })
114+
if (badImages[iconUrl]) {
115+
badImages[iconUrl].artifacts.push(node.artifact)
116+
badImages[iconUrl].slugs.push(node.slug)
117+
} else {
118+
badImages[iconUrl] = { url: iconUrl, reason: "Invalid", slugs: [node.slug], artifacts: [node.artifact] }
119+
}
120+
115121
} else {
116122
try {
117123
await createRemoteFileNode({
@@ -307,10 +313,11 @@ exports.onCreateWebpackConfig = ({ stage, actions }) => {
307313
}
308314

309315
exports.onPostBootstrap = async () => {
316+
const badImageDetails = Object.values(badImages);
310317
// Write out to a file
311-
if (badImages?.length > 0) {
312-
console.warn(`Recording details of ${badImages.length} bad images.`)
313-
const content = JSON.stringify(badImages)
318+
if (badImageDetails?.length > 0) {
319+
console.warn(`Recording details of ${badImageDetails.length} bad images.`)
320+
const content = JSON.stringify(badImageDetails)
314321
const resultsFile = "bad-image-check-results.json"
315322
await fs.writeFile(resultsFile, content, { flag: "w+" }, err => {
316323
console.warn("Error writing results:", err)

site-validation/bad-image-issue.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Arrays;
2727
import java.util.List;
2828
import java.util.Collections;
29+
import java.util.stream.Collectors;
2930

3031
@Command(name = "report", mixinStandardHelpOptions = true,
3132
description = "Raises and closes issues depending on the results of bad image checking")
@@ -118,6 +119,9 @@ private void closeResolvedIssues(GitHub github, List<BadImage> links) throws IOE
118119
}
119120
}
120121

122+
private String getOwningPages(String[] slugs) {
123+
return Arrays.stream(slugs).map(slug -> siteUrl + "/" + slug).collect(Collectors.joining("\n - "));
124+
}
121125

122126
private void processBadImage(GitHub github, BadImage link) {
123127
try {
@@ -135,18 +139,19 @@ private void processBadImage(GitHub github, BadImage link) {
135139

136140
// If there's no matching defect ...
137141
if (answer.getTotalCount() == 0) {
138-
String title = String.format("Invalid image: %s", link.url);
139-
// Eventually, we would like to customise the message depending on the exact nature of the broken link.
140-
// For now, just do something generic.
142+
String title = String.format("%s image: %s", link.reason, link.url);
141143
String body = String.format("""
142-
Invalid image: %s
144+
%s image: %s
143145
144-
The problem image was found on %s
146+
The problem image was found on these artifacts: %s
147+
148+
Affected pages are
149+
- %s
145150
146151
This issue was auto-created by the bad image helper.
147152
148153
--- %s --- Do not remove this line or the bad image helper will not be able to manage this issue
149-
""", link.url, link.artifact, EYECATCHER);
154+
""", link.reason, link.url, Arrays.toString(link.artifacts), getOwningPages(link.slugs), EYECATCHER);
150155

151156
if (!dryRun) {
152157
GHIssue issue = repository.createIssue(title)
@@ -193,6 +198,8 @@ public static void main(String... args) {
193198

194199
record BadImage(
195200
String url,
196-
String artifact) {
201+
String reason,
202+
String[] artifacts,
203+
String[] slugs) {
197204
}
198205
}

0 commit comments

Comments
 (0)