Skip to content

Commit d60e965

Browse files
committed
wrap jobs with if
1 parent 051e080 commit d60e965

File tree

2 files changed

+80
-57
lines changed

2 files changed

+80
-57
lines changed

config.example.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Github Personal Access Token (https://github.com/settings/tokens) with rights:
22
# - "repo - public_repo"
33
# - "admin:org - read:org"
4-
token:
4+
token:
55

66
# HAWK Catcher TOKEN
7-
hawk_token:
7+
hawk_token:
88

99
# Columns Nodes id
1010
# To get these values use any app for sending requests (Insomnia for example) and send the following request
@@ -16,8 +16,9 @@ hawk_token:
1616
# Headers:
1717
# Authorization: bearer YOUR_GITHUB_PERSONAL_ACCESS_TOKEN
1818
# Content-Type: application/json
19+
# User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15
1920
# Body Type: GraphQL
20-
# Body:
21+
# Body:
2122
# query {
2223
# organization(login: "codex-team") {
2324
# project(number: 11) {
@@ -28,19 +29,19 @@ hawk_token:
2829
# node {
2930
# id,
3031
# name
31-
# }
32+
# }
3233
# }
3334
# }
3435
# }
3536
# }
3637
# }
37-
column_node_id_to_do:
38-
column_node_id_pr:
38+
column_node_id_to_do:
39+
column_node_id_pr:
3940

4041
# @codex_bot notify URL
4142
# Open https://t.me/codex_bot
4243
# And run /notify command
43-
notifier_url:
44+
notifier_url:
4445

4546
# Define jobs
4647
# Example: 0 9,18 * * 1-5
@@ -59,4 +60,4 @@ meeting_mention:
5960
mention:
6061
# - n0str
6162
- tg: nvc_8996
62-
gh: nvc8996
63+
gh: nvc8996

src/index.js

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ const TRIM_PR_NAME_LENGHT = 35;
3030
* The default cron expression described as:
3131
* At minute 0 past hour 9 and 18 on every day-of-week from Monday through Friday.
3232
*/
33-
const TO_DO_TIME = config.to_do_time || '0 9,20 * * 1-5';
33+
const TO_DO_TIME = config.to_do_time;
3434
/**
3535
* The default cron expression described as:
3636
* At minute 0 past hour 9 and 18 on every day-of-week from Monday through Friday.
3737
*/
38-
const PR_TIME = config.pr_time || '0 9,20 * * 1-5';
38+
const PR_TIME = config.pr_time;
3939
/**
4040
* The default cron expression described as:
4141
* At 21:00 on every day-of-week from Monday through Friday.
4242
*/
43-
const MEETING_TIME = config.meeting_time || '0 21 * * 1-5';
43+
const MEETING_TIME = config.meeting_time;
4444
const octokit = new Octokit({ auth: TOKEN });
4545

4646
const MEMBERS_QUERY = require('./queries/members');
@@ -389,57 +389,79 @@ function parseMeetingMessage(mentionList) {
389389
* Call the Github GraphQL API, parse its response to message and add that message as cron job.
390390
*/
391391
async function main() {
392-
const meetingJob = new CronJob(
393-
MEETING_TIME,
394-
() => {
395-
notify(parseMeetingMessage(MEETING_MENTION))
396-
.then(() => console.log('Meeting Job Completed.'))
397-
.catch(HawkCatcher.send);
398-
},
399-
null,
400-
true,
401-
'Europe/Moscow'
402-
);
392+
if (MEETING_TIME) {
393+
const meetingJob = new CronJob(
394+
MEETING_TIME,
395+
() => {
396+
notify(parseMeetingMessage(MEETING_MENTION))
397+
.then(() => console.log('Meeting Job Completed.'))
398+
.catch(HawkCatcher.send);
399+
},
400+
null,
401+
true,
402+
'Europe/Moscow'
403+
);
403404

404-
const toDoJob = new CronJob(
405-
TO_DO_TIME,
406-
async () => {
407-
notify(
408-
await notifyMessage("📌 Sprint's backlog", COLUMN_NODE_ID_TO_DO, true)
409-
)
410-
.then(() => console.log('Tasks Job Completed.'))
411-
.catch(HawkCatcher.send);
412-
},
413-
null,
414-
true,
415-
'Europe/Moscow'
416-
);
405+
meetingJob.start();
406+
console.log('Meeting notifier started');
407+
console.log('Will notify at:' + MEETING_TIME);
417408

418-
const prJob = new CronJob(
419-
PR_TIME,
420-
async () => {
421-
notify(
422-
await notifyMessage('👀 Pull requests for review', COLUMN_NODE_ID_PR)
423-
)
424-
.then(() => console.log('PR Job Completed.'))
425-
.catch(HawkCatcher.send);
426-
},
427-
null,
428-
true,
429-
'Europe/Moscow'
430-
);
409+
// notify(parseMeetingMessage(MEETING_MENTION))
410+
// .then(() => console.log('Meeting Job Completed.'))
411+
// .catch(HawkCatcher.send);
412+
}
413+
414+
if (TO_DO_TIME) {
415+
const toDoJob = new CronJob(
416+
TO_DO_TIME,
417+
async () => {
418+
notify(
419+
await notifyMessage("📌 Sprint's backlog", COLUMN_NODE_ID_TO_DO, true)
420+
)
421+
.then(() => console.log('Tasks Job Completed.'))
422+
.catch(HawkCatcher.send);
423+
},
424+
null,
425+
true,
426+
'Europe/Moscow'
427+
);
428+
429+
toDoJob.start();
430+
console.log('To do list Notifier started');
431+
console.log('Will notify at:' + TO_DO_TIME);
432+
433+
// notify(
434+
// await notifyMessage("📌 Sprint's backlog", COLUMN_NODE_ID_TO_DO, true)
435+
// )
436+
// .then(() => console.log('Tasks Job Completed.'))
437+
// .catch(HawkCatcher.send);
438+
}
431439

432-
meetingJob.start();
433-
console.log('Meeting notifier started');
434-
console.log('Will notify at:' + MEETING_TIME);
440+
if (PR_TIME) {
441+
const prJob = new CronJob(
442+
PR_TIME,
443+
async () => {
444+
notify(
445+
await notifyMessage('👀 Pull requests for review', COLUMN_NODE_ID_PR)
446+
)
447+
.then(() => console.log('PR Job Completed.'))
448+
.catch(HawkCatcher.send);
449+
},
450+
null,
451+
true,
452+
'Europe/Moscow'
453+
);
435454

436-
toDoJob.start();
437-
console.log('To do list Notifier started');
438-
console.log('Will notify at:' + TO_DO_TIME);
455+
prJob.start();
456+
console.log('PR review list Notifier started');
457+
console.log('Will notify at:' + PR_TIME);
439458

440-
prJob.start();
441-
console.log('PR review list Notifier started');
442-
console.log('Will notify at:' + PR_TIME);
459+
// notify(
460+
// await notifyMessage('👀 Pull requests for review', COLUMN_NODE_ID_PR)
461+
// )
462+
// .then(() => console.log('PR Job Completed.'))
463+
// .catch(HawkCatcher.send);
464+
}
443465
}
444466

445467
main();

0 commit comments

Comments
 (0)