Skip to content

Commit

Permalink
Add notification upon trigger execution
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartinou committed Dec 7, 2024
1 parent 1d925ba commit bde9dc6
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 93 deletions.
5 changes: 5 additions & 0 deletions app/api/trigger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const component = require('./component');
const registry = require('../registry');
const log = require('../log').child({ component: 'trigger' });

/**
* Run a specific trigger on a specific container provided in the payload.
Expand All @@ -14,12 +15,14 @@ async function runTrigger(req, res) {

const triggerToRun = registry.getState().trigger[`trigger.${triggerType}.${triggerName}`];
if (!triggerToRun) {
log.warn(`No trigger found(type=${triggerType}, name=${triggerName})`);
res.status(404).json({
error: `Error when running trigger ${triggerType}.${triggerName} (trigger not found)`,
});
return;
}
if (!containerToTrigger) {
log.warn(`Trigger cannot be executed without container (type=${triggerType}, name=${triggerName})`);
res.status(400).json({
error: `Error when running trigger ${triggerType}.${triggerName} (container is undefined)`,
});
Expand All @@ -28,8 +31,10 @@ async function runTrigger(req, res) {

try {
await triggerToRun.trigger(containerToTrigger);
log.info(`Trigger executed with success (type=${triggerType}, name=${triggerName}, container=${JSON.stringify(containerToTrigger)})`);
res.status(200).json({});
} catch (e) {
log.warn(`Trigger cannot be executed without container (type=${triggerType}, name=${triggerName})`);
res.status(500).json({
error: `Error when running trigger ${triggerType}.${triggerName} (${e.message})`,
});
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/ContainerFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
this.isRefreshing = true;
try {
const body = await refreshAllContainers();
this.$root.$emit("notify", `All containers refreshed`);
this.$root.$emit("notify", "All containers refreshed");
this.$emit("refresh-all-containers", body);
} catch (e) {
this.$root.$emit(
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/SnackBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
},
timeout: {
type: Number,
default: 2000,
default: 4000,
},
message: {
type: String,
Expand Down
202 changes: 112 additions & 90 deletions ui/src/components/TriggerDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,8 @@
</v-app-bar>
<v-expand-transition>
<v-card-text v-show="showDetail">
<v-navigation-drawer
v-model="testForm"
absolute
right
temporary
width="512"
>
<v-container>
<v-card-subtitle class="text-body-1">
<v-icon>mdi-test-tube</v-icon>
Test trigger</v-card-subtitle
>
<v-text-field
label="Container ID"
v-model="container.id"
append-icon="mdi-identifier"
outlined
dense
/>
<v-text-field
label="Container Name"
v-model="container.name"
append-icon="mdi-pencil"
outlined
dense
/>
<v-text-field
label="Container Watcher"
v-model="container.watcher"
append-icon="mdi-update"
outlined
dense
/>
<v-select
label="Update kind"
v-model="container.updateKind.kind"
:items="['digest', 'tag']"
:append-icon="
container.updateKind.kind === 'tag' ? 'mdi-tag' : 'mdi-pound'
"
outlined
dense
/>
<v-select
v-if="container.updateKind.kind === 'tag'"
label="Update semver diff"
v-model="container.updateKind.semverDiff"
:items="['major', 'minor', 'patch']"
:append-icon="
container.updateKind.semverDiff === 'major'
? 'mdi-alert'
: container.updateKind.semverDiff === 'minor'
? 'mdi-alert-decagram'
: 'mdi-information'
"
outlined
dense
/>
<v-text-field
label="Container local value"
v-model="container.updateKind.localValue"
append-icon="mdi-tag"
outlined
dense
/>
<v-text-field
label="Container remote value"
v-model="container.updateKind.remoteValue"
append-icon="mdi-tag-check"
outlined
dense
/>
<v-btn outlined small class="accent" block @click="runTrigger"
>Run trigger</v-btn
>
</v-container>
</v-navigation-drawer>
<v-row>
<v-col :lg="6" :md="6">
<v-col cols="8">
<v-list dense v-if="configurationItems.length > 0">
<v-list-item
v-for="configurationItem in configurationItems"
Expand All @@ -103,15 +26,101 @@
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-btn outlined small class="accent" @click="testForm = true">
Test
<v-icon right>mdi-test-tube</v-icon>
</v-btn>
</v-list-item>
</v-list>
<span v-else>Default configuration</span>
</v-col>
<v-col cols="4" class="text-right">
<v-btn outlined small class="accent" @click="showTestForm = true">
Test
<v-icon right>mdi-test-tube</v-icon>
</v-btn>

<v-navigation-drawer
v-model="showTestForm"
absolute
right
temporary
width="512"
>
<v-container class="text-left">
<v-card-subtitle class="text-body-1">
<v-icon>mdi-test-tube</v-icon>
Test trigger</v-card-subtitle
>
<v-text-field
label="Container ID"
v-model="container.id"
append-icon="mdi-identifier"
outlined
dense
/>
<v-text-field
label="Container Name"
v-model="container.name"
append-icon="mdi-pencil"
outlined
dense
/>
<v-text-field
label="Container Watcher"
v-model="container.watcher"
append-icon="mdi-update"
outlined
dense
/>
<v-select
label="Update kind"
v-model="container.updateKind.kind"
:items="['digest', 'tag']"
:append-icon="
container.updateKind.kind === 'tag'
? 'mdi-tag'
: 'mdi-pound'
"
outlined
dense
/>
<v-select
v-if="container.updateKind.kind === 'tag'"
label="Update semver diff"
v-model="container.updateKind.semverDiff"
:items="['major', 'minor', 'patch']"
:append-icon="
container.updateKind.semverDiff === 'major'
? 'mdi-alert'
: container.updateKind.semverDiff === 'minor'
? 'mdi-alert-decagram'
: 'mdi-information'
"
outlined
dense
/>
<v-text-field
label="Container local value"
v-model="container.updateKind.localValue"
append-icon="mdi-tag"
outlined
dense
/>
<v-text-field
label="Container remote value"
v-model="container.updateKind.remoteValue"
append-icon="mdi-tag-check"
outlined
dense
/>
<v-btn
outlined
small
class="accent"
block
@click="runTrigger"
:loading="isTriggering"
>Run trigger</v-btn
>
</v-container>
</v-navigation-drawer>
</v-col>
</v-row>
</v-card-text>
</v-expand-transition>
Expand All @@ -132,7 +141,8 @@ export default {
data() {
return {
showDetail: true,
testForm: false,
showTestForm: false,
isTriggering: false,
container: {
id: "123456789",
name: "container_test",
Expand Down Expand Up @@ -179,11 +189,23 @@ export default {
this.showDetail = !this.showDetail;
},
async runTrigger() {
await runTrigger({
triggerType: this.trigger.type,
triggerName: this.trigger.name,
container: this.container,
});
this.isTriggering = true;
try {
await runTrigger({
triggerType: this.trigger.type,
triggerName: this.trigger.name,
container: this.container,
});
this.$root.$emit("notify", "Trigger executed with success");
} catch (err) {
this.$root.$emit(
"notify",
`Trigger executed with error (${err.message}})`,
"error",
);
} finally {
this.isTriggering = false;
}
},
},
filters: {
Expand Down
6 changes: 5 additions & 1 deletion ui/src/services/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ async function runTrigger({ triggerType, triggerName, container }) {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(container),
});
return response.json();
const json = await response.json();
if (response.status !== 200) {
throw new Error(json.error ? json.error : "Unknown error");
}
return json;
}

export { getTriggerIcon, getAllTriggers, runTrigger };

0 comments on commit bde9dc6

Please sign in to comment.