* Build a minimal event payload from aw_context metadata for centralized slash-command dispatches. * @param {Record } awContext * @param {string} eventName * @returns {Record |null}
(awContext, eventName)
| 114 | * @returns {Record<string, any>|null} |
| 115 | */ |
| 116 | function buildPayloadFromAwContext(awContext, eventName) { |
| 117 | const itemType = typeof awContext.item_type === "string" ? awContext.item_type : ""; |
| 118 | const itemNumberRaw = awContext.item_number; |
| 119 | const commentIdRaw = awContext.comment_id; |
| 120 | const commentNodeId = typeof awContext.comment_node_id === "string" ? awContext.comment_node_id : ""; |
| 121 | const itemNumber = Number(itemNumberRaw); |
| 122 | const commentId = Number(commentIdRaw); |
| 123 | |
| 124 | if (!itemType || !Number.isFinite(itemNumber) || itemNumber <= 0) { |
| 125 | return null; |
| 126 | } |
| 127 | |
| 128 | /** @type {Record<string, any>} */ |
| 129 | const payload = {}; |
| 130 | |
| 131 | if (itemType === "issue") { |
| 132 | payload.issue = { number: itemNumber }; |
| 133 | } else if (itemType === "pull_request") { |
| 134 | payload.pull_request = { number: itemNumber }; |
| 135 | if (eventName === "issue_comment") { |
| 136 | payload.issue = { number: itemNumber, pull_request: {} }; |
| 137 | } |
| 138 | } else if (itemType === "discussion") { |
| 139 | payload.discussion = { number: itemNumber }; |
| 140 | } |
| 141 | |
| 142 | if (Number.isFinite(commentId) && commentId > 0) { |
| 143 | payload.comment = { id: commentId }; |
| 144 | if (commentNodeId) { |
| 145 | payload.comment.node_id = commentNodeId; |
| 146 | } |
| 147 | } else if (commentNodeId) { |
| 148 | payload.comment = { node_id: commentNodeId }; |
| 149 | } |
| 150 | |
| 151 | return Object.keys(payload).length > 0 ? payload : null; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Validate workflow_dispatch target repository against allowlist configuration. |
no outgoing calls
no test coverage detected