2018-04-06 23:01:07 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Title } from '@angular/platform-browser';
|
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
|
|
|
|
import { CommitTrackerService } from '../../shared/service/commit-tracker.service';
|
|
|
|
|
import { Commit } from '../../shared/commit';
|
|
|
|
|
import { CommitStatus } from '../../shared/commit-status.enum';
|
|
|
|
|
import { Result } from '../../shared/result.enum';
|
2018-04-09 18:41:53 +02:00
|
|
|
import { Build } from '../../shared/build';
|
2018-04-06 23:01:07 +02:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-commit-tracker',
|
|
|
|
|
templateUrl: './commit-tracker.component.html',
|
|
|
|
|
styleUrls: ['./commit-tracker.component.css']
|
|
|
|
|
})
|
|
|
|
|
export class CommitTrackerComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
public CommitStatus = CommitStatus;
|
|
|
|
|
|
|
|
|
|
constructor(private commitTrackerService: CommitTrackerService,
|
|
|
|
|
private titleService: Title,
|
2018-04-09 18:41:53 +02:00
|
|
|
private route: ActivatedRoute) {
|
|
|
|
|
}
|
2018-04-06 23:01:07 +02:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.titleService.setTitle('Commit-tracker : MTAStv');
|
2018-04-09 18:41:53 +02:00
|
|
|
this.route.data.subscribe((data: { commits: Array<Commit> }) => this.commits = data.commits);
|
2018-04-06 23:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get commits(): Array<Commit> {
|
|
|
|
|
return this.commitTrackerService.commits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set commits(commits: Array<Commit>) {
|
|
|
|
|
this.commitTrackerService.commits = commits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public labelClasses(commit: Commit, commitStatus: String) {
|
|
|
|
|
const classes: Object = {
|
|
|
|
|
ui: true,
|
|
|
|
|
big: true,
|
|
|
|
|
circular: true,
|
|
|
|
|
label: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (commitStatus) {
|
|
|
|
|
case CommitStatus.Verified:
|
|
|
|
|
return Object.assign(classes, {
|
2018-04-09 18:41:53 +02:00
|
|
|
green: commit.gerrit_verified === 1,
|
|
|
|
|
red: commit.gerrit_verified === -1,
|
2018-04-06 23:01:07 +02:00
|
|
|
});
|
|
|
|
|
case CommitStatus.CodeReview:
|
|
|
|
|
return Object.assign(classes, {
|
2018-04-09 18:41:53 +02:00
|
|
|
green: commit.gerrit_code_review === 2,
|
|
|
|
|
yellow: commit.gerrit_code_review === 1 || commit.gerrit_code_review === -1,
|
|
|
|
|
red: commit.gerrit_code_review === -2,
|
2018-04-06 23:01:07 +02:00
|
|
|
});
|
|
|
|
|
case CommitStatus.CommitFeedbackLoop:
|
|
|
|
|
return Object.assign(classes, {
|
2018-04-09 18:41:53 +02:00
|
|
|
'blue inprogress': commit.cfl_result === Result.Building,
|
|
|
|
|
'blue-yellow inprogress': commit.cfl_result === Result.Building
|
|
|
|
|
&& this.hasSubbuildWithCode(commit.cfl_sub_builds, Result.Unstable),
|
|
|
|
|
'blue-red inprogress': commit.cfl_result === Result.Building
|
|
|
|
|
&& this.hasSubbuildWithCode(commit.cfl_sub_builds, Result.Failure),
|
2018-04-06 23:01:07 +02:00
|
|
|
green: commit.cfl_result === Result.Success,
|
2018-04-09 18:41:53 +02:00
|
|
|
grey: commit.cfl_result === Result.Aborted,
|
|
|
|
|
yellow: commit.cfl_result === Result.Unstable,
|
2018-04-06 23:01:07 +02:00
|
|
|
red: commit.cfl_result === Result.Failure,
|
|
|
|
|
brown: commit.cfl_result === Result.NotBuilt,
|
|
|
|
|
});
|
|
|
|
|
case CommitStatus.ShortFeedbackLoop:
|
|
|
|
|
return Object.assign(classes, {
|
2018-04-09 18:41:53 +02:00
|
|
|
'blue inprogress': commit.sfl_result === Result.Building,
|
|
|
|
|
'blue-yellow inprogress': commit.sfl_result === Result.Building
|
|
|
|
|
&& this.hasSubbuildWithCode(commit.sfl_sub_builds, Result.Unstable),
|
|
|
|
|
'blue-red inprogress': commit.sfl_result === Result.Building
|
|
|
|
|
&& this.hasSubbuildWithCode(commit.sfl_sub_builds, Result.Failure),
|
2018-04-06 23:01:07 +02:00
|
|
|
green: commit.sfl_result === Result.Success,
|
2018-04-09 18:41:53 +02:00
|
|
|
grey: commit.sfl_result === Result.Aborted,
|
|
|
|
|
yellow: commit.sfl_result === Result.Unstable,
|
2018-04-06 23:01:07 +02:00
|
|
|
red: commit.sfl_result === Result.Failure,
|
|
|
|
|
brown: commit.sfl_result === Result.NotBuilt,
|
|
|
|
|
});
|
|
|
|
|
case CommitStatus.NightlyFeedbackLoop:
|
|
|
|
|
return Object.assign(classes, {
|
2018-04-09 18:41:53 +02:00
|
|
|
'blue inprogress': commit.nfl_result === Result.Building,
|
|
|
|
|
'blue-yellow inprogress': commit.nfl_result === Result.Building
|
|
|
|
|
&& this.hasSubbuildWithCode(commit.nfl_sub_builds, Result.Unstable),
|
|
|
|
|
'blue-red inprogress': commit.nfl_result === Result.Building
|
|
|
|
|
&& this.hasSubbuildWithCode(commit.nfl_sub_builds, Result.Failure),
|
2018-04-06 23:01:07 +02:00
|
|
|
green: commit.nfl_result === Result.Success,
|
2018-04-09 18:41:53 +02:00
|
|
|
grey: commit.nfl_result === Result.Aborted,
|
|
|
|
|
yellow: commit.nfl_result === Result.Unstable,
|
2018-04-06 23:01:07 +02:00
|
|
|
red: commit.nfl_result === Result.Failure,
|
2018-04-09 18:41:53 +02:00
|
|
|
brown: commit.nfl_result === Result.NotBuilt,
|
2018-04-06 23:01:07 +02:00
|
|
|
});
|
2018-04-09 18:41:53 +02:00
|
|
|
default:
|
|
|
|
|
return classes;
|
2018-04-06 23:01:07 +02:00
|
|
|
}
|
2018-04-09 18:41:53 +02:00
|
|
|
}
|
2018-04-06 23:01:07 +02:00
|
|
|
|
2018-04-09 18:41:53 +02:00
|
|
|
private hasSubbuildWithCode(build: Build, status: Result): boolean {
|
|
|
|
|
if (build === null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return build.build.subBuild.some(subBuild => {
|
|
|
|
|
let thing = false;
|
|
|
|
|
if (subBuild.build.subBuild) {
|
|
|
|
|
thing = subBuild.build.subBuild.some(subSubBuild => this.hasSubbuildWithCode(
|
|
|
|
|
subSubBuild, status
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
return subBuild.result === status || thing;
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-06 23:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public rowClasses(commit: Commit) {
|
|
|
|
|
return {
|
|
|
|
|
positive: this.isAllOk(commit),
|
|
|
|
|
negative: this.hasAnyFailure(commit)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private isAllOk(commit: Commit) {
|
|
|
|
|
return [
|
|
|
|
|
commit.cfl_result,
|
|
|
|
|
commit.sfl_result,
|
|
|
|
|
commit.nfl_result,
|
|
|
|
|
].every(result => result === Result.Success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private hasAnyFailure(commit: Commit) {
|
|
|
|
|
return [
|
|
|
|
|
commit.cfl_result,
|
|
|
|
|
commit.sfl_result,
|
|
|
|
|
commit.nfl_result,
|
|
|
|
|
].some(result => result === Result.Failure);
|
|
|
|
|
}
|
|
|
|
|
}
|