forked from community/community
-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (56 loc) · 2.12 KB
/
label-feedback-dispatch.yml
File metadata and controls
64 lines (56 loc) · 2.12 KB
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
name: Dispatch Staff Label Feedback
on:
discussion:
types:
- labeled
- unlabeled
permissions:
contents: read
jobs:
dispatch-feedback-event:
runs-on: ubuntu-latest
env:
COMMUNITY_OPS_REPOSITORY: community/community-ops
steps:
- name: Forward discussion label events
uses: actions/github-script@v8
with:
github-token: ${{ secrets.WRITE_TO_COMM_OPS_TOKEN }}
script: |
const actor = context.actor;
const action = context.payload.action;
const discussion = context.payload.discussion;
const label = context.payload.label;
if (!label?.name) {
core.info("Skipping event with missing label");
return;
}
if (!discussion?.number) {
throw new Error("Missing discussion number in discussion event payload");
}
if ((actor || "").endsWith("[bot]")) {
core.info(`Skipping bot-generated event: ${actor}`);
return;
}
const [owner, repo] = process.env.COMMUNITY_OPS_REPOSITORY.split("/");
await github.rest.repos.createDispatchEvent({
owner,
repo,
event_type: "staff-label-correction",
client_payload: {
data: {
source_repository: `${context.repo.owner}/${context.repo.repo}`,
target_repository: `${process.env.COMMUNITY_OPS_REPOSITORY}`,
discussion_number: discussion.number,
discussion_title: discussion.title || "unknown",
discussion_url: discussion.html_url || discussion.url || "",
category: discussion.category?.name || "unknown",
category_slug: discussion.category?.slug || "unknown",
event_type: action,
label: label.name,
actor,
createdAt: new Date().toISOString(),
},
},
});
core.info(`Forwarded ${action} event for discussion #${discussion.number}`);