Skip to content

Commit 980182e

Browse files
committed
fix: conflict issue truncation
1 parent ee7f2a3 commit 980182e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

client/utils/createIssueLink.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const GITHUB_ISSUES_URL =
33
? 'https://github.com/w3c/aria-at'
44
: 'https://github.com/bocoup/aria-at';
55

6+
// Maximum URL length for GitHub issues
7+
// Tested on multiple browsers and devices
8+
const MAX_GITHUB_URL_LENGTH = 8000;
9+
610
// TODO: Use At.key
711
const atLabelMap = {
812
'VoiceOver for macOS': 'vo',
@@ -183,10 +187,26 @@ const createIssueLink = ({
183187
body += `\n${conflictMarkdown}`;
184188
}
185189

186-
return (
187-
`${GITHUB_ISSUES_URL}/issues/new?title=${encodeURI(title)}&` +
188-
`labels=${labels}&body=${encodeURIComponent(body)}`
189-
);
190+
let url = `${GITHUB_ISSUES_URL}/issues/new?title=${encodeURI(
191+
title
192+
)}&labels=${labels}&body=${encodeURIComponent(body)}`;
193+
194+
// This code assumes that URLs can only become too long with conflict markdown present
195+
if (conflictMarkdown && url.length > MAX_GITHUB_URL_LENGTH) {
196+
// If URL is too long, truncate the conflict markdown section
197+
const truncationMessage = `\n\n[Content truncated due to URL length limits. Please visit [${window.location}](${window.location}) and click "Review Conflicts" to review the full conflict information.]`;
198+
const maxBodyLength = Math.floor(
199+
MAX_GITHUB_URL_LENGTH -
200+
(url.length - body.length) -
201+
truncationMessage.length
202+
);
203+
body = body.slice(0, maxBodyLength) + truncationMessage;
204+
url = `${GITHUB_ISSUES_URL}/issues/new?title=${encodeURI(
205+
title
206+
)}&labels=${labels}&body=${encodeURIComponent(body)}`;
207+
}
208+
209+
return url;
190210
};
191211

192212
/**

0 commit comments

Comments
 (0)