Skip to content

Commit 6b9259d

Browse files
committed
feat: minimal working version
1 parent 6047f2f commit 6b9259d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

dist/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const _default: (robot: any, name: RegExp, callback: (context: any, issues: RegExpMatchArray) => void) => void;
2+
export default _default;

dist/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
class Command {
4+
constructor(cmd, callback) {
5+
this.cmd = cmd;
6+
this.callback = callback;
7+
this.pattern = /CMD +((([\w-.]+\/[\w-.]+)?#\d+) *((, *)? *and +|, *)?)+/i;
8+
}
9+
get command() {
10+
const raw = this.pattern.source;
11+
// Warning: We ignore this.cmd flags
12+
return new RegExp(raw.replace(/CMD/, this.cmd.source), this.pattern.flags);
13+
}
14+
issues(str) {
15+
return str.match(/(?:[\w-.]+\/[\w-.]+)?#\d+/g);
16+
}
17+
listener(context) {
18+
const match = context.payload.comment.body.match(this.command);
19+
if (match) {
20+
this.callback(context, this.issues(match[0]));
21+
}
22+
}
23+
}
24+
/**
25+
* A Probot extension to make it easier to working with issue commands.
26+
*
27+
* @example
28+
*
29+
* // Type `closes #1, and owner/repo#2`
30+
* commands(robot, /clos(es|ing)/, (context, issues) => {
31+
* console.log(issues)
32+
* // ['#1','owner/repo#2', ...]
33+
* })
34+
*/
35+
exports.default = (robot, name, callback) => {
36+
const command = new Command(name, callback);
37+
robot.on('issue_comment.created', command.listener.bind(command));
38+
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
"author": "Ahmed T. Ali <ah.tajelsir@gmail.com>",
99
"license": "MIT",
1010
"scripts": {
11+
"prepublish": "tsc",
1112
"test": "jest",
1213
"semantic-release": "semantic-release"
1314
},
15+
"files": ["dist/index.js", "README.md"],
1416
"devDependencies": {
1517
"@types/jest": "^22.0.0",
1618
"jest": "^22.0.4",

0 commit comments

Comments
 (0)