2018-03-29 00:18:33 -04:00
|
|
|
import { ComplexBotComponent } from "../complex-bot.component";
|
|
|
|
import { Component } from "@angular/core";
|
|
|
|
import { SessionStorage } from "../../../shared/SessionStorage";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2018-03-29 00:18:33 -04:00
|
|
|
|
|
|
|
interface TravisCiConfig {
|
2018-03-30 16:59:25 -04:00
|
|
|
webhookId: string;
|
2018-03-29 00:18:33 -04:00
|
|
|
repos: {
|
|
|
|
[repoKey: string]: { // "turt2live/matrix-dimension"
|
|
|
|
addedByUserId: string;
|
|
|
|
template: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
interface LocalRepo {
|
|
|
|
repoKey: string;
|
|
|
|
template: string;
|
|
|
|
addedByUserId: string;
|
|
|
|
isSelf: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "travisci.complex-bot.component.html",
|
|
|
|
styleUrls: ["travisci.complex-bot.component.scss"],
|
|
|
|
})
|
|
|
|
export class TravisCiComplexBotConfigComponent extends ComplexBotComponent<TravisCiConfig> {
|
|
|
|
|
|
|
|
public newRepoKey = "";
|
|
|
|
|
2020-10-23 07:30:20 -04:00
|
|
|
constructor(public translate: TranslateService) {
|
|
|
|
super("travisci", translate);
|
|
|
|
this.translate = translate;
|
2018-03-29 00:18:33 -04:00
|
|
|
}
|
|
|
|
|
2018-03-30 16:59:25 -04:00
|
|
|
public get webhookUrl(): string {
|
|
|
|
if (!this.newConfig) return "not specified";
|
|
|
|
|
|
|
|
return window.location.origin + "/api/v1/dimension/webhooks/travisci/" + this.newConfig.webhookId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get travisYaml(): string {
|
|
|
|
return "" +
|
|
|
|
"notifications:\n" +
|
|
|
|
" webhooks:\n" +
|
|
|
|
" urls:\n" +
|
|
|
|
" - " + this.webhookUrl + "\n" +
|
|
|
|
" on_success: change # always | never | change\n" +
|
|
|
|
" on_failure: always\n" +
|
|
|
|
" on_start: never\n";
|
|
|
|
}
|
|
|
|
|
2018-03-29 00:18:33 -04:00
|
|
|
public addRepo(): void {
|
|
|
|
if (!this.newRepoKey.trim()) {
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Please enter a repository').subscribe((res: string) => {
|
|
|
|
this.toaster.pop('warning', res);
|
|
|
|
});
|
2018-03-29 00:18:33 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-30 16:59:25 -04:00
|
|
|
this.newConfig.repos[this.newRepoKey] = {
|
|
|
|
addedByUserId: SessionStorage.userId,
|
|
|
|
template: "" +
|
2019-07-11 00:17:16 -04:00
|
|
|
"%{repository_slug}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}\n" +
|
|
|
|
" Change view : %{compare_url}\n" +
|
|
|
|
" Build details : %{build_url}\n"
|
2018-03-30 16:59:25 -04:00
|
|
|
};
|
2018-03-29 00:18:33 -04:00
|
|
|
this.newRepoKey = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public getRepos(): LocalRepo[] {
|
|
|
|
if (!this.newConfig.repos) this.newConfig.repos = {};
|
|
|
|
return Object.keys(this.newConfig.repos).map(r => {
|
|
|
|
return {
|
|
|
|
repoKey: r,
|
|
|
|
template: this.newConfig.repos[r].template,
|
|
|
|
addedByUserId: this.newConfig.repos[r].addedByUserId,
|
|
|
|
isSelf: SessionStorage.userId === this.newConfig.repos[r].addedByUserId,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeRepo(repo: LocalRepo): void {
|
|
|
|
delete this.newConfig.repos[repo.repoKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
public async interceptSave(): Promise<any> {
|
|
|
|
const memberEvent = await this.scalarClientApi.getMembershipState(this.roomId, this.bot.notificationUserId);
|
|
|
|
const isJoined = memberEvent && memberEvent.response && ["join", "invite"].indexOf(memberEvent.response.membership) !== -1;
|
|
|
|
|
|
|
|
if (!isJoined) {
|
|
|
|
await this.scalarClientApi.inviteUser(this.roomId, this.bot.notificationUserId);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.save();
|
|
|
|
}
|
2020-10-23 07:30:20 -04:00
|
|
|
}
|