Skip to content

Commit c7254a6

Browse files
authored
chore: update (#1)
1 parent 6c98da3 commit c7254a6

File tree

10 files changed

+6668
-118
lines changed

10 files changed

+6668
-118
lines changed

.env.example

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
# The ID of your GitHub App
2-
APP_ID=
3-
WEBHOOK_SECRET=development
4-
5-
# Use `trace` to get verbose logging or `info` to show less
6-
LOG_LEVEL=debug
7-
8-
# Go to https://smee.io/new set this to the URL that you are redirected to.
9-
WEBHOOK_PROXY_URL=
1+
APP_ID=<your app id>
2+
WEBHOOK_SECRET=<your app secret>
3+
PRIVATE_KEY_PATH=private-key.pem
4+
NODE_ENV=production

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/yarn.lock
21
/node_modules
32
.env
4-
/lib
3+
/lib
4+
.vercel
5+
/dist
6+
/private-key.pem.prod

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# alain-bot
2+
3+
https://github.com/Developerayo/probot/blob/probot-deployment-docs/docs/deployment.md#vercel

now.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,32 @@
1414
],
1515
"scripts": {
1616
"build": "tsc -p tsconfig.json",
17-
"dev": "nodemon --exec \"npm start\"",
1817
"start": "probot run ./lib/index.js",
1918
"probot-config": "probot run ./lib/index.js",
2019
"lint": "standard **/*.ts --fix",
2120
"test": "jest && standard **/*.ts",
2221
"test:watch": "jest --watch --notify --notifyMode=change --coverage"
2322
},
2423
"dependencies": {
25-
"@types/uuid": "^3.4.4",
26-
"@vitalets/google-translate-api": "^2.8.0",
27-
"axios": "^0.19.0",
28-
"js-yaml": "^3.13.1",
29-
"kmp": "^0.0.3",
30-
"nock": "^10.0.0",
31-
"probot": "^7.2.0",
24+
"probot": "^9.13.0",
25+
"probot-serverless-now": "^2.1.2",
26+
"axios": "^0.19.2",
3227
"string-template": "^1.0.0",
33-
"uuid": "^3.3.2"
28+
"kmp": "^0.0.3",
29+
"@google-cloud/translate": "^6.0.2"
3430
},
3531
"devDependencies": {
36-
"@types/jest": "^24.0.0",
37-
"@types/js-yaml": "^3.12.1",
38-
"@types/nock": "^9.3.0",
39-
"@types/node": "^11.9.0",
32+
"@types/jest": "^26.0.8",
33+
"@types/node": "^14.0.27",
4034
"@types/string-template": "^1.0.2",
41-
"eslint-plugin-typescript": "^0.14.0",
42-
"jest": "^24.0.0",
43-
"nodemon": "^1.17.2",
44-
"smee-client": "^1.0.2",
45-
"standard": "^12.0.1",
46-
"ts-jest": "^24.0.0",
47-
"typescript": "^3.3.1",
35+
"jest": "^26.2.2",
36+
"standard": "^14.3.4",
37+
"ts-jest": "^26.1.4",
38+
"typescript": "^3.9.7",
4839
"typescript-eslint-parser": "^22.0.0"
4940
},
5041
"engines": {
51-
"node": ">= 8.3.0"
42+
"node": "12.x"
5243
},
5344
"standard": {
5445
"parser": "typescript-eslint-parser",

private-key.pem

Whitespace-only changes.

src/bot.ts

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { LoggerWithTarget } from "probot/lib/wrap-logger";
33
import format from "string-template";
44

55
import { Config } from "./interfaces/config.interface";
6-
import { OrgsListMembersResponseItem } from "@octokit/rest";
6+
import { Octokit } from "@octokit/rest";
7+
// import { v2 } from "@google-cloud/translate";
8+
// const translate = new v2.Translate({ projectId: "458602011089" });
79

8-
const translate = require("@vitalets/google-translate-api");
910
const kmp = require("kmp");
1011
const axios = require("axios");
1112

@@ -50,7 +51,7 @@ export class Bot {
5051

5152
try {
5253
if (this.context.event.search("pull_request") !== -1) {
53-
await this.context.github.pullRequests.createReviewRequest(
54+
await this.context.github.pulls.createReviewRequest(
5455
this.context.issue({ reviewers: assignees })
5556
);
5657
} else {
@@ -172,52 +173,52 @@ export class Bot {
172173
}
173174
}
174175

175-
async replyTranslate() {
176-
const config = this.config.issue.translate;
177-
const issue = this.context.payload.issue;
178-
if (containsChinese(issue.title)) {
179-
const body = await translate(issue.body.replace(/<!--(.*?)-->/g, ""), {
180-
from: "zh-CN",
181-
to: "en",
182-
});
183-
const title = await translate(issue.title, { from: "zh-CN", to: "en" });
184-
if (body.text && title.text) {
185-
let content = format(config.replay, {
186-
title: title.text,
187-
body: body.text,
188-
});
189-
const issueComment = this.context.issue({ body: content });
190-
191-
this.log.trace(
192-
{
193-
issue,
194-
issueComment,
195-
},
196-
"translating issue..."
197-
);
198-
199-
try {
200-
await this.context.github.issues.createComment(issueComment);
201-
this.log.info(
202-
{
203-
issue,
204-
issueComment,
205-
},
206-
"translated issue."
207-
);
208-
} catch (e) {
209-
this.log.error(
210-
{
211-
error: new Error(e),
212-
issue,
213-
issueComment,
214-
},
215-
"translate issue error!"
216-
);
217-
}
218-
}
219-
}
220-
}
176+
// async replyTranslate() {
177+
// const config = this.config.issue.translate;
178+
// const issue = this.context.payload.issue;
179+
// if (containsChinese(issue.title)) {
180+
// const [body] = await translate.translate(
181+
// issue.body.replace(/<!--(.*?)-->/g, ""),
182+
// "en"
183+
// );
184+
// const [title] = await translate.translate(issue.title, "en");
185+
// if (body && title) {
186+
// let content = format(config.replay, {
187+
// title: title,
188+
// body: body,
189+
// });
190+
// const issueComment = this.context.issue({ body: content });
191+
192+
// this.log.trace(
193+
// {
194+
// issue,
195+
// issueComment,
196+
// },
197+
// "translating issue..."
198+
// );
199+
200+
// try {
201+
// await this.context.github.issues.createComment(issueComment);
202+
// this.log.info(
203+
// {
204+
// issue,
205+
// issueComment,
206+
// },
207+
// "translated issue."
208+
// );
209+
// } catch (e) {
210+
// this.log.error(
211+
// {
212+
// error: new Error(e),
213+
// issue,
214+
// issueComment,
215+
// },
216+
// "translate issue error!"
217+
// );
218+
// }
219+
// }
220+
// }
221+
// }
221222

222223
async replyNeedReproduce() {
223224
const config = this.config.issue.needReproduce;
@@ -377,7 +378,7 @@ export class Bot {
377378
}
378379

379380
private async getMembers(): Promise<string[]> {
380-
let members: OrgsListMembersResponseItem[] = [];
381+
let members: Octokit.OrgsListMembersResponseItem[] = [];
381382
const repo = this.context.repo();
382383
let response = await this.context.github.orgs.listMembers({
383384
org: repo.owner,

src/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { Application, Context } from "probot";
22
import { LoggerWithTarget } from "probot/lib/wrap-logger";
3-
import uuid from "uuid/v4";
43

5-
import { Bot } from "./bot";
4+
// import { Bot } from "./bot";
65
import { Config } from "./interfaces/config.interface";
76

87
export = async (app: Application) => {
98
const github = await app.auth();
109
const name = (await github.apps.getAuthenticated({})).data.name;
11-
const id = uuid();
1210

1311
// app.on("release.published", async (context) => {
1412
// const logger = getLogger(context);
@@ -25,20 +23,22 @@ export = async (app: Application) => {
2523
// });
2624

2725
app.on("issues.opened", async (context) => {
28-
const logger = getLogger(context);
29-
const config = await getConfig(context, logger);
30-
const bot = new Bot(context, config, logger);
31-
await bot.replyInvalid();
32-
await bot.replyTranslate();
33-
// await bot.addComponentLabel();
26+
console.log(context);
27+
// const logger = getLogger(context);
28+
// const config = await getConfig(context, logger);
29+
// const bot = new Bot(context, config, logger);
30+
// await bot.replyInvalid();
31+
// // await bot.replyTranslate();
32+
// // await bot.addComponentLabel();
3433
});
3534

3635
app.on("issues.labeled", async (context) => {
37-
const logger = getLogger(context);
38-
const config = await getConfig(context, logger);
39-
const bot = new Bot(context, config, logger);
40-
await bot.replyNeedReproduce();
41-
await bot.replyLabeled();
36+
console.log(context);
37+
// const logger = getLogger(context);
38+
// const config = await getConfig(context, logger);
39+
// const bot = new Bot(context, config, logger);
40+
// await bot.replyNeedReproduce();
41+
// await bot.replyLabeled();
4242
});
4343

4444
// app.on(["issues.labeled", "pull_request.labeled"], async (context) => {
@@ -73,6 +73,6 @@ export = async (app: Application) => {
7373
}
7474

7575
function getLogger(context: Context) {
76-
return context.log.child({ name, id });
76+
return context.log.child({ name, id: "ng-alain-bot" });
7777
}
7878
};

tsconfig.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
"noUnusedLocals": false,
1111
"pretty": true,
1212
"strict": true,
13-
"sourceMap": true,
13+
"sourceMap": false,
1414
"outDir": "./lib",
1515
"skipLibCheck": true,
1616
"noImplicitAny": true,
1717
"esModuleInterop": true,
18-
"declaration": true,
18+
"declaration": false,
1919
"resolveJsonModule": true
2020
},
21-
"include": [
22-
"src/**/*"
23-
],
21+
"include": ["src/**/*"],
2422
"compileOnSave": false
2523
}

0 commit comments

Comments
 (0)