Improve issue/merge_request regexps;
This commit is contained in:
parent
90245819af
commit
8efdd4544a
33
index.js
33
index.js
@ -222,11 +222,40 @@ function fetch_and_say(isIssue, id, from, chan) {
|
||||
});
|
||||
}
|
||||
|
||||
var issueRegexp = /(?:\s|^)#(\d+)/g;
|
||||
var mergeRequestRegexp = /(?:\s|^)!(\d+)/g;
|
||||
|
||||
function testIssueRegexp(r) {
|
||||
function test(input, expected) {
|
||||
var match = r.exec(input);
|
||||
var found = 0;
|
||||
while (match !== null) {
|
||||
if (match[1] !== expected[found].toString()) {
|
||||
throw new Error('should have found ' + expected[found]);
|
||||
}
|
||||
found++;
|
||||
match = r.exec(input);
|
||||
}
|
||||
if (expected.length !== found) {
|
||||
throw new Error('missing expected occurrences: ' + expected.length + 'vs expected ' + found);
|
||||
}
|
||||
r.lastIndex = 0;
|
||||
}
|
||||
|
||||
test('hello #301 jeej', [301]);
|
||||
test('#302 lol', [302]);
|
||||
test('lol#303', []);
|
||||
test('lol #303', [303]);
|
||||
test('\t#304', [304]);
|
||||
test(' #305', [305]);
|
||||
test('hello#305 #306 jeej#42 #307 #lol # #308', [306, 307, 308]);
|
||||
};
|
||||
|
||||
testIssueRegexp(issueRegexp);
|
||||
|
||||
app.listen(config.port, config.hostname, function() {
|
||||
console.log('gitlab-to-irc running.');
|
||||
|
||||
var issueRegexp = /#(\d+)/g;
|
||||
var mergeRequestRegexp = /!(\d+)/g;
|
||||
client.on('message', function(from, chan, message) {
|
||||
var matches = null;
|
||||
while ((matches = issueRegexp.exec(message)) !== null) {
|
||||
|
Loading…
Reference in New Issue
Block a user