From a59807e7fc6ec72b63016b6111f9f395fc14a337 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 30 Jan 2023 14:23:58 +0100 Subject: [PATCH] refs #4975 Method upload now send rocket message --- modules/mdb/back/methods/mdbVersion/upload.js | 47 +++++++++++++++++-- modules/mdb/back/model-config.json | 3 ++ modules/mdb/back/models/mdbConfig.json | 24 ++++++++++ modules/mdb/back/models/mdbVersionTree.json | 3 ++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 modules/mdb/back/models/mdbConfig.json diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 1df4365a9..09392b3c0 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -26,6 +26,11 @@ module.exports = Self => { type: 'string', required: true, description: `The old version number` + }, { + arg: 'description', + type: 'string', + required: true, + description: `The description of changes` }, { arg: 'unlock', type: 'boolean', @@ -42,8 +47,8 @@ module.exports = Self => { verb: 'POST' } }); - - Self.upload = async(ctx, appName, toVersion, branch, fromVersion, unlock, options) => { + // Cambiar a forma corta: ejemplo: ctx.appName + Self.upload = async(ctx, appName, toVersion, branch, fromVersion, description, unlock, options) => { const models = Self.app.models; const myOptions = {}; const $t = ctx.req.__; // $translate @@ -133,12 +138,48 @@ module.exports = Self => { } } + let formatDesc; + // eslint-disable-next-line no-constant-condition + if (branch == 'master' || 'test' || 'dev') + formatDesc = `> :branch_${branch}: `; + else + formatDesc = `> :branch: `; + + formatDesc += `*${appName.toUpperCase()}* v.${toVersion} `; + const fromBranch = await models.MdbVersionTree.find({ + where: {version: fromVersion}, + fields: ['branchFk'] + }); + if (branch == fromBranch[0].branchFk) + formatDesc += `[*${branch}*]: `; + else + formatDesc += `[*${fromBranch}* ยป *${branch}*]: `; + + const params = await models.MdbConfig.find({}); + const issueTrackerUrl = params[0].issueTrackerUrl; + const issueNumberRegex = params[0].issueNumberRegex; + const chatDestination = params[0].chatDestination; + + const regex = new RegExp(issueNumberRegex, 'g'); + const matches = description.matchAll(regex); + if (matches) { + for (const match of matches) { + let issueId = match[0]; + let newUrl = issueTrackerUrl.replace('{index}', match[1]); + description = description.replace(` ${issueId}`, ` [${issueId}](${newUrl})`); + } + } + formatDesc += description; + + await models.Chat.send(ctx, chatDestination, formatDesc, myOptions); + await models.MdbVersionTree.create({ app: appName, version: toVersion, branchFk: branch, fromVersion, - userFk: userId + userFk: userId, + description }, myOptions); await models.MdbVersion.upsert({ diff --git a/modules/mdb/back/model-config.json b/modules/mdb/back/model-config.json index 8010afca2..b59a4fda0 100644 --- a/modules/mdb/back/model-config.json +++ b/modules/mdb/back/model-config.json @@ -11,6 +11,9 @@ "MdbVersionTree": { "dataSource": "vn" }, + "MdbConfig": { + "dataSource": "vn" + }, "AccessContainer": { "dataSource": "accessStorage" } diff --git a/modules/mdb/back/models/mdbConfig.json b/modules/mdb/back/models/mdbConfig.json new file mode 100644 index 000000000..60634104a --- /dev/null +++ b/modules/mdb/back/models/mdbConfig.json @@ -0,0 +1,24 @@ +{ + "name": "MdbConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "mdbConfig" + } + }, + "properties": { + "id": { + "type": "string", + "id": true + }, + "issueTrackerUrl": { + "type": "string" + }, + "issueNumberRegex": { + "type": "string" + }, + "chatDestination": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/modules/mdb/back/models/mdbVersionTree.json b/modules/mdb/back/models/mdbVersionTree.json index 8c0260e54..106473b64 100644 --- a/modules/mdb/back/models/mdbVersionTree.json +++ b/modules/mdb/back/models/mdbVersionTree.json @@ -23,6 +23,9 @@ }, "userFk": { "type": "number" + }, + "description": { + "type": "string" } }, "relations": {