Skip to content

Commit bf2a8a1

Browse files
Copilotpelikhan
andauthored
fix: address review comments — fix candidate pattern for hyphens, use shared helper in create_pull_request
- TEMPORARY_ID_CANDIDATE_PATTERN now uses [A-Za-z0-9_-]+ (no \b) so #aw_test-id captures the full token 'test-id' instead of just 'test', triggering a warning as expected - create_pull_request.cjs now uses getOrGenerateTemporaryId() shared helper instead of duplicating the validation/fallback logic - Added test for hyphen-containing malformed temp ID reference Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a6bd2d2f-d14b-45b6-b5aa-61ea6b64360c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 2c6713f commit bf2a8a1

3 files changed

Lines changed: 21 additions & 27 deletions

File tree

actions/setup/js/create_pull_request.cjs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { getTrackerID } = require("./get_tracker_id.cjs");
1111
const { removeDuplicateTitleFromDescription } = require("./remove_duplicate_title.cjs");
1212
const { sanitizeTitle, applyTitlePrefix } = require("./sanitize_title.cjs");
1313
const { getErrorMessage } = require("./error_helpers.cjs");
14-
const { replaceTemporaryIdReferences, isTemporaryId, generateTemporaryId } = require("./temporary_id.cjs");
14+
const { replaceTemporaryIdReferences, getOrGenerateTemporaryId } = require("./temporary_id.cjs");
1515
const { resolveTargetRepoConfig, resolveAndValidateRepo } = require("./repo_helpers.cjs");
1616
const { addExpirationToFooter } = require("./ephemerals.cjs");
1717
const { generateWorkflowIdMarker } = require("./generate_footer.cjs");
@@ -247,30 +247,12 @@ async function main(config = {}) {
247247

248248
const pullRequestItem = message;
249249

250-
let temporaryId;
251-
if (pullRequestItem.temporary_id !== undefined && pullRequestItem.temporary_id !== null) {
252-
if (typeof pullRequestItem.temporary_id !== "string") {
253-
core.warning(`Skipping create_pull_request: temporary_id must be a string (got ${typeof pullRequestItem.temporary_id})`);
254-
return {
255-
success: false,
256-
error: `temporary_id must be a string (got ${typeof pullRequestItem.temporary_id})`,
257-
};
258-
}
259-
260-
const rawTemporaryId = pullRequestItem.temporary_id.trim();
261-
const normalized = rawTemporaryId.startsWith("#") ? rawTemporaryId.substring(1).trim() : rawTemporaryId;
262-
263-
if (!isTemporaryId(normalized)) {
264-
// Warn and auto-generate rather than failing - an invalid temporary_id is a minor issue
265-
const autoGenerated = generateTemporaryId();
266-
core.warning(
267-
`Invalid temporary_id format: '${pullRequestItem.temporary_id}'. Temporary IDs must be in format 'aw_' followed by 3 to 12 alphanumeric or underscore characters (A-Za-z0-9_). Example: 'aw_abc' or 'aw_pr_fix'. Using auto-generated ID: '${autoGenerated}'`
268-
);
269-
temporaryId = autoGenerated;
270-
} else {
271-
temporaryId = normalized.toLowerCase();
272-
}
250+
const tempIdResult = getOrGenerateTemporaryId(pullRequestItem, "pull request");
251+
if (tempIdResult.error) {
252+
core.warning(`Skipping create_pull_request: ${tempIdResult.error}`);
253+
return { success: false, error: tempIdResult.error };
273254
}
255+
const temporaryId = tempIdResult.temporaryId;
274256

275257
core.info(`Processing create_pull_request: title=${pullRequestItem.title || "No title"}, bodyLength=${pullRequestItem.body?.length || 0}`);
276258

actions/setup/js/temporary_id.cjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ const crypto = require("crypto");
3030
const TEMPORARY_ID_PATTERN = /#(aw_[A-Za-z0-9_]{3,12})\b/gi;
3131

3232
/**
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
33+
* Regex pattern for detecting candidate #aw_ references (any alphanumeric, underscore, or hyphen content)
34+
* Used to identify malformed temporary ID references that don't match TEMPORARY_ID_PATTERN.
35+
* Uses a broader character set (including hyphens) than the valid pattern to capture the full token
36+
* and warn about references like #aw_test-id where the hyphen makes the whole token invalid.
3537
*/
36-
const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9_]+)\b/gi;
38+
const TEMPORARY_ID_CANDIDATE_PATTERN = /#aw_([A-Za-z0-9_-]+)/gi;
3739

3840
/**
3941
* @typedef {Object} RepoIssuePair

actions/setup/js/temporary_id.test.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ describe("temporary_id.cjs", () => {
177177
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("#aw_ab"));
178178
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("#aw_toolongname123"));
179179
});
180+
181+
it("should warn about malformed temporary ID reference containing a hyphen", async () => {
182+
const { replaceTemporaryIdReferences } = await import("./temporary_id.cjs");
183+
const map = new Map();
184+
const text = "Check #aw_test-id for details";
185+
const result = replaceTemporaryIdReferences(text, map, "owner/repo");
186+
expect(result).toBe("Check #aw_test-id for details");
187+
expect(mockCore.warning).toHaveBeenCalledOnce();
188+
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("#aw_test-id"));
189+
});
180190
});
181191

182192
describe("getOrGenerateTemporaryId", () => {

0 commit comments

Comments
 (0)