MCPcopy Create free account
hub / github.com/alibaba/open-code-review / makeGithub

Function makeGithub

scripts/github-actions/post-review-comments.test.js:103–403  ·  view source on GitHub ↗
(opts = {})

Source from the content-addressed store, hash-verified

101}
102
103function makeGithub(opts = {}) {
104 const createReviewCalls = [];
105 const issueComments = [];
106 const updatedComments = [];
107 const listCommentsCalls = [];
108 const listReviewCommentsCalls = [];
109 const listReviewsCalls = [];
110 const listFilesCalls = [];
111 const getPullCalls = [];
112 // Interleaved log of write operations (createReview / createComment /
113 // updateComment) in call order, so tests can assert positioning invariants
114 // such as "summary created before review" without timing the calls.
115 const ops = [];
116 // Per-comment attempt counter, keyed by commentKey, so perCommentError can be
117 // attempt-aware (e.g. "429 on attempt 0, succeed on attempt 1").
118 const perCommentAttempts = new Map();
119
120 function successRemaining() {
121 return opts.successRemaining != null ? String(opts.successRemaining) : "5000";
122 }
123
124 // Inline comment objects recorded in BATCH createReview calls only, so tests
125 // can simulate "this comment already landed on the server" without predicting
126 // the random IDs from newCommentId(). Under multi-batch (N < toSend.length)
127 // there are several batch calls (body === REVIEW_TAG), so this scans ALL batch
128 // calls — not just createReviewCalls[0]. Scoped to batch calls so batch-level
129 // landing (echoPosted) stays disjoint from per-comment landing (landedKeys,
130 // which reads per-comment calls with body === "").
131 function batchPostedComments() {
132 const out = [];
133 for (const call of createReviewCalls) {
134 if ((call.body || "") !== REVIEW_TAG) continue;
135 for (const c of call.comments || []) {
136 const m = /<!--\s*(ocr-\d+-\d+-[a-f0-9]+)\s*-->/.exec(c.body || "");
137 if (m) {
138 out.push({
139 path: c.path,
140 body: c.body,
141 side: c.side || "RIGHT",
142 start_line: c.start_line,
143 line: c.line,
144 });
145 }
146 }
147 }
148 return out;
149 }
150
151 // Count of batch createReview calls issued so far (body === REVIEW_TAG), so a
152 // per-batch-index error spec can target e.g. "fail batch #2 but not #1".
153 function batchCallCount() {
154 let n = 0;
155 for (const call of createReviewCalls) {
156 if ((call.body || "") === REVIEW_TAG) n++;
157 }
158 return n;
159 }
160

Calls 8

batchCallCountFunction · 0.85
makeErrFunction · 0.85
successResFunction · 0.85
commentKeyFunction · 0.85
batchPostedCommentsFunction · 0.85
addFunction · 0.70
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected