Skip to content

Commit baf8126

Browse files
committed
the hawk.nodejs catcher added
1 parent 5b64a57 commit baf8126

File tree

4 files changed

+82
-48
lines changed

4 files changed

+82
-48
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# - "admin:org - read:org"
44
TOKEN=
55

6+
#HAWK Catcher TOKEN
7+
HAWK_TOKEN=
8+
69
# Node id
710
COLUMN_NODE_ID_TO_DO=
811
COLUMN_NODE_ID_PR=

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"get-projects": "node bin/get-projects.js"
1212
},
1313
"dependencies": {
14+
"@hawk.so/nodejs": "^2.2.0",
1415
"@octokit/core": "^3.1.2",
1516
"axios": "^0.19.2",
1617
"cron": "^1.8.2",

src/index.js

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require('dotenv').config();
22

33
const Utils = require('./utils');
4+
const HawkCatcher = require('@hawk.so/nodejs').default;
45

56
const { Octokit } = require('@octokit/core');
67
const parseGithubUrl = require('parse-github-url');
@@ -9,6 +10,8 @@ const axios = require('axios').default;
910
const CronJob = require('cron').CronJob;
1011

1112
const TOKEN = process.env.TOKEN;
13+
const HAWK_TOKEN = process.env.HAWK_TOKEN;
14+
1215
const COLUMN_NODE_ID_TO_DO = process.env.COLUMN_NODE_ID_TO_DO;
1316
const COLUMN_NODE_ID_PR = process.env.COLUMN_NODE_ID_PR;
1417
const NOTIFIER_URL = process.env.NOTIFIER_URL;
@@ -40,6 +43,16 @@ const CARDS_QUERY = require('./queries/cards');
4043
const ISSUE_QUERY = require('./queries/issue');
4144
const PR_QUERY = require('./queries/pr');
4245

46+
/**
47+
* Initialize HawkCatcher.
48+
*/
49+
HawkCatcher.init({
50+
token: HAWK_TOKEN,
51+
context: {
52+
myOwnDebugInfo: '1234',
53+
},
54+
});
55+
4356
/**
4457
* Sends POST request to telegram bot
4558
*
@@ -76,7 +89,7 @@ function checkForParsableGithubLink(message) {
7689
return [true, owner, name, type, id];
7790
}
7891

79-
return [ false ];
92+
return [false];
8093
}
8194

8295
/**
@@ -355,7 +368,7 @@ async function parseQuery(members, response) {
355368
})
356369
);
357370

358-
let cardDataWithoutMembers = [ ...parsedCardData ];
371+
let cardDataWithoutMembers = [...parsedCardData];
359372

360373
for (let i = 0; i < members.length; i++) {
361374
cardDataWithoutMembers = cardDataWithoutMembers.map((x) =>
@@ -482,56 +495,60 @@ function parseMeetingMessage(mentionList) {
482495
* Call the Github GraphQL API, parse its response to message and add that message as cron job.
483496
*/
484497
async function main() {
485-
const toDoJob = new CronJob(
486-
TO_DO_TIME,
487-
async () => {
488-
notify(
489-
await notifyMessage("📌 Sprint's backlog", COLUMN_NODE_ID_TO_DO, true)
490-
)
491-
.then(() => console.log('Tasks Job Completed.'))
492-
.catch(console.error);
493-
},
494-
null,
495-
true,
496-
'Europe/Moscow'
497-
);
498+
try {
499+
const toDoJob = new CronJob(
500+
TO_DO_TIME,
501+
async () => {
502+
notify(
503+
await notifyMessage("📌 Sprint's backlog", COLUMN_NODE_ID_TO_DO, true)
504+
)
505+
.then(() => console.log('Tasks Job Completed.'))
506+
.catch(HawkCatcher.send);
507+
},
508+
null,
509+
true,
510+
'Europe/Moscow'
511+
);
498512

499-
const prJob = new CronJob(
500-
PR_TIME,
501-
async () => {
502-
notify(
503-
await notifyMessage('👀 Pull requests for review', COLUMN_NODE_ID_PR)
504-
)
505-
.then(() => console.log('PR Job Completed.'))
506-
.catch(console.error);
507-
},
508-
null,
509-
true,
510-
'Europe/Moscow'
511-
);
512-
const meetingJob = new CronJob(
513-
MEETING_TIME,
514-
() => {
515-
notify(parseMeetingMessage(MEETING_MENTION))
516-
.then(() => console.log('Meeting Job Completed.'))
517-
.catch(console.error);
518-
},
519-
null,
520-
true,
521-
'Europe/Moscow'
522-
);
513+
const prJob = new CronJob(
514+
PR_TIME,
515+
async () => {
516+
notify(
517+
await notifyMessage('👀 Pull requests for review', COLUMN_NODE_ID_PR)
518+
)
519+
.then(() => console.log('PR Job Completed.'))
520+
.catch(HawkCatcher.send);
521+
},
522+
null,
523+
true,
524+
'Europe/Moscow'
525+
);
526+
const meetingJob = new CronJob(
527+
MEETING_TIME,
528+
() => {
529+
notify(parseMeetingMessage(MEETING_MENTION))
530+
.then(() => console.log('Meeting Job Completed.'))
531+
.catch(HawkCatcher.send);
532+
},
533+
null,
534+
true,
535+
'Europe/Moscow'
536+
);
523537

524-
toDoJob.start();
525-
console.log('To do list Notifier started');
526-
console.log('Will notify at:' + TO_DO_TIME);
538+
toDoJob.start();
539+
console.log('To do list Notifier started');
540+
console.log('Will notify at:' + TO_DO_TIME);
527541

528-
prJob.start();
529-
console.log('PR review list Notifier started');
530-
console.log('Will notify at:' + PR_TIME);
542+
prJob.start();
543+
console.log('PR review list Notifier started');
544+
console.log('Will notify at:' + PR_TIME);
531545

532-
meetingJob.start();
533-
console.log('Meeting notifier started');
534-
console.log('Will notify at:' + MEETING_TIME);
546+
meetingJob.start();
547+
console.log('Meeting notifier started');
548+
console.log('Will notify at:' + MEETING_TIME);
549+
} catch (e) {
550+
HawkCatcher.send(e);
551+
}
535552
}
536553

537554
main();

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
minimatch "^3.0.4"
4040
strip-json-comments "^3.1.1"
4141

42+
"@hawk.so/nodejs@^2.2.0":
43+
version "2.2.0"
44+
resolved "https://registry.yarnpkg.com/@hawk.so/nodejs/-/nodejs-2.2.0.tgz#d72f028b2b39eaf6ac1a8b5f711ab9faa7649cb3"
45+
integrity sha512-6QdzhfNfzEEmkHzW3ApfGAbl4Ri8P68ezHqHgzToGVN/42SeC/wWX21hR69BrXSfMloK/33AH+Be/luNY388Ug==
46+
dependencies:
47+
axios "^0.19.2"
48+
stack-trace "^0.0.10"
49+
4250
"@nodelib/fs.scandir@2.1.4":
4351
version "2.1.4"
4452
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz#d4b3549a5db5de2683e0c1071ab4f140904bbf69"
@@ -1958,6 +1966,11 @@ sprintf-js@~1.0.2:
19581966
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
19591967
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
19601968

1969+
stack-trace@^0.0.10:
1970+
version "0.0.10"
1971+
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
1972+
integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=
1973+
19611974
string-width@^3.0.0:
19621975
version "3.1.0"
19631976
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"

0 commit comments

Comments
 (0)