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',
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({

View File

@ -11,6 +11,9 @@
"MdbVersionTree": {
"dataSource": "vn"
},
"MdbConfig": {
"dataSource": "vn"
},
"AccessContainer": {
"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": {
"type": "number"
},
"description": {
"type": "string"
}
},
"relations": {