(github, owner, repo, itemNumber, memoryID)
| 83 | } |
| 84 | |
| 85 | async function findManagedComment(github, owner, repo, itemNumber, memoryID) { |
| 86 | const newFormatMarker = buildCodeFenceOpener(memoryID); |
| 87 | const legacyMarker = `<${COMMENT_MEMORY_TAG} id="${memoryID}">`; |
| 88 | core.info(`comment_memory: scanning comments for memory_id='${memoryID}' on #${itemNumber} in ${owner}/${repo}`); |
| 89 | let page = 1; |
| 90 | const perPage = 100; |
| 91 | while (page <= COMMENT_MEMORY_MAX_SCAN_PAGES) { |
| 92 | core.info(`comment_memory: scanning page ${page}/${COMMENT_MEMORY_MAX_SCAN_PAGES}`); |
| 93 | const { data } = await github.rest.issues.listComments({ |
| 94 | owner, |
| 95 | repo, |
| 96 | issue_number: itemNumber, |
| 97 | per_page: perPage, |
| 98 | page, |
| 99 | }); |
| 100 | if (!Array.isArray(data) || data.length === 0) { |
| 101 | core.info(`comment_memory: no comments found on page ${page}`); |
| 102 | return null; |
| 103 | } |
| 104 | const match = data.find(comment => { |
| 105 | const body = comment.body; |
| 106 | if (typeof body !== "string") { |
| 107 | return false; |
| 108 | } |
| 109 | if (!body.includes(newFormatMarker) && !body.includes(legacyMarker)) { |
| 110 | return false; |
| 111 | } |
| 112 | return body.includes(MANAGED_COMMENT_PROVENANCE_MARKER); |
| 113 | }); |
| 114 | if (match) { |
| 115 | core.info(`comment_memory: found existing managed comment id=${match.id} on page ${page}`); |
| 116 | return match; |
| 117 | } |
| 118 | if (data.length < perPage) { |
| 119 | core.info(`comment_memory: reached final page ${page} without match`); |
| 120 | return null; |
| 121 | } |
| 122 | page += 1; |
| 123 | } |
| 124 | core.warning(`comment_memory: reached scan limit (${COMMENT_MEMORY_MAX_SCAN_PAGES} pages) without match for memory_id='${memoryID}'`); |
| 125 | return null; |
| 126 | } |
| 127 | |
| 128 | async function main(config = {}) { |
| 129 | const parsedMaxCount = parseInt(String(config.max ?? "1"), 10); |
no test coverage detected