Skip to content

Commit c6fc55c

Browse files
committed
Add more commands to dapr bot
Signed-off-by: Shubham Sharma <[email protected]>
1 parent e56f31d commit c6fc55c

File tree

2 files changed

+185
-12
lines changed

2 files changed

+185
-12
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Copyright 2022 The Dapr Authors
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
#
13+
14+
name: dapr-bot-schedule
15+
16+
on:
17+
schedule:
18+
- cron: '*/10 * * * *'
19+
workflow_dispatch:
20+
jobs:
21+
prune_stale:
22+
name: Prune Stale
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Prune Stale
26+
uses: actions/[email protected]
27+
with:
28+
repo-token: ${{ secrets.DAPR_BOT_TOKEN }}
29+
days-before-issue-stale: 60
30+
days-before-pr-stale: 30
31+
days-before-close: 7
32+
stale-issue-message: >
33+
This issue has been automatically marked as stale because it has not had activity in the
34+
last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity
35+
occurs. Thank you for your contributions.
36+
close-issue-message: >
37+
This issue has been automatically closed because it has not had activity in the
38+
last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved.
39+
Thank you for your contributions.
40+
stale-pr-message: >
41+
This pull request has been automatically marked as stale because it has not had
42+
activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please
43+
feel free to give a status update now, ping for review, or re-open when it's ready.
44+
Thank you for your contributions!
45+
close-pr-message: >
46+
This pull request has been automatically closed because it has not had
47+
activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready.
48+
Thank you for your contributions!
49+
stale-issue-label: 'stale'
50+
exempt-issue-labels: 'pinned,good first issue,help wanted,triaged/resolved'
51+
stale-pr-label: 'stale'
52+
exempt-pr-labels: 'pinned'
53+
operations-per-run: 500
54+
ascending: true

.github/workflows/dapr-bot.yml

Lines changed: 131 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,137 @@ jobs:
2727
with:
2828
github-token: ${{secrets.DAPR_BOT_TOKEN}}
2929
script: |
30-
const payload = context.payload;
31-
const issue = context.issue;
32-
const isFromPulls = !!payload.issue.pull_request;
33-
const commentBody = payload.comment.body;
34-
if (!isFromPulls && commentBody && commentBody.indexOf("/assign") == 0) {
35-
if (!issue.assignees || issue.assignees.length === 0) {
36-
await github.issues.addAssignees({
30+
// list of owner who can control dapr-bot workflow
31+
// TODO: Read owners from OWNERS file.
32+
const owners = [
33+
"yaron2",
34+
"youngbupark",
35+
"Haishi2016",
36+
"lukekim",
37+
"amanbha",
38+
"msfussell",
39+
"shalabhms",
40+
"LMWF",
41+
"artursouza",
42+
"vinayada1",
43+
"mukundansundar",
44+
"wcs1only",
45+
"orizohar",
46+
"pruthvidhodda",
47+
"mchmarny",
48+
"tcnghia",
49+
"berndverst",
50+
"halspang",
51+
"tanvigour",
52+
"dmitsh",
53+
"pkedy",
54+
"CodeMonkeyLeet",
55+
"XavierGeerinck",
56+
"amulyavarote",
57+
"shubham1172"
58+
];
59+
60+
const payload = context.payload;
61+
const issue = context.issue;
62+
const isFromPulls = !!payload.issue.pull_request;
63+
const commentBody = payload.comment.body;
64+
if (!isFromPulls && commentBody && commentBody.indexOf("/assign") == 0) {
65+
if (!issue.assignees || issue.assignees.length === 0) {
66+
await github.issues.addAssignees({
67+
owner: issue.owner,
68+
repo: issue.repo,
69+
issue_number: issue.number,
70+
assignees: [context.actor],
71+
})
72+
}
73+
return;
74+
}
75+
76+
// the author of this issue is interacting with it
77+
if (!isFromPulls && context.actor == issue.owner) {
78+
// if there is a 'needs-author-feedback' label,
79+
// replace it with 'needs-team-attention'.
80+
var labels = await github.issues.listLabelsOnIssue({
81+
issue_number: issue.number,
3782
owner: issue.owner,
3883
repo: issue.repo,
39-
issue_number: issue.number,
40-
assignees: [context.actor],
41-
})
84+
});
85+
labels.forEach(label => {
86+
if (label.name == 'needs-author-feedback') {
87+
await github.issues.removeLabel({
88+
issue_number: issue.number,
89+
owner: issue.owner,
90+
repo: issue.repo,
91+
name: 'needs-author-feedback'
92+
});
93+
await github.issues.addLabels({
94+
issue_number: issue.number,
95+
owner: issue.owner,
96+
repo: issue.repo,
97+
labels: ['needs-team-attention']
98+
})
99+
}
100+
});
42101
}
43-
return;
44-
}
102+
103+
// actions above this check are enabled for everyone.
104+
if (owners.indexOf(context.actor) < 0) {
105+
return;
106+
}
107+
108+
// Pollyfill: register createDispatchEvent because actions/[email protected]
109+
// does not have createDispatchEvent.
110+
github.registerEndpoints({
111+
repos: {
112+
createDispatchEvent: {
113+
"headers": { "accept": "application/vnd.github.everest-preview+json" },
114+
"method": "POST",
115+
"params": {
116+
"client_payload": { "type": "object" },
117+
"event_type": { "type": "string" },
118+
"owner": { "required": true, "type": "string" },
119+
"repo": { "required": true, "type": "string" }
120+
},
121+
"url": "/repos/:owner/:repo/dispatches"
122+
}
123+
}
124+
});
125+
126+
if (!isFromPulls && commentBody) {
127+
if (commentBody.indexOf("/ok-to-test") == 0) {
128+
// Get pull request
129+
const pull = await github.pulls.get({
130+
owner: issue.owner,
131+
repo: issue.repo,
132+
pull_number: issue.number
133+
});
134+
if (pull && pull.data) {
135+
// Get commit id and repo from pull head
136+
const testPayload = {
137+
pull_head_ref: pull.data.head.sha,
138+
pull_head_repo: pull.data.head.repo.full_name,
139+
command: "ok-to-test",
140+
issue: issue,
141+
};
142+
143+
// Fire repository_dispatch event to trigger e2e test
144+
await github.repos.createDispatchEvent({
145+
owner: issue.owner,
146+
repo: issue.repo,
147+
event_type: "e2e-test",
148+
client_payload: testPayload,
149+
});
150+
151+
console.log(`Trigger E2E test for ${JSON.stringify(testPayload)}`);
152+
}
153+
} else if(commentBody.indexOf("/ping-author") == 0) {
154+
// Add new label
155+
await github.issues.addLabels({
156+
issue_number: issue.number,
157+
owner: issue.owner,
158+
repo: issue.repo,
159+
labels: ['needs-author-feedback']
160+
})
161+
return;
162+
}
163+
}

0 commit comments

Comments
 (0)