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

Function makeGithub

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

Source from the content-addressed store, hash-verified

82}
83
84function makeGithub(opts = {}) {
85 const createReviewCalls = [];
86 const issueComments = [];
87 const updatedComments = [];
88 const listCommentsCalls = [];
89 const listReviewCommentsCalls = [];
90 const listReviewsCalls = [];
91 // Interleaved log of write operations (createReview / createComment /
92 // updateComment) in call order, so tests can assert positioning invariants
93 // such as "summary created before review" without timing the calls.
94 const ops = [];
95 // Per-comment attempt counter, keyed by commentKey, so perCommentError can be
96 // attempt-aware (e.g. "429 on attempt 0, succeed on attempt 1").
97 const perCommentAttempts = new Map();
98
99 function successRemaining() {
100 return opts.successRemaining != null ? String(opts.successRemaining) : "5000";
101 }
102
103 // Inline comment objects recorded in the BATCH createReview call (index 0)
104 // only, so tests can simulate "this comment already landed on the server"
105 // without predicting the random IDs from newCommentId(). Scoped to the batch
106 // call so batch-level landing (echoPosted) stays disjoint from per-comment
107 // landing (landedKeys, which reads per-comment calls at index >= 1).
108 function batchPostedComments() {
109 const out = [];
110 const call = createReviewCalls[0];
111 if (call) {
112 for (const c of call.comments || []) {
113 const m = /<!--\s*(ocr-\d+-\d+-[a-f0-9]+)\s*-->/.exec(c.body || "");
114 if (m) {
115 out.push({
116 path: c.path,
117 body: c.body,
118 side: c.side || "RIGHT",
119 start_line: c.start_line,
120 line: c.line,
121 });
122 }
123 }
124 }
125 return out;
126 }
127
128 return {
129 createReviewCalls,
130 issueComments,
131 updatedComments,
132 listCommentsCalls,
133 listReviewCommentsCalls,
134 listReviewsCalls,
135 ops,
136 rest: {
137 users: {
138 getAuthenticated: async () => ({ data: { login: "github-actions[bot]" } }),
139 },
140 pulls: {
141 get: async () => ({ data: { head: { sha: "head-sha" } } }),

Callers 1

runFunction · 0.85

Calls 6

makeErrFunction · 0.85
successResFunction · 0.85
commentKeyFunction · 0.85
batchPostedCommentsFunction · 0.85
addFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected