-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (157 loc) · 6.39 KB
/
dapr-bot.yml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: dapr-bot
on:
issue_comment: {types: created}
jobs:
daprbot:
name: bot-processor
runs-on: ubuntu-latest
steps:
- name: Comment analyzer
uses: actions/github-script@v1
with:
github-token: ${{secrets.DAPR_BOT_TOKEN}}
script: |
// list of owner who can control dapr-bot workflow
// TODO: Read owners from OWNERS file.
const owners = [
'artursouza',
'berndverst',
'daixiang0',
'halspang',
'ItalyPaleAle',
'johnewart',
'msfussell',
'mukundansundar',
'pkedy',
'pruthvidhodda',
'shubham1172',
'skyao',
'tanvigour',
'yaron2'
];
const payload = context.payload;
const issue = context.issue;
const isFromPulls = !!payload.issue.pull_request;
const commentBody = payload.comment.body;
if (!isFromPulls && commentBody && commentBody.indexOf("/assign") == 0) {
if (!issue.assignees || issue.assignees.length === 0) {
await github.issues.addAssignees({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
assignees: [context.actor],
})
}
return;
}
// actions above this check are enabled for everyone.
if (owners.indexOf(context.actor) < 0) {
return;
}
if (commentBody && commentBody.indexOf("/make-me-laugh") == 0) {
const result = await github.request("https://official-joke-api.appspot.com/random_joke");
jokedata = result.data;
joke = "I have a bad feeling about this.";
if (jokedata && jokedata.setup && jokedata.punchline) {
joke = `${jokedata.setup} - ${jokedata.punchline}`;
}
await github.issues.createComment({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
body: joke,
});
return;
}
// Pollyfill: register createDispatchEvent because actions/[email protected]
// does not have createDispatchEvent.
github.registerEndpoints({
repos: {
createDispatchEvent: {
"headers": { "accept": "application/vnd.github.everest-preview+json" },
"method": "POST",
"params": {
"client_payload": { "type": "object" },
"event_type": { "type": "string" },
"owner": { "required": true, "type": "string" },
"repo": { "required": true, "type": "string" }
},
"url": "/repos/:owner/:repo/dispatches"
}
}
});
if (isFromPulls && commentBody) {
if (commentBody.indexOf("/ok-to-test") == 0) {
// Get pull request
const pull = await github.pulls.get({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number
});
if (pull && pull.data) {
// Get commit id and repo from pull head
const testPayload = {
pull_head_ref: pull.data.head.sha,
pull_head_repo: pull.data.head.repo.full_name,
command: "ok-to-test",
issue: issue,
};
// Fire repository_dispatch event to trigger e2e test
await github.repos.createDispatchEvent({
owner: issue.owner,
repo: issue.repo,
event_type: "e2e-test",
client_payload: testPayload,
});
console.log(`Trigger E2E test for ${JSON.stringify(testPayload)}`);
}
} else if (commentBody.indexOf("/build-windows-base") == 0) {
// Get pull request
const pull = await github.pulls.get({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number
});
if (pull && pull.data) {
// Get commit id and repo from pull head
const testPayload = {
pull_head_ref: pull.data.head.sha,
pull_head_repo: pull.data.head.repo.full_name,
command: "windows-base",
issue: issue,
};
// Fire repository_dispatch event to trigger e2e test
await github.repos.createDispatchEvent({
owner: issue.owner,
repo: issue.repo,
event_type: "windows-base",
client_payload: testPayload,
});
console.log(`Trigger a build of the windows base image ${JSON.stringify(testPayload)}`);
}
} else if (commentBody.indexOf("/ok-to-perf") == 0) {
// Get pull request
const pull = await github.pulls.get({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number
});
if (pull && pull.data) {
// Get commit id and repo from pull head
const perfPayload = {
pull_head_ref: pull.data.head.sha,
pull_head_repo: pull.data.head.repo.full_name,
command: "ok-to-perf",
issue: issue,
};
// Fire repository_dispatch event to trigger e2e test
await github.repos.createDispatchEvent({
owner: issue.owner,
repo: issue.repo,
event_type: "perf-test",
client_payload: perfPayload,
});
console.log(`Trigger Perf test for ${JSON.stringify(perfPayload)}`);
}
}
}