Skip to content

Commit

Permalink
Use GitHub status API to get more accurate results (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
jkimbo and sindresorhus committed Apr 25, 2020
1 parent 989c1de commit 82dffa1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
26 changes: 18 additions & 8 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ meow(`
`);

(async () => {
try {
await got.head('https://github.com', {
timeout: 10000,
retry: 2
});
const {status} = await got('https://kctbh9vrtdwd.statuspage.io/api/v2/summary.json', {
timeout: 10000,
retry: 2
}).json();

console.error('\n ๐Ÿˆ It\'s up. Go back to work!');
if (['major', 'critical'].includes(status.indicator)) {
console.log('\n๐Ÿฆ„ It\'s down. Play with your ๐Ÿ˜ธ/๐Ÿถ! And stay home!\n');
console.log('Status page: https://githubstatus.com');
process.exitCode = 1;
} catch {
console.log('\n๐Ÿฆ„ It\'s down. Play with your ๐Ÿ˜ธ/๐Ÿถ! And stay home!');
return;
}

if (status.indicator === 'minor') {
console.log('\n๐Ÿค” There might be some issues. Probably better to play with your ๐Ÿ˜ธ/๐Ÿถ instead! Also stay at home!\n');
console.log('Status page: https://githubstatus.com');
process.exitCode = 1;
return;
}

console.error('\n ๐Ÿˆ It\'s up. Go back to work!');
process.exitCode = 0;
})();
10 changes: 5 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ test('main', async t => {
let returnValue;

try {
const {stdout} = await execa('./cli.js');
returnValue = stdout;
const {stdout, stderr} = await execa('./cli.js');
returnValue = stdout || stderr;
} catch (error) {
const {stderr} = error;
returnValue = stderr;
const {stdout} = error;
returnValue = stdout;
}

t.regex(returnValue, /down|up/);
t.regex(returnValue, /down|up|issues/);
});

0 comments on commit 82dffa1

Please sign in to comment.