MCPcopy Create free account
hub / github.com/PRX/Infrastructure / compareCommits

Function compareCommits

ci/src/slack-message-handler/github.mjs:5–50  ·  view source on GitHub ↗
(ownerAndRepo, before, after)

Source from the content-addressed store, hash-verified

3// https://docs.github.com/en/rest/commits/commits#compare-two-commits
4// Returns information comparing two commits for a given repository
5export async function compareCommits(ownerAndRepo, before, after) {
6 return new Promise((resolve, reject) => {
7 const gitHubToken = process.env.GITHUB_ACCESS_TOKEN;
8
9 if (
10 before === '0000000000000000000000000000000000000000' ||
11 after === '0000000000000000000000000000000000000000'
12 ) {
13 resolve({});
14 }
15
16 const options = {
17 host: 'api.github.com',
18 path: `/repos/${ownerAndRepo}/compare/${before}...${after}?per_page=16`,
19 method: 'GET',
20 headers: {
21 Accept: 'application/vnd.github.v3+json',
22 Authorization: `token ${gitHubToken}`,
23 'User-Agent': 'PRX/CI (slack-message-handler)',
24 'Content-Length': Buffer.byteLength(''),
25 },
26 };
27
28 const req = request(options, (res) => {
29 res.setEncoding('utf8');
30
31 let json = '';
32 res.on('data', (chunk) => {
33 json += chunk;
34 });
35 res.on('end', () => {
36 if (res.statusCode >= 200 && res.statusCode < 300) {
37 resolve(JSON.parse(json));
38 } else {
39 reject(new Error(`GitHub request failed! ${res.statusCode}`));
40 }
41 });
42 });
43
44 // Generic request error handling
45 req.on('error', (e) => reject(e));
46
47 req.write('');
48 req.end();
49 });
50}

Callers 1

statusBlocksFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected