Skip to content

Commit 8cfae30

Browse files
Copilotpelikhan
andcommitted
fix: centralize candidate pattern, remove core guard, add word boundaries
- Extract TEMPORARY_ID_CANDIDATE_PATTERN as a module-level constant next to TEMPORARY_ID_PATTERN (with word boundary \b at end) - Remove typeof core guard — core is always defined via shim.cjs - Reset lastIndex before using the global regex in replaceTemporaryIdReferences Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 372783f commit 8cfae30

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

actions/setup/js/temporary_id.cjs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const crypto = require("crypto");
2929
*/
3030
const TEMPORARY_ID_PATTERN = /#(aw_[A-Za-z0-9]{3,8})/gi;
3131

32+
/**
33+
* Regex pattern for detecting candidate #aw_ references (any length, word-boundary delimited)
34+
* Used to identify malformed temporary ID references that don't match TEMPORARY_ID_PATTERN
35+
*/
36+
const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9]+)\b/gi;
37+
3238
/**
3339
* @typedef {Object} RepoIssuePair
3440
* @property {string} repo - Repository slug in "owner/repo" format
@@ -81,14 +87,12 @@ function normalizeTemporaryId(tempId) {
8187
*/
8288
function replaceTemporaryIdReferences(text, tempIdMap, currentRepo) {
8389
// Detect and warn about malformed #aw_ references that won't be resolved
84-
if (typeof core !== "undefined") {
85-
const candidatePattern = /#aw_([A-Za-z0-9]+)/gi;
86-
let candidate;
87-
while ((candidate = candidatePattern.exec(text)) !== null) {
88-
const tempId = `aw_${candidate[1]}`;
89-
if (!isTemporaryId(tempId)) {
90-
core.warning(`Malformed temporary ID reference '${candidate[0]}' found in body text. Temporary IDs must be in format '#aw_' followed by 3 to 8 alphanumeric characters (A-Za-z0-9). Example: '#aw_abc' or '#aw_Test123'`);
91-
}
90+
let candidate;
91+
TEMPORARY_ID_CANDIDATE_PATTERN.lastIndex = 0;
92+
while ((candidate = TEMPORARY_ID_CANDIDATE_PATTERN.exec(text)) !== null) {
93+
const tempId = `aw_${candidate[1]}`;
94+
if (!isTemporaryId(tempId)) {
95+
core.warning(`Malformed temporary ID reference '${candidate[0]}' found in body text. Temporary IDs must be in format '#aw_' followed by 3 to 8 alphanumeric characters (A-Za-z0-9). Example: '#aw_abc' or '#aw_Test123'`);
9296
}
9397
}
9498

@@ -539,6 +543,7 @@ function getCreatedTemporaryId(message) {
539543

540544
module.exports = {
541545
TEMPORARY_ID_PATTERN,
546+
TEMPORARY_ID_CANDIDATE_PATTERN,
542547
generateTemporaryId,
543548
isTemporaryId,
544549
normalizeTemporaryId,

0 commit comments

Comments
 (0)