MCPcopy Create free account
hub / github.com/github/gh-aw / parseAwContext

Function parseAwContext

actions/setup/js/push_to_pull_request_branch.cjs:56–89  ·  view source on GitHub ↗

* @param {unknown} rawAwContext * @returns {{ item_type: string, item_number: number | null } | null}

(rawAwContext)

Source from the content-addressed store, hash-verified

54 * @returns {{ item_type: string, item_number: number | null } | null}
55 */
56function parseAwContext(rawAwContext) {
57 /**
58 * @param {unknown} parsed
59 * @returns {{ item_type: string, item_number: number | null } | null}
60 */
61 function validateAndNormalizeParsedContext(parsed) {
62 if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
63 return null;
64 }
65 const parsedObj = /** @type {Record<string, unknown>} */ parsed;
66 const itemTypeValue = parsedObj["item_type"];
67 const itemNumberValue = parsedObj["item_number"];
68 const itemType = typeof itemTypeValue === "string" ? itemTypeValue : "";
69 const itemNumber = parsePositiveInteger(itemNumberValue);
70 return { item_type: itemType, item_number: itemNumber };
71 }
72
73 if (rawAwContext == null) {
74 return null;
75 }
76 if (typeof rawAwContext === "string") {
77 const trimmed = rawAwContext.trim();
78 if (!trimmed) {
79 return null;
80 }
81 try {
82 const parsed = JSON.parse(trimmed);
83 return validateAndNormalizeParsedContext(parsed);
84 } catch {
85 return null;
86 }
87 }
88 return validateAndNormalizeParsedContext(rawAwContext);
89}
90
91/**
92 * Parses a value into a positive integer.

Callers 1

mainFunction · 0.85

Calls 2

parseMethod · 0.45

Tested by

no test coverage detected