-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
62 lines (49 loc) · 1.42 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
61
62
'use strict'
const checker = require('./Github/repoChecker')
const twitMessager = require('./Twitter/postTwit')
// Init repoChecker to match current date
checker.init((new Date()).toISOString())
// In order to work with heroku I need a server so...
const express = require('express')
const app = express()
app.all('*', function (req, res) {
res.redirect('https://github.com/VzqzAc/twgitbot')
})
let port = process.env.PORT || 3000
app.listen(port, function (error) {
if (error) console.error(error)
})
let interval
try {
interval = setInterval(checkForChanges, 86400000)
} catch (e) {
clearInterval(interval)
}
function checkForChanges () {
checker.fetchCommits()
.then(function (commits) {
if (!commits.length) return
checker.updateLastCheck((new Date()).toISOString())
let newSHA = commits[0].sha
if (checker.shouldFetch(newSHA)) {
checker.updateLastSHA(newSHA)
let newCommit = checker.updateLastCommit(commits[0])
checkLanguages(newCommit)
checker.fetchLanguages(function (languages) {
twitMessager.createAndPost(commits[0], languages)
})
}
})
.catch(console.error)
}
function checkLanguages (commit) {
checker.fetchLanguages()
.then(function (languages) {
publishTwit(commit, languages)
})
.catch(console.error)
}
function publishTwit (commit, languages) {
twitMessager.createAndPost(commit, languages)
.then()
}