-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
86 lines (70 loc) · 3.77 KB
/
main.ts
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
import container from "./ioc-config";
import EventBus from "./event/event-bus";
import InstallationStorage from "./provider/github/client/installation-storage";
import { WebServer } from "./webserver";
import { HistoryService, ElasticHistoryService, NoopHistoryService } from "./elastic/persister";
import { ConfigurationService, ScottyConfig } from "./configuration";
import { log } from "@swingletree-oss/harness";
import { CacheSyncEvent } from "./event/event-model";
import { InstallationWebservice } from "./routes/installations";
import { ReportWebservice } from "./routes/report";
import GhAppInstallationHandler from "./provider/github/app-installation-handler";
import { CommitStatusSender } from "./provider/status-sender";
import GithubCommitStatusSender from "./provider/github/commit-status-sender";
import GiteaCommitStatusSender from "./provider/gitea/commit-status-sender";
import GithubClientService from "./provider/github/client/github-client";
import TokenStorage from "./provider/github/client/token-storage";
import { GiteaClient } from "./provider/gitea/client";
import { ProviderClient } from "./provider/provider-client";
import { RepoConfigWebservice } from "./routes/config/service";
require("source-map-support").install();
class Scotty {
private webserver: WebServer;
private eventBus: EventBus;
constructor() {
log.info("Starting up...");
const configService = container.get<ConfigurationService>(ConfigurationService);
if (configService.getBoolean(ScottyConfig.Elastic.ENABLED)) {
log.info("Registering Elastic Storage Service");
container.bind<HistoryService>(HistoryService).to(ElasticHistoryService).inSingletonScope();
} else {
log.info("Elastic is disabled. Will not write any Notification Events to Elastic.");
container.bind<HistoryService>(HistoryService).to(NoopHistoryService).inSingletonScope();
}
this.webserver = container.get<WebServer>(WebServer);
this.eventBus = container.get<EventBus>(EventBus);
// configure SCM provider
const provider = configService.get(ScottyConfig.PROVIDER);
switch (provider) {
case "gitea":
log.info("SCM provider set to Gitea");
container.bind<ProviderClient>(ProviderClient).to(GiteaClient).inSingletonScope();
container.bind<CommitStatusSender>(CommitStatusSender).to(GiteaCommitStatusSender).inSingletonScope();
break;
default:
log.info("no SCM provider specified. Using default setting:");
case "github":
log.info("SCM provider set to GitHub");
container.bind<ProviderClient>(ProviderClient).to(GithubClientService).inSingletonScope();
container.bind<GhAppInstallationHandler>(GhAppInstallationHandler).toSelf().inSingletonScope();
container.bind<TokenStorage>(TokenStorage).toSelf().inSingletonScope();
container.bind<InstallationStorage>(InstallationStorage).toSelf().inSingletonScope();
container.bind<CommitStatusSender>(CommitStatusSender).to(GithubCommitStatusSender).inSingletonScope();
// strap installation handler
container.get<GhAppInstallationHandler>(GhAppInstallationHandler);
// strap installation service
this.webserver.addRouter("/installation", container.get<InstallationWebservice>(InstallationWebservice).getRouter());
break;
}
// strap report service
this.webserver.addRouter("/report", container.get<ReportWebservice>(ReportWebservice).getRouter());
// strap repository config webservices
this.webserver.addRouter("/config/", container.get<RepoConfigWebservice>(RepoConfigWebservice).getRouter());
// bootstrap periodic events
setInterval(() => { this.eventBus.emit(new CacheSyncEvent()); }, InstallationStorage.SYNC_INTERVAL);
}
public isEnabled(): boolean {
return true;
}
}
new Scotty();