BlueWallet/scripts/appcenter-post-build-get-pr-number.js
2023-12-29 11:09:34 +00:00

44 lines
935 B
JavaScript
Executable File

const https = require('https');
const gitCommand = "git log -n 1 --pretty=%d HEAD | awk '{print $2}' | sed 's/origin\\///' | sed 's/)//'";
const branch = require('child_process').execSync(gitCommand).toString().trim();
if (branch === 'master') process.exit();
const req = https.request(
{
hostname: 'api.github.com',
port: 443,
path: '/repos/BlueWallet/BlueWallet/pulls',
method: 'GET',
headers: { 'User-Agent': 'BlueWallet bot' },
},
resp => {
let data = '';
resp.on('data', chunk => {
data += chunk;
});
resp.on('end', () => {
try {
const prs = JSON.parse(data);
for (const pr of prs) {
if (branch === pr.head.ref) {
console.log(pr.number);
}
}
} catch (err) {
console.log(err);
console.log('got json: ', data);
}
});
},
);
req.on('error', e => {
console.error(e);
});
req.end();