Skip to content

Commit

Permalink
* Implemented the pull part of #56
Browse files Browse the repository at this point in the history
* Fixed Review.merge() since buffers were not closed
* Enhanced toasts in Composer
  • Loading branch information
benjboyer committed Apr 15, 2020
1 parent 0c80a0a commit 31545ac
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/main/groovy/io/peasoup/inv/cli/InitCommand.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InitCommand implements CliCommand {
return false
}

protected ScmExecutor.SCMReport processSCM() {
ScmExecutor.SCMReport processSCM() {
String actualFileLocation = initFileLocation
File scmFile

Expand Down
10 changes: 4 additions & 6 deletions src/main/groovy/io/peasoup/inv/composer/Review.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ class Review {
Files.copy(latestRun.toPath(), latestBackup.toPath())
assert latestBackup.exists(), 'Latest run backup file must be present on filesystem'

def generatedRun = new File(RunsRoller.latest.folder(), "run.txt")
generatedRun.delete()

DeltaGraph deltaGraph = new DeltaGraph(baseRun.newReader(), latestBackup.newReader())
DeltaGraph deltaGraph = new DeltaGraph(baseRun.newReader(), latestRun.newReader())
deltaGraph.removeScms(removeScms)
deltaGraph.resolve()

generatedRun << "This file was generated with Composer.${System.lineSeparator()}"
generatedRun.append(deltaGraph.merge())
latestRun.delete()
latestRun << "This file was generated with Composer.${System.lineSeparator()}"
latestRun.append(deltaGraph.merge())
}

Map compare() {
Expand Down
28 changes: 23 additions & 5 deletions src/main/groovy/io/peasoup/inv/composer/WebServer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import io.peasoup.inv.cli.InitCommand
import io.peasoup.inv.graph.GraphNavigator
import io.peasoup.inv.run.RunsRoller
import io.peasoup.inv.scm.ScmDescriptor
Expand Down Expand Up @@ -125,7 +126,8 @@ class WebServer {
],
initFile : [
default: "/initfile",
save: "/initfile"
save: "/initfile",
pull: "/initfile/pull"
],
run : [
default : "/run",
Expand Down Expand Up @@ -183,7 +185,7 @@ class WebServer {

get("/initfile", { Request req, Response res ->
if (!webServerConfigs.initFile)
return ""
return showError("Missing init file")

if (!(webServerConfigs.initFile instanceof String))
return showError(res, "InitFile is corrupted. Contact your administrator.")
Expand Down Expand Up @@ -225,6 +227,23 @@ class WebServer {
errors: exceptionMessages
])
})

post("/initfile/pull", { Request req, Response res ->
if (!webServerConfigs.initFile)
return showError("Missing init file")

if (!(webServerConfigs.initFile instanceof String))
return showError(res, "InitFile is corrupted. Contact your administrator.")

// Reuse InitCommand to pull init file
InitCommand initCommand = new InitCommand(initFileLocation: webServerConfigs.initFile as String)
def report = initCommand.processSCM()

if (!report)
showResult("Could not pull init")

return showResult("Pulled init successfully")
})
}

// Runs
Expand Down Expand Up @@ -485,7 +504,7 @@ class WebServer {

post("/scms/applyDefaultAll", { Request req, Response res ->
scms.elements.values().each { ScmFile.SourceFileElement element ->
if (run == null || !run.isSelected(element.descriptor.name))
if (run != null && !run.isSelected(element.descriptor.name))
return

def parametersFile = new File(parametersLocation, element.simpleName() + ".json")
Expand All @@ -501,8 +520,7 @@ class WebServer {
post("/scms/resetAll", { Request req, Response res ->

scms.elements.values().each { ScmFile.SourceFileElement element ->

if (!run.isSelected(element.descriptor.name))
if (run != null && !run.isSelected(element.descriptor.name))
return

def parametersFile = new File(parametersLocation, element.simpleName() + ".json")
Expand Down
7 changes: 5 additions & 2 deletions src/main/groovy/io/peasoup/inv/graph/DeltaGraph.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.peasoup.inv.graph

import groovy.text.SimpleTemplateEngine
import groovy.transform.CompileStatic
import groovy.transform.ToString
import io.peasoup.inv.run.InvInvoker
import io.peasoup.inv.run.RunsRoller

Expand Down Expand Up @@ -163,11 +162,15 @@ class DeltaGraph {
return "Report generated at: ${htmlOutput.canonicalPath}"
}

@ToString
static class DeltaLine {
String state
GraphNavigator.Linkable link
GraphNavigator.Node owner

@Override
String toString() {
"[${state}] ${link.value}"
}
}
}

2 changes: 2 additions & 0 deletions src/main/groovy/io/peasoup/inv/graph/RunGraph.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class RunGraph {
files << file
}
}

logs.close()
}

String toPlainList() {
Expand Down
27 changes: 24 additions & 3 deletions src/main/groovy/io/peasoup/inv/scm/ScmDescriptor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.peasoup.inv.scm
import groovy.json.JsonSlurper
import groovy.transform.CompileStatic
import io.peasoup.inv.Home
import io.peasoup.inv.run.Logger

@CompileStatic
class ScmDescriptor {
Expand Down Expand Up @@ -99,10 +100,30 @@ class ScmDescriptor {
class HookDescriptor {

String init
def init(String value) { this.init = value }
/**
* Indicates how the init (or initialization) phase should behave.
* It is similar to 'git clone', 'svn checkout', 'tf get', etc.
* @param value the Shell Script (Sh) commands
*/
void init(String value) { this.init = value }

String pull
/**
* Indicates how pull should behave
* @param value the Shell Script (Sh) commands
*/
void pull(String value) {this.pull = value }

String update
def update(String value) { this.update = value }
/**
* DEPRECATED. See 'pull' instead
* @param value
* @return
*/
@Deprecated
def update(String value) {
Logger.warn("scm.update() is deprecated. Use scm.pull() instead.")
pull(value)
}
}

class AskDescriptor {
Expand Down
8 changes: 4 additions & 4 deletions src/main/groovy/io/peasoup/inv/scm/ScmExecutor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class ScmExecutor {
report.isOk = executeCommands(repository, repository.hooks.init)
Logger.info("[SCM] name: ${name}, path: ${repository.path.canonicalPath} [INIT] done")

} else if (repository.hooks.update) {
} else if (repository.hooks.pull) {

Logger.info("[SCM] name: ${name}, path: ${repository.path.canonicalPath} [UPDATE] start")
report.isOk = executeCommands(repository, repository.hooks.update)
Logger.info("[SCM] name: ${name}, path: ${repository.path.canonicalPath} [UPDATE] done")
Logger.info("[SCM] name: ${name}, path: ${repository.path.canonicalPath} [PULL] start")
report.isOk = executeCommands(repository, repository.hooks.pull)
Logger.info("[SCM] name: ${name}, path: ${repository.path.canonicalPath} [PULL] done")
}

return report
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/public/imports/choose-inv.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ Vue.component('choose-inv', {

filter()
})
.catch(response => {
.catch(err => {
vm.$bus.$emit('toast', `error:Failed to <strong>fetch broadcast owners</strong>!`)
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/public/imports/configure-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ Vue.component('configure-init', {
vm.$bus.$emit('toast', `success:Saved <strong>init file</strong> successfully!`)
}
})
.catch(err => {
vm.$bus.$emit('toast', `error:Failed to <strong>save init file</strong>!`)
})
},
close: function() {
var vm = this
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/public/imports/configure-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Vue.component('configure-parameters', {
axios.post(vm.value.api.links.scms.applyDefaultAll).then(response => {
vm.updateIndex++

vm.$bus.$emit('toast', `success:Applied <strong>all defaults parameters</strong> successfully!`)
vm.$bus.$emit('toast', `warn:Applied <strong>all defaults parameters</strong> successfully!`)
})
},
resetAll: function() {
Expand Down Expand Up @@ -483,14 +483,16 @@ Vue.component('configure-parameters-carousel', {

vm.value.edit(scmParameters)
})
.catch(error => {
.catch(err => {

scmParameters.changed = false
scmParameters.loaded = false
scmParameters.loading = false

scmParameters.errors.push(error.response.data)
vm.$forceUpdate()

vm.$bus.$emit('toast', `error:Failed to <strong>edit parameters</strong>!`)
})
},
resetParameters: function(scmParameters) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/public/imports/configure-scms.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ Vue.component('configure-scms-details', {
vm.searchScm()
}
})
.catch(err => {
if (vm.mode == 'edit')
vm.$bus.$emit('toast', `success:Failed <strong>to save ${vm.editScript.descriptor.name}</strong>!`)

if (vm.mode == 'new')
vm.$bus.$emit('toast', `success:Failed <strong>to save ${vm.newName}</strong>!`)
})
},
closeEdit: function() {
var vm = this
Expand All @@ -284,6 +291,9 @@ Vue.component('configure-scms-details', {
vm.$bus.$emit('toast', `warn:Removed <strong>${scm.descriptor.name}</strong> successfully!`)
vm.searchScm()
})
.catch(err => {
vm.$bus.$emit('toast', `error:Failed <strong>to remove ${scm.descriptor.name}</strong>!`)
})
}
},
mounted: function() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/public/imports/configure-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Vue.component('configure-settings', {

vm.$bus.$emit('toast', `success:Saved <strong>settings.xml</strong> successfully!`)
})
.catch(err => {
vm.$bus.$emit('toast', `error:Failed <strong>to save settings.xml</strong>!`)
})
},
close: function() {
var vm = this
Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/public/imports/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Vue.component('layout', {
<a class="navbar-item" @click.stop="showConfigureSCMs()">Edit SCMs</a>
<a class="navbar-item" @click.stop="showConfigureInit()">Edit init file</a>
<hr class="navbar-divider">
<a class="navbar-item">Pull changes (coming soon!)</a>
<a class="navbar-item" @click.stop="pullInit()">Pull changes</a>
<a class="navbar-item">Push changes (coming soon!)</a>
<hr class="navbar-divider">
<a class="navbar-item has-text-danger">Reset everything (coming soon!)</a>
Expand Down Expand Up @@ -310,6 +310,15 @@ Vue.component('layout', {
showConfigureInit: function() {
this.navbar.configureInit.model.visible = true
},
pullInit: function() {
var vm = this
axios.post(vm.shared.api.links.initFile.pull).then(response => {
vm.$bus.$emit('toast', `success:Pulled <strong>init file changes</strong> successfully!`)
})
.catch(err => {
vm.$bus.$emit('toast', `error:Failed to <strong>pull init file changes</strong>!`)
})
}
},
mounted: function() {
var vm = this
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/public/imports/promote.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ Vue.component('promote', {
window.location.href = '#choose'
window.location.reload(true)
}, 1000)
}).catch(reponse => {
}).catch(err => {
vm.promoted = false
vm.promoting = false
vm.error = true

vm.$bus.$emit('toast', `error:Failed to <strong>promote</strong>!`)
})
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/public/imports/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Vue.component('review', {
vm.loading = false
vm.ready = true
})
.catch(function() {
.catch(err => {
vm.loading = false
})
},
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/public/imports/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ Vue.component('toast', {
clearInterval(vm.latestToast)

// Get which styleClass to use
if (message.startsWith('warn:')) {
vm.styleClass = 'is-warning'
if (message.startsWith('error:')) {
vm.styleClass = 'is-danger'
vm.message = message.substring(6)
} else if (message.startsWith('warn:')) {
vm.styleClass = 'is-primary'
vm.message = message.substring(5)
} else if (message.startsWith('success:')) {
vm.styleClass = 'is-success'
Expand Down
7 changes: 3 additions & 4 deletions src/test/groovy/io/peasoup/inv/composer/ReviewTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,22 @@ class ReviewTest {
RunsRoller.latest.roll() // make sure to roll once

// Generate base
def baseRun = new File(Home.getCurrent(), 'run.txt')
def baseRun = new File(Home.getCurrent(), 'base-merge.txt')
baseRun.delete()
baseRun << new File(getClass().getResource('/baseRun.txt').toURI()).text

// Generate subset
def subsetFile = new File(RunsRoller.latest.folder(), 'run.txt')
def subsetFile = new File(RunsRoller.latest.folder(), 'run-merge.txt')
subsetFile.delete()
subsetFile << new File(getClass().getResource('/subsetRun.txt').toURI()).text

def deltaGraph = new DeltaGraph(baseRun.newReader(), subsetFile.newReader())
deltaGraph.resolve()
def removed = deltaGraph.deltaLines.findAll { it.state == 'x' }

new Review(baseRun, subsetFile).merge()
assert subsetFile.exists()

def newBaseFileGraph = new RunGraph(subsetFile.newReader())
def removed = deltaGraph.deltaLines.findAll { it.state == 'x' }

assert removed.size() > 0
removed.each {
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/io/peasoup/inv/scm/ScmHandlerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ScmHandlerTest {

assert executor.scms["my-repository"].hooks
assert executor.scms["my-repository"].hooks.init.contains("mkdir my-repository")
assert executor.scms["my-repository"].hooks.update.contains("echo 'update'")
assert executor.scms["my-repository"].hooks.pull.contains("echo 'update'")
}

@Test
Expand Down

0 comments on commit 31545ac

Please sign in to comment.