Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to trigger events directly from the API #137

Merged
merged 3 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions back-end/domain/module/AbstractModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AbstractModule {
}

/**
* @param config
* @param {Status} status
*/
fireEvent(config, status) {
Expand Down
29 changes: 29 additions & 0 deletions back-end/routes/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const app = (module.exports = require('express')());
const EventTrigger = require('../domain/event/EventTrigger.js');
const Config = require('../config/ConfigLoaderFactory')
.getLoader()
.getConfig();

app.post('/', (request, response) => {
console.log('/event [POST]');

const eventName = request.body.event;

if (!eventName) {
return response.status(422).json({
message: `Missing required field "event".`,
});
}

if (Config.getEventByName(eventName)) {
EventTrigger.fireModulesForEvent(eventName, null);

return response.json({
message: 'Event has been triggered!',
});
}

return response.status(404).json({
message: `The given event name "${eventName}" is not found.`,
});
});
1 change: 1 addition & 0 deletions back-end/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ app.use('/webhook', require('./webhook'));
app.use('/debug', require('./debug'));
app.use('/contributors', require('./contributors'));
app.use('/version', require('./version'));
app.use('/event', require('./event.js'));
29 changes: 28 additions & 1 deletion docs/status-API.md → docs/API.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Status API
# API

- [Statuses](#statuses)
- [Events](#events)

## Statuses

### POST /status

@todo: Explain that you can manually push statuses to the `POST /status`. The API will let you know what's required or not.

Expand All @@ -22,6 +29,26 @@
| `image` | no | An URL to an image representing the status |
| `userImage` | no | An URL to an image showing the user who triggered the status |

### DELETE /status/:status-key

@todo: Explain that you can remove statues using `DELETE /status/:status-key`

### GET /status/clear-all

@todo: Explain that yo can remove all statuses using `GET /status/clear-all`

## Events

### POST /event

You can directly trigger an event (configured in the configuration) via `POST /event`.

```json
{
"event": "celebrate-success"
}
```

| key | required? | description |
| ----------- | --------- | -------------------------------------------------------------------------- |
| `event` | yes | The configuration key that is used for the event that should be triggered. |
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pages:
- Run as a service: setup/run-as-service.md
- Run with Docker: setup/run-with-docker.md
- Setup Raspberry: setup/Raspberry.md
- Status API: status-API.md
- CIMonitor API: API.md
- Link a service:
- GitLab: services/GitLab.md
- Travis CI: services/Travis-CI.md
Expand Down
3 changes: 1 addition & 2 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ mix.copy('front-end/static/', 'dashboard/');
if (!mix.inProduction()) {
mix.webpackConfig({ devtool: `inline-source-map` });

const Config = require('./back-end/config/Config');
mix.browserSync({
proxy: `localhost:${Config.getServerPort()}`,
proxy: `localhost:9999`,
injectChanges: false,
files: [`dashboard/**/*`],
});
Expand Down