refs #4975 Method upload now send rocket message
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2023-01-30 14:23:58 +01:00
parent ce1bdaec17
commit a59807e7fc
4 changed files with 74 additions and 3 deletions

View File

@ -26,6 +26,11 @@ module.exports = Self => {
type: 'string', type: 'string',
required: true, required: true,
description: `The old version number` description: `The old version number`
}, {
arg: 'description',
type: 'string',
required: true,
description: `The description of changes`
}, { }, {
arg: 'unlock', arg: 'unlock',
type: 'boolean', type: 'boolean',
@ -42,8 +47,8 @@ module.exports = Self => {
verb: 'POST' verb: 'POST'
} }
}); });
// Cambiar a forma corta: ejemplo: ctx.appName
Self.upload = async(ctx, appName, toVersion, branch, fromVersion, unlock, options) => { Self.upload = async(ctx, appName, toVersion, branch, fromVersion, description, unlock, options) => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {}; const myOptions = {};
const $t = ctx.req.__; // $translate 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({ await models.MdbVersionTree.create({
app: appName, app: appName,
version: toVersion, version: toVersion,
branchFk: branch, branchFk: branch,
fromVersion, fromVersion,
userFk: userId userFk: userId,
description
}, myOptions); }, myOptions);
await models.MdbVersion.upsert({ await models.MdbVersion.upsert({

View File

@ -11,6 +11,9 @@
"MdbVersionTree": { "MdbVersionTree": {
"dataSource": "vn" "dataSource": "vn"
}, },
"MdbConfig": {
"dataSource": "vn"
},
"AccessContainer": { "AccessContainer": {
"dataSource": "accessStorage" "dataSource": "accessStorage"
} }

View File

@ -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"
}
}
}

View File

@ -23,6 +23,9 @@
}, },
"userFk": { "userFk": {
"type": "number" "type": "number"
},
"description": {
"type": "string"
} }
}, },
"relations": { "relations": {