MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / getPRInfo

Function getPRInfo

bin/checkout-pr.js:65–112  ·  view source on GitHub ↗

* Fetch PR information * @param {string} prUrl - PR url

(prUrl)

Source from the content-addressed store, hash-verified

63 * @param {string} prUrl - PR url
64 */
65function getPRInfo(prUrl) {
66 const options = {
67 ...parseURL(prUrl),
68 headers: {
69 'User-Agent': 'Node.js https client',
70 },
71 };
72 return new Promise((resolve, reject) => {
73 https
74 .get(options, res => {
75 const {statusCode} = res;
76 const contentType = res.headers['content-type'];
77
78 let error;
79 if (statusCode !== 200) {
80 error = new Error('Request Failed.\n' + `Status Code: ${statusCode}`);
81 } else if (!/^application\/json/.test(contentType)) {
82 error = new Error(
83 'Invalid content-type.\n' +
84 `Expected application/json but received ${contentType}`,
85 );
86 }
87 if (error) {
88 console.error(error.message);
89 // Consume response data to free up memory
90 res.resume();
91 return reject(error);
92 }
93
94 res.setEncoding('utf8');
95 let rawData = '';
96 res.on('data', chunk => {
97 rawData += chunk;
98 });
99 res.on('end', () => {
100 try {
101 const parsedData = JSON.parse(rawData);
102 resolve(parsedData);
103 } catch (e) {
104 reject(e);
105 }
106 });
107 })
108 .on('error', e => {
109 reject(e);
110 });
111 });
112}
113
114/**
115 * Run `git` command with the arguments

Callers 1

checkoutPRFunction · 0.85

Calls 7

errorMethod · 0.80
getMethod · 0.65
parseMethod · 0.65
rejectFunction · 0.50
resolveFunction · 0.50
onMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected