Skip to content

Commit

Permalink
fix(ui): correctly display metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
error418 committed Sep 23, 2019
1 parent 7dc5518 commit 44062b6
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/github/commit-status-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CommitStatusSender {
name: event.payload.sender,
output: {
title: event.payload.title,
summary: event.markdown || event.payload.shortMessage
summary: event.markdown || event.payload.shortMessage || ""
}
};

Expand Down
9 changes: 8 additions & 1 deletion src/core/pages/page-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import HealthService, { HealthState } from "../health-service";
import { CoreConfig } from "../core-config";
import { HistoryService } from "../history/history-service";
import { LOGGER } from "../../logger";
import { query } from "winston";
import { SwingletreeUtil } from "../../util";

@injectable()
class PageRoutes {
Expand Down Expand Up @@ -93,6 +93,12 @@ class PageRoutes {
});
}

private flatten(object: any) {
const result = SwingletreeUtil.flattenObject(object);
console.log(JSON.stringify(result, null, 2));
return result;
}

public getRoute(): Router {
const router = Router();

Expand All @@ -102,6 +108,7 @@ class PageRoutes {
res.locals.healthStates = this.healthService.getStates(HealthState.DOWN);
res.locals.isBuildHistoryEnabled = this.isBuildHistoryEnabled;
res.locals.path = req.path;
res.locals.flatten = this.flatten;

res.locals.componentIcon = this.componentIcon;
res.locals.moment = require("moment");
Expand Down
25 changes: 17 additions & 8 deletions src/nebula/status-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ import { NebulaConfig } from "./config";
import EventBus from "../core/event/event-bus";
import { NotificationEvent } from "../core/event/event-model";
import { Swingletree } from "../core/model";
import { TemplateEngine, Templates } from "../core/template/template-engine";
import { NebulaEvents } from "./events";
import { NebulaModel } from "./model";


@injectable()
export class NebulaStatusEmitter {
private readonly eventBus: EventBus;
private readonly templateEngine: TemplateEngine;
private readonly context: string;

constructor(
@inject(EventBus) eventBus: EventBus,
@inject(ConfigurationService) configurationService: ConfigurationService,
@inject(TemplateEngine) templateEngine: TemplateEngine
@inject(ConfigurationService) configurationService: ConfigurationService
) {
this.eventBus = eventBus;
this.templateEngine = templateEngine;
this.context = configurationService.get(NebulaConfig.CONTEXT);

eventBus.register(NebulaEvents.EventType.REPORT_RECEIVED, this.reportReceivedHandler, this);
Expand All @@ -30,20 +26,33 @@ export class NebulaStatusEmitter {
public getAnnotations(report: NebulaModel.Report): Swingletree.Annotation[] {
const annotations: Swingletree.Annotation[] = [];

// TODO: implement

return annotations;
}

public reportReceivedHandler(event: NebulaEvents.ReportReceivedEvent) {
const annotations = this.getAnnotations(event.report);
const build = event.report.payload.build;

const notificationData: Swingletree.AnalysisReport = {
sender: this.context,
source: event.source,
checkStatus: event.report.payload.build.result.status == NebulaModel.ResultValue.SUCCESS ? Swingletree.Conclusion.PASSED : Swingletree.Conclusion.BLOCKED,
title: `Gradle Build`,
title: `${event.report.payload.build.testCount} Tests`,
metadata: {
project: build.project,
java: {
version: build.info.javaVersion,
detailVersion: build.info.detailedJavaVersion
},
gradle: {
version: build.info.build.gradle.version
},
build: {
elapsedTime: build.elapsedTime
},
test: {
count: build.testCount
}
},
annotations: annotations
};
Expand Down
20 changes: 20 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class SwingletreeUtil {
public static flattenObject(obj: any) {
const segment: any = {};

for (const i in obj) {
if (!obj.hasOwnProperty(i)) continue;

if (obj[i] instanceof Object && obj[i] !== null) {
const flatObject = this.flattenObject(obj[i]);
for (const x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
segment[i + "." + x] = flatObject[x];
}
} else {
segment[i] = obj[i];
}
}
return segment;
}
}
2 changes: 1 addition & 1 deletion swingletree.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ github:
nebula:
enabled: false
secret: # basic auth password protecting the webhook
context: gradle/zap # defines the check status name
context: gradle/nebula # defines the check status name
debug: false # log zap webhook event requests on debug level

# SonarQube specific configuration
Expand Down
38 changes: 38 additions & 0 deletions test/util.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";

import { suite, test, describe } from "mocha";
import { expect, assert } from "chai";
import * as chai from "chai";
import * as sinon from "sinon";
import { SwingletreeUtil } from "../src/util";

chai.use(require("sinon-chai"));

const sandbox = sinon.createSandbox();

describe("ConfigurationService", () => {

describe("Utilities", () => {
it("should flatten objects", () => {
const testObj = {
a: {
b: "c",
d: {
e: "f",
g: "h",
array: [ 1, 2, 3 ]
}
}
};

const result = SwingletreeUtil.flattenObject(testObj);

expect(result["a.d.e"]).to.be.equal("f");
expect(result["a.d.g"]).to.be.equal("h");
expect(result["a.b"]).to.be.equal("c");
expect(result["a.d.array.0"]).to.be.equal(1);
expect(result["a.d.array.1"]).to.be.equal(2);
expect(result["a.d.array.2"]).to.be.equal(3);
});
});
});
5 changes: 3 additions & 2 deletions views/builds.pug
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ block content
if item.metadata
table(class="table table-sm build-list")
tbody
each key, index in Object.keys(item.metadata)
-var flatMetadata = flatten(item.metadata)
each key in Object.keys(flatMetadata)
tr
td=key
td=item.metadata[key]
td=flatMetadata[key]
else
span None
div.col-md-7
Expand Down

0 comments on commit 44062b6

Please sign in to comment.