Skip to content

Commit c917646

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

File tree

4 files changed

+151
-135
lines changed

4 files changed

+151
-135
lines changed

.github/scripts/dapr_bot.js

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

.github/workflows/dapr-bot-schedule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
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.
4848
Thank you for your contributions!
4949
stale-issue-label: 'stale'
50-
exempt-issue-labels: 'pinned,good first issue,help wanted,triaged/resolved'
50+
exempt-issue-labels: 'pinned,good first issue,help wanted,triaged/resolved,triaged/unresolved'
5151
stale-pr-label: 'stale'
5252
exempt-pr-labels: 'pinned'
5353
operations-per-run: 500

.github/workflows/dapr-bot.yml

Lines changed: 2 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -27,137 +27,5 @@ jobs:
2727
with:
2828
github-token: ${{secrets.DAPR_BOT_TOKEN}}
2929
script: |
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,
82-
owner: issue.owner,
83-
repo: issue.repo,
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-
});
101-
}
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-
}
30+
const script = require('${process.env.GITHUB_WORKSPACE}/.github/scripts/dapr_bot.js')
31+
await script({github, context})

.github/workflows/test-e2e.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ on:
2424
branches:
2525
- master
2626
- release-*
27+
# Manual trigger
28+
workflow_dispatch:
29+
# Dispatch on external events
30+
repository_dispatch:
31+
types: [e2e-test]
2732

2833
jobs:
2934
test-e2e:

0 commit comments

Comments
 (0)