-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Extract view build log into command
- Loading branch information
1 parent
51956b1
commit b810761
Showing
5 changed files
with
119 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {window} from "vscode"; | ||
import {VstsBuildRestClient} from "../vstsbuildrestclient"; | ||
import {Settings} from "../settings"; | ||
import {BuildQuickPicker} from "../components/BuildQuickPicker"; | ||
import {BuildLogViewer} from "../components/BuildLogViewer"; | ||
|
||
export default class OpenBuildLogCommand { | ||
private buildQuickPicker: BuildQuickPicker; | ||
private logViewer: BuildLogViewer; | ||
|
||
constructor(private settings: Settings, private restClient: VstsBuildRestClient) { | ||
this.buildQuickPicker = new BuildQuickPicker(settings, restClient); | ||
this.logViewer = new BuildLogViewer(restClient); | ||
} | ||
|
||
public execute() { | ||
this.buildQuickPicker.showBuildDefinitionQuickPick("Select a build definition") | ||
.then(result => { | ||
if (!result) { | ||
return; | ||
} | ||
|
||
if (result.length > 1) { | ||
window.showInformationMessage(`Viewing group build is not possible, please select single build instead.`); | ||
return; | ||
} | ||
|
||
return this.buildQuickPicker.showBuildQuickPick(result[0].id, "Select a build to view"); | ||
}) | ||
.then(build => { | ||
if (!build) { | ||
return; | ||
} | ||
|
||
this.logViewer.viewLog(build.id); | ||
}); | ||
} | ||
|
||
public dispose() { | ||
if (this.logViewer) { | ||
this.logViewer.dispose; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use strict"; | ||
|
||
import {window, OutputChannel} from "vscode"; | ||
import {VstsBuildRestClient} from "../vstsbuildrestclient"; | ||
|
||
|
||
export class BuildLogViewer { | ||
private outputChannel: OutputChannel; | ||
private intervalTimer: NodeJS.Timer; | ||
private updateIntervalInSeconds: number = 5; | ||
private currentLogIndex: number = 0; | ||
|
||
constructor(private restClient: VstsBuildRestClient) { | ||
} | ||
|
||
public viewLog(buildId: number) { | ||
if (!this.outputChannel) { | ||
this.outputChannel = window.createOutputChannel("VSTS Build Log"); | ||
} | ||
|
||
this.outputChannel.clear(); | ||
this.outputChannel.show(); | ||
|
||
this.getNext(buildId); | ||
} | ||
|
||
private getNext(buildId: number) { | ||
if (this.currentLogIndex === 0) { | ||
this.outputChannel.appendLine("(VSTS Build Agent Status extension) Waiting for first logs..."); | ||
} | ||
|
||
let getBuild = this.restClient.getBuild(buildId); | ||
let getLog = getBuild.then(build => this.restClient.getLog(build.value)); | ||
|
||
Promise.all([getBuild, getLog]).then(value => { | ||
let build = value[0]; | ||
let log = value[1]; | ||
|
||
if (!log) { | ||
return; | ||
} | ||
|
||
var newLogEntries = log.value.messages.splice(this.currentLogIndex); | ||
newLogEntries.forEach(element => { | ||
this.outputChannel.appendLine(element); | ||
}); | ||
|
||
this.currentLogIndex = this.currentLogIndex + newLogEntries.length; | ||
|
||
if (build.value.status === "completed") { | ||
clearInterval(this.intervalTimer); | ||
this.intervalTimer = null; | ||
this.currentLogIndex = 0; | ||
|
||
this.outputChannel.appendLine("(VSTS Build Agent Status extension) End of build log") | ||
} else if (build.value.status !== "completed" && !this.intervalTimer) { | ||
this.intervalTimer = setInterval(() => this.getNext(buildId), this.updateIntervalInSeconds * 1000); | ||
} | ||
}); | ||
} | ||
|
||
public dispose() { | ||
if (this.outputChannel) { | ||
this.outputChannel.dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters