-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (47 loc) · 1.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict'
const core = require('@actions/core');
const github = require('@actions/github');
const axios = require('axios');
const main = async () => {
try {
const email = core.getInput('email') || '[email protected]';
console.log(`Hello ${email}!`);
const count = await getLastContributedCount();
if (count === 0) {
const res = await axios.post(
'https://simple-send-mail-service.herokuapp.com/send-mail', {
email: email,
title: `📣 NONE CONTRIBUTED ALERT`,
body: `You have no contributes to Github today. Please commit something!`,
});
if (res.statusCode >= 400) {
throw res.statusText
}
core.setOutput("message", 'Success');
} else {
core.setOutput("message", 'You have contributed today, so we don\'t send any alert email.');
}
} catch (error) {
console.log(error);
core.setFailed(error);
}
}
const getLastContributedCount = async () => {
const url = `https://github.com/${github.context.repo.owner}`
console.log(`Getting contributed count from ${url}`);
const res = await axios.get(url, { headers: { accept: 'text/html' } });
var body = res.data;
var count = [];
body = body.slice(body.indexOf('js-calendar-graph-svg') + 23);
body = body.slice(0, body.indexOf('</svg>'));
body.split("\n").slice(2).map(c => c.trim()).forEach(c => {
let fill = c.match(/data-count="([0-9]+)"/);
if (fill) {
count.push(parseInt(fill[1]));
}
});
count = count.slice(count.length - 1, count.length);
console.log(`Last contributed count: ${count[count.length - 1]}`);
return count[count.length - 1]
}
main();