Skip to content

Commit

Permalink
fixes #43 ChainLP: Build Id in the Header is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
anshooarora committed Jan 18, 2025
1 parent 6afc542 commit 4e9f552
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public class BuildController {

@GetMapping
public ResponseEntity<Page<Build>> findAll(@RequestParam(required = false, defaultValue = "0") final long id,
@RequestParam(required = false, defaultValue = "0") final Long displayId,
@RequestParam(required = false) final Integer projectId,
@RequestParam(required = false) final String result,
@RequestParam(required = false) final Long startedAfter,
@RequestParam(required = false) final Long endedBefore,
final Pageable pageable) {
return ResponseEntity.ok(service.findAll(id, projectId, result, startedAfter, endedBefore, pageable));
return ResponseEntity.ok(service.findAll(id, displayId, projectId, result, startedAfter, endedBefore, pageable));
}

@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public BuildService(final BuildRepository repository,

@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Cacheable(value = "builds", unless = "#result == null || #result.totalElements == 0")
public Page<Build> findAll(final long id, final Integer projectId, final String result,
public Page<Build> findAll(final long id, final long displayId, final Integer projectId, final String result,
final Long startedAfter, final Long endedBefore, final Pageable pageable) {
final BuildSpec spec = new BuildSpec(
Build.builder().id(id)
.displayId(displayId)
.projectId(projectId)
.result(result)
.startedAt(startedAfter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Predicate toPredicate(final Root<Build> root, final CriteriaQuery<?> quer
final List<Predicate> predicates = new ArrayList<>();

addPredicateIfNotZero(predicates, cb, root.get(Build_.id), _build.getId());
addPredicateIfNotZero(predicates, cb, root.get(Build_.displayId), _build.getDisplayId());
addPredicateIfNotNull(predicates, cb, root.get(Build_.projectId), _build.getProjectId());
addPredicateIfNotNullAndEmpty(predicates, cb, root.get(Build_.result), _build.getResult());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public class Test {
@Column(name = "build_id")
private Long buildId;

@Column(name = "build_display_id")
private Long buildDisplayId;

public void setBuildDisplayId(final Long buildDisplayId) {
this.buildDisplayId = buildDisplayId;
if (children != null) {
children.forEach(x -> x.setBuildDisplayId(buildDisplayId));
}
}

@Column(name = "project_id")
private Integer projectId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aventstack.chainlp.api.test;

import com.aventstack.chainlp.api.build.Build;
import com.aventstack.chainlp.api.build.BuildService;
import com.aventstack.chainlp.api.project.ProjectService;
import com.aventstack.chainlp.api.tag.Tag;
Expand Down Expand Up @@ -134,13 +135,20 @@ public Test create(final Test test) {

// if client does not provide a project-id, we will try to find the project-id from the build
if (null == test.getProjectId() || 0L == test.getProjectId()) {
final Integer projectId = buildService.findById(test.getBuildId()).getProjectId();
final Build build = buildService.findById(test.getBuildId());
final Integer projectId = build.getProjectId();
test.setProjectId(projectId);
test.setBuildDisplayId(build.getDisplayId());
} else {
// else, we will check if the project exists
projectService.findById(test.getProjectId());
}

if (null == test.getBuildDisplayId() || 0L == test.getBuildDisplayId()) {
final Build build = buildService.findById(test.getBuildId());
test.setBuildDisplayId(build.getDisplayId());
}

test.getChildren().forEach(x -> x.setProjectId(test.getProjectId()));

log.debug("Saving test {} for buildId: {}", test, test.getBuildId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class BuildTestGrowthComponent {
const builds: Build[] = this.builds.content;
for (let i = 0; i < builds.length; i++) {
if (builds[i].buildstats.length > 0) {
this.data.labels?.push('#' + builds[i].id);
this.data.labels?.push('#' + builds[i].displayId);
this.data.datasets[0].data.push(builds[i].buildstats[0].total);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ <h5 class="mb-3 testname" [ngClass]="test.result.toLowerCase()">{{test.name}}</h
<span class="badge rounded-pill text-bg-secondary me-1" *ngFor="let tag of test.tags">{{tag.name}}</span>
</div>
<div class="mt-3" *ngIf="showMeta">
<a [routerLink]="['/', 'builds', test.buildId]">
<span class="btn btn-outline-primary">Go to build {{test.buildId}} <i class="ms-1 bi bi-arrow-up-right-square"></i></span></a>
<a [routerLink]="['/', 'projects', test.projectId, 'builds', test.buildDisplayId]">
<span class="btn btn-outline-primary">Go to build {{test.buildDisplayId}} <i class="ms-1 bi bi-arrow-up-right-square"></i></span></a>
</div>
</div>
<div class="col-8">
Expand Down
2 changes: 2 additions & 0 deletions chainlp/frontend/chainlp/src/app/model/test.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Embed } from "./embed.model";
export class Test extends Page<Test> {
id: number;
buildId: number;
buildDisplayId: number;
projectId: number;
startedAt: Date;
endedAt: Date;
durationMs: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ <h2 ngbAccordionHeader>
(click)="selectBuild(build)">
<div class="card-body d-on-hover">
<div class="ms-1 mb-2 d-flex justify-content-between">
<div class="build-name pointer" routerLink="{{build.id}}">
<div class="build-name pointer" routerLink="{{build.displayId}}">
<i class="bi bi-check-circle-fill text-success" *ngIf="build.result.toString() == 'PASSED'"></i>
<i class="bi bi-x-circle-fill text-danger" *ngIf="build.result.toString() != 'PASSED'"></i>
<span class="ms-2 fw-semibold">
<span *ngIf="!build.displayId || build.displayId == 0">#{{build.id}}</span>
<span *ngIf="build.displayId && build.displayId > 0">#{{build.displayId}}</span> - {{build.testRunner}}</span>
<span>#{{build.displayId}}</span> - {{build.testRunner}}</span>
</div>
<div class="d-flex">
<div class="pointer me-2" ngbDropdown>
Expand Down Expand Up @@ -139,7 +138,7 @@ <h2 ngbAccordionHeader>
<ng-container *ngIf="selectedBuild && selectedBuild.buildstats && selectedBuild.buildstats.length">
<div class="card">
<div class="card-header pb-0">
<h6 class="mb-0">#{{selectedBuild.id}} - {{statsTitle}}</h6>
<h6 class="mb-0">#{{selectedBuild.displayId}} - {{statsTitle}}</h6>
</div>
<div class="card-body py-0">
<div class="mx-auto" style="width: 150px;max-height: 150px;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="page-header">
<div class="container">
<div class="d-flex justify-content-between">
<h4>Build {{build.id}}</h4>
<h4>Build {{build.displayId}}</h4>
<div>
<button type="button" class="btn btn-outline-primary btn-sm ms-1"
[ngClass]="{'active': !displaySummary}" (click)="toggleDisplaySummary()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class BuildComponent implements OnInit, OnDestroy {
'testng': ['Suite', 'Class', 'Method']
};

projectId: number;
buildId: number;
buildDisplayId: number;
build: Build;
page: Page<Test>;
displaySummary: boolean = true;
Expand All @@ -56,14 +58,14 @@ export class BuildComponent implements OnInit, OnDestroy {

ngOnInit(): void {
this.route.paramMap.subscribe(val => {
this.projectId = parseInt(this.route.snapshot.paramMap.get('projectId') || '0');
let id = this.route.snapshot.paramMap.get('buildId') || '0';
if (this.buildId == parseInt(id)) {
if (this.buildDisplayId == parseInt(id)) {
return;
}
this.resetAll();
this.buildId = parseInt(id);
this.buildDisplayId = parseInt(id);
this.findBuild();
this.findTests();
});
}

Expand Down Expand Up @@ -157,10 +159,13 @@ export class BuildComponent implements OnInit, OnDestroy {
}

findBuild(): void {
this._buildService.find(this.buildId)
this._buildService.findByDisplayId(this.projectId, this.buildDisplayId)
.pipe(takeUntil(this._destroy$))
.subscribe({
next: (build: Build) => {
next: (page: Page<Build>) => {
const build = page.content[0];
this.buildId = build.id;
this.findTests();
if (build.testRunner.indexOf('cucumber') > -1) {
this.tagDepth = 1;
} else {
Expand Down Expand Up @@ -207,21 +212,21 @@ export class BuildComponent implements OnInit, OnDestroy {

findTestsByStatus(result: string, depth: number): void {
const test = new Test();
test.buildId = this.buildId;
test.buildId = this.buildDisplayId;
test.depth = 0;
if (depth === 0) {
test.result = result;
}
if (depth >= 1) {
test.result = '';
test.children = [new Test()];
test.children[0].buildId = this.buildId;
test.children[0].buildId = this.buildDisplayId;
if (depth >= 2) {
test.children[0].result = '';
test.children[0].children = [new Test()];
test.children[0].children[0].depth = 2;
test.children[0].children[0].result = result;
test.children[0].children[0].buildId = this.buildId;
test.children[0].children[0].buildId = this.buildDisplayId;
} else {
test.children[0].depth = 1;
test.children[0].result = result;
Expand Down Expand Up @@ -270,7 +275,7 @@ export class BuildComponent implements OnInit, OnDestroy {

filterTag(tag: string): void {
this.page = new Page<Test>();
this._testService.search(0, '', -1, this.buildId, 0, '', tag, '', 0, 'AND')
this._testService.search(0, '', -1, this.buildDisplayId, 0, '', tag, '', 0, 'AND')
.pipe(takeUntil(this._destroy$))
.subscribe({
next: (page: Page<Test>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h5>Build Status</h5>
<td>{{ project.name }}</td>
<ng-container *ngIf="project.builds && project.builds.content">
<td *ngFor="let build of project.builds.content">
<span class="" role="button" [routerLink]="['/', 'projects', project.id, 'builds', build.id]">
<span class="" role="button" [routerLink]="['/', 'projects', project.id, 'builds', build.displayId]">
<i class="bi bi-check-circle-fill text-success" *ngIf="build.result == 'PASSED'"></i>
<i class="bi bi-x-circle-fill text-danger" *ngIf="build.result != 'PASSED'"></i>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ <h5 class="mb-0 pointer" [routerLink]="['/', 'projects', project.id, 'builds']">
<a class="status-bar"
*ngFor="let build of project.builds.content | slice:0:12"
[ngClass]="{'status-success': build.result.toString() == 'PASSED', 'status-failure': build.result.toString() != 'PASSED'}"
[routerLink]="['/', 'projects', project.id, 'builds', build.id]"
ngbTooltip="{{build.result}}, {{build.startedAt | timeago}} - Took {{moment.utc(build.durationMs).format('HH:mm:ss')}}"
[routerLink]="['/', 'projects', project.id, 'builds', build.displayId]"
ngbTooltip="#{{build.displayId}} {{build.result}}, {{build.startedAt | timeago}} - Took {{moment.utc(build.durationMs).format('HH:mm:ss')}}"
tooltipClass="text-sm">
</a>
<div class="ms-auto pointer d-on-hover-target" ngbDropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ <h6>Build History</h6>
<tr>
<th></th>
<th scope="col" *ngFor="let build of buildPage.content">
#{{build.id}}
#{{build.displayId}}
</th>
</tr>
</thead>
<tbody>
<tr style="border-bottom-color: transparent;">
<td>Result</td>
<td *ngFor="let build of buildPage.content">
<span role="button" [routerLink]="['/', 'projects', projectId, 'builds', build.id]">
<span role="button" [routerLink]="['/', 'projects', projectId, 'builds', build.displayId]">
<i class="bi" [ngClass]="{
'bi-check-circle-fill text-success': build.result === 'PASSED',
'bi-x-circle-fill text-danger': build.result === 'FAILED'
Expand Down Expand Up @@ -87,8 +87,8 @@ <h6>Failing tests</h6>
<td>{{test.startedAt | date:'yyyy-MM-dd h:m:s a'}}</td>
<td>{{test.endedAt | date:'yyyy-MM-dd h:m:s a'}}</td>
<td>
<span class="badge badge-outline" role="button" [routerLink]="['/', 'projects', projectId, 'builds', test.buildId]">
<i class="bi bi-box-arrow-up-right me-2"></i>Build {{test.buildId}}</span>
<span class="badge badge-outline" role="button" [routerLink]="['/', 'projects', projectId, 'builds', test.buildDisplayId]">
<i class="bi bi-box-arrow-up-right me-2"></i>Build {{test.buildDisplayId}}</span>
</td>
</tr>
</tbody>
Expand Down
7 changes: 7 additions & 0 deletions chainlp/frontend/chainlp/src/app/services/build.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ export class BuildService extends BaseService<Build> {
return this.query(params);
}

findByDisplayId(projectId: number, displayId: number): Observable<Page<Build>> {
const params = new HttpParams()
.set('projectId', projectId)
.set('displayId', displayId);
return this.query(params);
}

}

0 comments on commit 4e9f552

Please sign in to comment.