Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 35ffaa2

Browse files
committed
Merge branch 'dev' into main
2 parents 440a3a9 + 8d144cc commit 35ffaa2

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sudo-bot/gh-deployer",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"description": "A GitHub deployer robot",
55
"main": "dist/index.js",
66
"private": false,

src/commands.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ interface responseManager {
193193
];
194194
}
195195

196+
const cleanCommand = (text: string) => {
197+
const posSeparator = text.lastIndexOf('\n-- \n');
198+
if (typeof posSeparator === 'number' && posSeparator > 0) {
199+
return text.substring(0, posSeparator);
200+
}
201+
// Alternative, replace known content
202+
return text
203+
.replace('\n-- \nYou are receiving this because you were mentioned.', '')
204+
.replace('\nReply to this email directly or view it on GitHub:\n', '')
205+
.replace('https://github.com/', 'ref:')
206+
.replace('issuecomment', '');
207+
};
208+
196209
export default {
197210
train: () => {
198211
return manager.train();
@@ -204,12 +217,10 @@ export default {
204217
DEPLOY_AND_MERGE_WITH_CONFIG_COMMANDS: DEPLOY_AND_MERGE_WITH_CONFIG_COMMANDS,
205218
DEPLOY_AND_MERGE_COMMANDS: DEPLOY_AND_MERGE_COMMANDS,
206219
DEPLOY_WITH_CONFIG_COMMANDS: DEPLOY_WITH_CONFIG_COMMANDS,
220+
cleanCommand: cleanCommand,
207221
getCommand: (text: string) => {
208222
logger.debug('Start getCommand:', text);
209-
text = text.replace('\n\n-- \nYou are receiving this because you were mentioned.', '');
210-
text = text.replace('\nReply to this email directly or view it on GitHub:\n', '');
211-
text = text.replace('https://github.com/', '');
212-
text = text.replace('issuecomment', '');
223+
text = cleanCommand(text);
213224
logger.debug('Start getCommand:', text);
214225
return new Promise((resolve: (data: commandData) => void, reject) => {
215226
logger.debug('Manager process text:', text);

test/commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ export default async function () {
245245
})
246246
.catch((err) => done(err));
247247
});
248+
test('test cleanCommand', function () {
249+
let text =
250+
'@bot Deploy PR\n\n-- \nYou are receiving this because you were mentioned.\nReply to this email directly or view it on GitHub:\nhttps://github.com/phpmyadmin/phpmyadmin/pull/15493#issuecomment-552420382';
251+
expect(commands.cleanCommand(text)).to.equal('@bot Deploy PR\n');
252+
});
253+
test('test cleanCommand no sep', function () {
254+
let text =
255+
'@bot Deploy PR\n\nYou are receiving this because you were mentioned.\nReply to this email directly or view it on GitHub:\nhttps://github.com/phpmyadmin/phpmyadmin/pull/15493#issuecomment-552420382';
256+
expect(commands.cleanCommand(text)).to.equal(
257+
'@bot Deploy PR\n\nYou are receiving this because you were mentioned.ref:phpmyadmin/phpmyadmin/pull/15493#-552420382'
258+
);
259+
});
248260
/*test('test deploy and merge a into b', function(done) {
249261
let command = commands.getCommand('Deploy and merge QA into master');
250262
command

0 commit comments

Comments
 (0)