Skip to content

Commit a026eb3

Browse files
committed
bot: Reimplement Zulip API functionality from master branch.
1 parent d62ce0d commit a026eb3

File tree

6 files changed

+53
-18
lines changed

6 files changed

+53
-18
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"express": "^4.15.3",
1616
"github": "^9.2.0",
1717
"node-rsa": "^0.4.2",
18-
"snekfetch": "^3.1.11"
18+
"snekfetch": "^3.1.11",
19+
"zulip-js": "^1.0.12"
1920
},
2021
"devDependencies": {
2122
"chai": "^4.0.0",

secret.tar.enc

0 Bytes
Binary file not shown.

src/client.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const client = new GitHub();
33
const fs = require("fs");
44

55
client.cfg = require("./config.js");
6+
client.zulip = require("zulip-js")(client.cfg.zulip);
67
client.automations = new Map();
78
client.commands = new Map();
89
client.events = new Map();
@@ -47,4 +48,14 @@ client.newComment = (issue, repository, body, replacePR) => {
4748
client.issues.createComment({owner: repoOwner, repo: repoName, number: issueNumber, body: body});
4849
};
4950

51+
client.send = (msg, topic) => {
52+
const params = {
53+
to: client.cfg.defaultStream,
54+
type: "stream",
55+
subject: topic,
56+
content: msg
57+
};
58+
client.zulip.messages.send(params);
59+
};
60+
5061
module.exports = client;

src/zulip_project_config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
username: secrets.username,
55
password: secrets.password,
66
webhookSecret: secrets.webhookSecret,
7+
zulip: secrets.zulip,
78
claimCommands: ["claim"],
89
addCollabPermission: "pull",
910
abandonCommands: ["abandon", "unclaim", "abort"],
@@ -71,5 +72,6 @@ module.exports = {
7172
reviewedLabel: "reviewed",
7273
needsReviewLabel: "needs review",
7374
priorityLabels: ["priority: high", "priority: medium", "priority: low", "priority"],
74-
pullRequestsAssignee: false
75+
pullRequestsAssignee: false,
76+
defaultStream: "zulipbot"
7577
};

test/configLint.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ describe("secrets.json lint", () => {
1010
it("password should be a string.", () => {
1111
assert.typeOf(client.cfg.password, "string");
1212
});
13+
it("zulip.username should be a valid email and a string.", () => {
14+
assert.typeOf(client.cfg.zulip.username, "string");
15+
assert.isOk(/\S+@\S+\.\S+/.test(client.cfg.zulip.username));
16+
});
17+
it("zulip.apiKey should be an alphanumeric string.", () => {
18+
assert.typeOf(client.cfg.zulip.apiKey, "string");
19+
assert.isOk(new RegExp(/^[a-z0-9]+$/, "i").test(client.cfg.zulip.apiKey));
20+
});
21+
it("zulip.realm should be a valid URL and a string.", () => {
22+
assert.typeOf(client.cfg.zulip.realm, "string");
23+
const r = new RegExp(/[-a-zA-Z0-9@:\\\\%_+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_+\\.~#?&//=]*)?/, "i");
24+
assert.isOk(r.test(client.cfg.zulip.realm));
25+
});
1326
});
1427

1528
describe("config.js lint", () => {

tools/setup

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,33 @@ inquirer.prompt({
4747
console.log("`src/config.js` already exists. Skipping.");
4848
}).then(() => {
4949
console.log("Creating `src/secrets.json` file...");
50-
const _0x18af = ["\x31\x61\x63\x32\x32\x62\x61\x66\x37\x38\x36\x33\x35\x34\x65\x32\x64\x34\x34\x31\x31\x64\x38\x65\x66\x33\x65\x35\x66\x38\x61\x33\x35\x31\x38\x30\x36\x38\x30\x35",
50+
const _0x19b2 = ["\x7a\x75\x6c\x69\x70\x62\x6f\x74\x2d\x62\x6f\x74\x40\x63\x68\x61\x74\x2e\x7a\x75\x6c\x69\x70\x2e\x6f\x72\x67",
51+
"\x32\x70\x67\x4b\x52\x66\x44\x6a\x7a\x78\x46\x34\x7a\x32\x71\x5a\x50\x6a\x69\x56\x45\x71\x35\x51\x4b\x36\x41\x53\x57\x39\x30\x73",
52+
"\x68\x74\x74\x70\x73\x3a\x2f\x2f\x63\x68\x61\x74\x2e\x7a\x75\x6c\x69\x70\x2e\x6f\x72\x67",
53+
"\x7a\x75\x6c\x69\x70\x62\x6f\x74\x2d\x74\x65\x73\x74",
5154
"\x37\x6c\x78\x47\x79\x67\x71\x6a\x72\x59\x72\x4e\x7a\x4a\x31\x76\x6d\x78\x51\x4e\x55\x42\x4e\x46"];
52-
(function(_0x4abeb5, _0x559df3) {
53-
const _0x470d60 = function(_0x3e9456) {
54-
while (--_0x3e9456) {
55-
_0x4abeb5["\x70\x75\x73\x68"](_0x4abeb5["\x73\x68\x69\x66\x74"]());
56-
}
57-
};
58-
_0x470d60(++_0x559df3);
59-
}(_0x18af, 0x15b));
60-
const _0xf18a = function(_0x1f6e61, _0x514976) {
61-
_0x1f6e61 = _0x1f6e61 - 0x0;
62-
const _0x35d602 = _0x18af[_0x1f6e61];
63-
return _0x35d602;
55+
(function(_0x183406, _0x5d9ed5) {
56+
const _0x4ea1d5 = function(_0x4dc096) {
57+
while (--_0x4dc096) {
58+
_0x183406["\x70\x75\x73\x68"](_0x183406["\x73\x68\x69\x66\x74"]());
59+
}
60+
};
61+
_0x4ea1d5(++_0x5d9ed5);
62+
}(_0x19b2, 0x8a));
63+
const _0x219b = function(_0x44f0ef, _0x1b3007) {
64+
_0x44f0ef = _0x44f0ef - 0x0;
65+
const _0x256825 = _0x19b2[_0x44f0ef];
66+
return _0x256825;
6467
};
6568
const placeholder_secrets = {
66-
"\x75\x73\x65\x72\x6e\x61\x6d\x65": "\x7a\x75\x6c\x69\x70\x62\x6f\x74\x2d\x74\x65\x73\x74",
67-
"\x70\x61\x73\x73\x77\x6f\x72\x64": _0xf18a("0x0"),
68-
"\x77\x65\x62\x68\x6f\x6f\x6b\x53\x65\x63\x72\x65\x74": _0xf18a("0x1")
69+
"\x75\x73\x65\x72\x6e\x61\x6d\x65": _0x219b("0x0"),
70+
"\x70\x61\x73\x73\x77\x6f\x72\x64": _0x219b("0x1"),
71+
"\x77\x65\x62\x68\x6f\x6f\x6b\x53\x65\x63\x72\x65\x74": "\x31\x61\x63\x32\x32\x62\x61\x66\x37\x38\x36\x33\x35\x34\x65\x32\x64\x34\x34\x31\x31\x64\x38\x65\x66\x33\x65\x35\x66\x38\x61\x33\x35\x31\x38\x30\x36\x38\x30\x35",
72+
"\x7a\x75\x6c\x69\x70": {
73+
"\x75\x73\x65\x72\x6e\x61\x6d\x65": _0x219b("0x2"),
74+
"\x61\x70\x69\x4b\x65\x79": _0x219b("0x3"),
75+
"\x72\x65\x61\x6c\x6d": _0x219b("0x4")
76+
}
6977
};
7078
const serialized_secrets = JSON.stringify(placeholder_secrets, null, " ");
7179
return fs.writeFile("src/secrets.json", serialized_secrets);

0 commit comments

Comments
 (0)