-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (75 loc) · 2.2 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const express = require('express')
const shelljs = require('shelljs')
const app = express();
var http = require("https");
const git = require('simple-git/promise');
const isProd = process.env.SERIOUS === "production"
// ms s m h
const duration = isProd ? 1000 * 60 * 60 : 1000 * 5
let TASK = null;
let PING = null;
const USER = process.env.GIT_USERNAME;
const PASS = process.env.GIT_PASSWORD;
const REPO = `github.com/${USER}/git-hack`;
const remote = `https://${USER}:${PASS}@${REPO}`;
console.log("Duration -> ", duration);
shelljs.exec("git init")
shelljs.exec(`git remote add origin ${remote}`)
shelljs.exec('git config --global user.email "raman.choudhary65@gmail.com"')
shelljs.exec('git config --global user.name "Raman Choudhary"')
shelljs.exec('git pull origin master')
console.log("Git Initiated");
start();
app.get("/you-shall-stop", (req, res) => {
end();
res.send("Task Stopped");
})
app.get("/status", (req, res) => {
if(TASK) {
res.send("Running...")
} else {
res.send("Stopped :(")
}
})
app.get("/start", (req, res) => {
start();
res.send("Task Started");
});
app.listen(process.env.PORT || 5000, () => {
console.log("Listening at 5000");
})
function start(){
console.log("Process Started");
TASK = setInterval(() => {
try{
const ts = new Date().getTime()
// git()
// .silent(true)
// .add("./*")
// .commit(`added a new comment at ${ts}`)
// .addRemote('origin', remote)
// .push(['-u', 'origin', 'master'], () => {
// console.log("Pushed Successfully");
// })
console.log(`Action Started at ${ts}`);
shelljs.exec(`echo "${ts} ms" >> commit-log`);
shelljs.exec("git add .")
shelljs.exec(`git commit -m"commed at ${ts}ms"`)
shelljs.exec("git pull origin master --force");
shelljs.exec("git push origin master");
console.log("Action Successfull");
}catch(e){
console.log("Action Failed");
console.log(e);
}
}, duration)
PING = setInterval(() => {
console.log("Pinging...");
http.get("https://git-hack.herokuapp.com/status")
}, 100000)
}
function end(){
console.log("Task Stopped");
clearInterval(TASK)
TASK = null;
}