diff --git a/src/config.ts b/src/config.ts index 627d54eca..f70bccd24 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,7 +6,6 @@ import { buildMattermostConfig } from "./lib/mattermost/config" const isSecure = (process.env.SECURE || 'true') === 'true'; - const userStatusOptions = [ { label: 'Indépendant', value: 'independent' }, { diff --git a/src/controllers/budgetController.ts b/src/controllers/budgetController.ts index fe066e28c..62a885ac6 100644 --- a/src/controllers/budgetController.ts +++ b/src/controllers/budgetController.ts @@ -50,7 +50,7 @@ function buildBudgetURL(startup, budget) { if (budget.startsWith('http') || parseInt(budget) === NaN) { return budget } else { - const startDts = startup?.phases?.map(p => p?.start).filter(p => p) || [] + const startDts = startup.attributes?.phases?.map(p => p?.start).filter(p => p) || [] startDts.sort() const url = new URL('https://beta-gouv-fr-budget.netlify.app') @@ -73,7 +73,7 @@ export async function determineMetadata(req, res, next) { }) } - const [subcommand, startupId, budget] = req.body?.text.split(" ")?.filter(e => e.length) || [] + const [subcommand, startupId, details] = req.body?.text.split(" ")?.filter(e => e.length) || [] const startups = await betagouv.startupsInfos() const startup = startups.find(s => s.id == startupId) if (!startup) { @@ -82,32 +82,35 @@ export async function determineMetadata(req, res, next) { }) } req.startup = startup - req.budget_url = buildBudgetURL(startup, budget) - - return res.json({ - text: `${req.body?.user_name} vient de demander la génération d'une page budget :smiley: (avec la commande \`${req.body?.command} ${req.body?.text}\` :tada:). + console.log(subcommand) + if (subcommand === "page") { + req.budget_url = buildBudgetURL(startup, details) + return res.json({ + text: `${req.body?.user_name} vient de demander la génération d'une page budget :smiley: (avec la commande \`${req.body?.command} ${req.body?.text}\` :tada:). La voilà : ${req.budget_url} Si vous avez des questions ou des problèmes, n'hésitez pas à rejoindre le canal [~domaine-transparence-budget](https://mattermost.incubateur.net/betagouv/channels/domaine-transparence-budget) :smiley: `, - response_type: 'in_channel', - attachments: [{ - actions: [{ - "id": `${req.body.trigger_id}-publish`, - "name": "Publier cette première version", - "integration": { - "url": "/notifications/budget/mattermost", - "context": { - "token": req.body.token, - "startup": startupId, - "budget_url": req.budget_url, + response_type: 'in_channel', + attachments: [{ + actions: [{ + "id": `${req.body.trigger_id}-publish`, + "name": "Publier cette première version", + "integration": { + "url": "/notifications/budget/mattermost", + "context": { + "token": req.body.token, + "startup": startupId, + "budget_url": req.budget_url, + } } - } + }] }] - }] - }) - + }) + } + req.budget_url = details req.channel_url = `${mattermost.servers[req.mattermostServerId]}/${req.body?.team_domain}/channels/${req.body?.channel_name}` + next() } async function addStartupProps(startup, props, res) { @@ -139,7 +142,7 @@ async function addStartupProps(startup, props, res) { export async function createPullRequest(req, res, next) { const data = { budget_url: req.budget_url, - channel_url: req.channel_url, + //channel_url: req.channel_url, } const result = await addStartupProps(req.startup, data, res) return res.json({text: "DONE", response_type: "in_channel", ...result}) diff --git a/src/index.ts b/src/index.ts index c569c5860..1fd453de4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,7 +61,6 @@ app.use(session({ cookie: { maxAge: 300000, sameSite: 'lax' } })); // Only used app.use(flash()); app.use(expressSanitizer()); app.use(bodyParser.urlencoded({ extended: false })); -app.use(bodyParser.json()); const getJwtTokenForUser = (id) => jwt.sign({ id }, config.secret, { expiresIn: '7 days' }); @@ -78,7 +77,7 @@ app.use( '/signin', '/marrainage/accept', '/marrainage/decline', - /notifications\/budget*/, + '/notifications/budget', '/notifications/github', '/onboarding', /onboardingSuccess\/*/, @@ -140,14 +139,9 @@ app.post( '/notifications/github', githubNotificationController.processNotification ); -app.post('/notifications/budget/mattermost', - budgetController.determineMattermostServer, - budgetController.checkToken, - budgetController.determineMetadata, - budgetController.createPullRequest, - ); - -app.post('/notifications/budget/site', +/*app.use('/notifications/budget', + bodyParser.json())*/ +app.post('/notifications/budget', budgetController.determineMattermostServer, budgetController.checkToken, budgetController.determineMetadata, diff --git a/src/lib/frontmatter.ts b/src/lib/frontmatter.ts index ac545b9d9..c6c9e18f6 100644 --- a/src/lib/frontmatter.ts +++ b/src/lib/frontmatter.ts @@ -1,6 +1,5 @@ import YAML from "yaml"; - export function applyChanges(text, changes) { const changeKeys = Object.keys(changes) const updates = {} @@ -47,4 +46,4 @@ export function applyChanges(text, changes) { content, updates } -} \ No newline at end of file +}