Merge pull request 'refs #4975 Added chat/send in mdbVersion/upload' (!1295) from 4975-mdbConfig-and-upload into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1295
This commit is contained in:
Guillermo Bonet 2023-02-01 06:21:03 +00:00
commit d30f471bc5
4 changed files with 76 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: false,
description: `The description of changes`
}, {
arg: 'unlock',
type: 'boolean',
@ -42,8 +47,7 @@ module.exports = Self => {
verb: 'POST'
}
});
Self.upload = async(ctx, appName, toVersion, branch, fromVersion, unlock, options) => {
Self.upload = async(ctx, options) => {
const models = Self.app.models;
const myOptions = {};
const $t = ctx.req.__; // $translate
@ -51,6 +55,12 @@ module.exports = Self => {
const AccessContainer = models.AccessContainer;
const fileOptions = {};
let tx;
const appName = ctx.args.appName;
const toVersion = ctx.args.toVersion;
const branch = ctx.args.branch;
const fromVersion = ctx.args.fromVersion;
let description = ctx.args.description;
const unlock = ctx.args.unlock;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -132,13 +142,46 @@ module.exports = Self => {
await fs.symlink(rootRelative, destinationRoot);
}
}
if (description) {
let formatDesc;
const mainBranches = new Set(['master', 'test', 'dev']);
if (mainBranches.has(branch))
formatDesc = `> :branch_${branch}: `;
else
formatDesc = `> :branch: `;
formatDesc += `*${appName.toUpperCase()}* v.${toVersion} `;
const oldVersion = await models.MdbVersionTree.findOne({
where: {version: fromVersion},
fields: ['branchFk']
}, myOptions);
if (branch == oldVersion.branchFk)
formatDesc += `[*${branch}*]: `;
else
formatDesc += `[*${oldVersion.branchFk}* » *${branch}*]: `;
const params = await models.MdbConfig.findOne(myOptions);
const issueTrackerUrl = params.issueTrackerUrl;
const issueNumberRegex = params.issueNumberRegex;
const chatDestination = params.chatDestination;
const regex = new RegExp(issueNumberRegex, 'g');
formatDesc += description.replace(regex, (match, issueId) => {
const newUrl = issueTrackerUrl.replace('{index}', issueId);
return `[#${issueId}](${newUrl})`;
});
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": {