This repository has been archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebsite.gs
59 lines (51 loc) · 1.81 KB
/
website.gs
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
var authCallback, doGet, installTrigger, triggerIsInstalled, uninstallTrigger;
function doGet(req) {
var githubService, output, template;
template = HtmlService.createTemplateFromFile("index");
githubService = template.githubService = getGitHubService();
template.muterState = triggerIsInstalled("muter") ? "installed" : "uninstalled";
if (fetchCachedGitHubTeamSlugs() === "err") {
template.lablerState = "not-authorized";
} else if (triggerIsInstalled("labler")) {
template.lablerState = "installed";
} else {
template.lablerState = "uninstalled";
}
output = template.evaluate();
output.setSandboxMode(HtmlService.SandboxMode.NATIVE);
return output;
};
function authCallback(req) {
var githubService;
githubService = getGitHubService();
githubService.handleCallback(req);
return doGet(req);
};
function installTrigger(name) {
return ScriptApp.newTrigger(name).timeBased().everyMinutes(30).create();
};
function uninstallTrigger(name) {
var i, len, results, trigger, triggers;
triggers = ScriptApp.getProjectTriggers();
results = [];
for (i = 0, len = triggers.length; i < len; i++) {
trigger = triggers[i];
if (trigger.getEventType() === ScriptApp.EventType.CLOCK && trigger.getHandlerFunction() === name) {
results.push(ScriptApp.deleteTrigger(trigger));
} else {
results.push(void 0);
}
}
return results;
};
function triggerIsInstalled(func) {
var i, len, trigger, triggers;
triggers = ScriptApp.getProjectTriggers();
for (i = 0, len = triggers.length; i < len; i++) {
trigger = triggers[i];
if (trigger.getEventType() === ScriptApp.EventType.CLOCK && trigger.getHandlerFunction() === func) {
return true;
}
}
return false;
};