Skip to content

Commit

Permalink
Use the manifest for pix bot build
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Apr 27, 2022
1 parent c2c6a32 commit e38a6e5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 71 deletions.
43 changes: 13 additions & 30 deletions build/controllers/manifest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const manifest = require('../manifest');

module.exports = {
async get(request) {
const protocol = request.headers['x-forwarded-proto'] ? request.headers['x-forwarded-proto'] : 'http';
const { host } = request.info;
const url = `${protocol}://${host}`;
return {
display_information: {
name: 'Pix Bot Build'
name: manifest.name
},
features: {
bot_user: {
display_name: 'Pix Bot Build',
display_name: manifest.name,
always_online: false
},
shortcuts: [
Expand All @@ -20,34 +22,15 @@ module.exports = {
description: 'Publie une nouvelle version et la déploie sur l\'environnement de recette'
}
],
slash_commands: [
{
command: '/pr-pix',
url: `${url}/slack/commands/pull-requests`,
description: 'Afficher les PR à review de l\'application Pix',
usage_hint: '[cross-team|team-acces|team-evaluation|team-certif|team-prescription]',
should_escape: false
},
{
command: '/tips-a11y',
url: `${url}/slack/commands/accessibility-tip`,
description: 'Je veux un tips sur l\'accessibilité !',
should_escape: false
},
{
command: '/changelog',
url: `${url}/slack/commands/changelog`,
description: 'Afficher le changelog depuis la dernière release',
should_escape: false
},
{
command: '/hotfix',
url: `${url}/slack/commands/create-and-deploy-pix-hotfix`,
description: 'Créer une version patch à partir d\'une branche et la déployer en recette',
usage_hint: '[branch-name]',
should_escape: false
}
]
slash_commands: manifest.slashCommands.map(({ command, path, description, usage_hint, should_escape }) => {
return {
command,
url: `${url}${path}`,
description,
usage_hint,
should_escape,
};
})
},
oauth_config: {
scopes: {
Expand Down
41 changes: 41 additions & 0 deletions build/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { Manifest } = require('../common/models/Manifest');
const slackbotController = require('./controllers/slack');
const googleSheet = require('./services/google-sheet');

const manifest = new Manifest('Pix Bot Build');

manifest.registerSlashCommand({
command: '/pr-pix',
path: '/slack/commands/pull-requests',
description: 'Afficher les PR à review de l\'application Pix',
usage_hint: '[cross-team|team-acces|team-evaluation|team-certif|team-prescription]',
should_escape: false,
handler: slackbotController.getPullRequests,
});

manifest.registerSlashCommand({
command: '/tips-a11y',
path: '/slack/commands/accessibility-tip',
description: 'Je veux un tips sur l\'accessibilité !',
should_escape: false,
handler: googleSheet.getA11YTip,
});

manifest.registerSlashCommand({
command: '/changelog',
path: '/slack/commands/changelog',
description: 'Afficher le changelog depuis la dernière release',
should_escape: false,
handler: slackbotController.getChangelogSinceLatestRelease,
});

manifest.registerSlashCommand({
command: '/hotfix',
path: '/slack/commands/create-and-deploy-pix-hotfix',
description: 'Créer une version patch à partir d\'une branche et la déployer en recette',
usage_hint: '[branch-name]',
should_escape: false,
handler: slackbotController.createAndDeployPixHotfix,
});

module.exports = manifest;
30 changes: 0 additions & 30 deletions build/routes/slack.js

This file was deleted.

11 changes: 0 additions & 11 deletions run/routes/slack.js

This file was deleted.

16 changes: 16 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ require('dotenv').config();
const path = require('path');
const Hapi = require('@hapi/hapi');
const config = require('./config');
const runManifest = require('./run/manifest');
const buildManifest = require('./build/manifest');
const { slackConfig } = require('./common/config');
const manifests = [runManifest, buildManifest];

const server = Hapi.server({
port: config.port,
Expand All @@ -17,4 +21,16 @@ const server = Hapi.server({
.forEach((file) => server.route(require(path.join(routesDir, file))));
});

manifests.forEach((manifest) => {
const routes = manifest
.getHapiRoutes()
.map((route) => {
return {
...route,
config: slackConfig,
};
});
server.route(routes);
});

module.exports = server;
2 changes: 2 additions & 0 deletions test/acceptance/build/manifest_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ describe('Acceptance | Build | Manifest', function() {
command: '/tips-a11y',
url: `http://${hostname}/slack/commands/accessibility-tip`,
description: 'Je veux un tips sur l\'accessibilité !',
usage_hint: undefined,
should_escape: false
},
{
command: '/changelog',
url: `http://${hostname}/slack/commands/changelog`,
description: 'Afficher le changelog depuis la dernière release',
usage_hint: undefined,
should_escape: false
},
{
Expand Down

0 comments on commit e38a6e5

Please sign in to comment.