-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
76 lines (61 loc) · 2.67 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Probot } from 'probot';
const commitMessageRegex = /^(fix|feat|docs|style|refactor|test|chore|perf|ci|build|bump|release|merge|revert|wip|work in progress): .*$/;
const pullRequestTitleRegex = /^(fix|feat|docs|style|refactor|test|chore|perf|ci|build|bump|release|merge|revert|wip|work in progress): .*$/;
const branchTitleRegex = /^(fix|feat|docs|style|refactor|test|chore|perf|ci|build|bump|release|merge|revert|wip|work in progress)\/.*$/;
const app = new Application<Context>();
app.on('push', async (context) => {
const { payload } = context.payload;
const { ref, commits } = payload;
if (ref === 'refs/heads/main' || ref === 'refs/heads/master') {
for (const commit of commits) {
const { message } = commit;
if (!commitMessageRegex.test(message)) {
await context.github.issues.createComment(context.issue({ body: 'Commit message does not match regex pattern.' }));
}
}
}
});
app.on('pull_request.opened', async (context) => {
const { payload } = context.payload;
const { title } = payload.pull_request;
if (!pullRequestTitleRegex.test(title)) {
await context.github.issues.createComment(context.issue({ body: 'Pull request title does not match regex pattern.' }));
}
const { head } = payload.pull_request;
const { ref } = head;
if (!branchTitleRegex.test(ref)) {
await context.github.issues.createComment(context.issue({ body: 'Branch title does not match regex pattern.' }));
}
});
app.on('pull_request.labeled', async (context) => {
const { payload } = context.payload;
const { label } = payload;
if (label.name === 'approved') {
await context.github.pulls.merge(context.pullRequest({ merge_method: 'merge' }));
await context.github.issues.createComment(context.issue({ body: 'Pull request merged.' }));
}
});
app.on('issues.opened', async (context) => {
const { payload } = context.payload;
const { title } = payload;
if (title === 'Release new version') {
const { name } = context.repo();
const { version } = await context.github.packages.getLatestPackageVersion({
owner: context.repo().owner,
repo: context.repo().repo,
package_type: 'npm',
});
await context.github.issues.createComment(context.issue({ body: `The latest version is ${version}.` }));
} else if (title === 'Deploy') {
const { name } = context.repo();
const { html_url } = await context.github.repos.createDeployment({
owner: context.repo().owner,
repo: context.repo().repo,
ref: 'main',
auto_merge: true,
required_contexts: [],
});
await context.github.issues.createComment(context.issue({ body: `Deployment created: ${html_url}` }));
}
});
export default app;