Skip to content

Commit a879073

Browse files
author
asyncapi-bot
committed
ci: update of files from global .github repo
1 parent 83239d6 commit a879073

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# This workflow is centrally managed at https://github.com/asyncapi/.github/
2+
# Don't make changes to this file in this repository, as they will be overwritten with
3+
# changes made to the same file in the abovementioned repository.
4+
5+
# The purpose of this workflow is to allow Microgrant Team members
6+
# (https://github.com/orgs/asyncapi/teams/microgrant_team) to issue commands to the
7+
# organization's global AsyncAPI bot related to the Microgrant Program, while at the
8+
# same time preventing unauthorized users from misusing them.
9+
10+
name: Microgrant Program commands
11+
12+
on:
13+
issue_comment:
14+
types:
15+
- created
16+
17+
env:
18+
MICROGRANT_PROGRAM_LABELS_JSON: |
19+
[
20+
{"name": "microgrant", "color": "708090", "description": "Participation in the Microgrant Program"}
21+
]
22+
23+
permissions: {}
24+
25+
jobs:
26+
guard-against-unauthorized-use:
27+
name: Guard against unauthorized use
28+
permissions:
29+
issues: write # required to post a comment on the issue/PR
30+
pull-requests: write # required to post a comment on the issue/PR if it's a PR
31+
if: >
32+
!contains(fromJSON('["aeworxet","thulieblack"]'), github.actor) &&
33+
github.event.comment &&
34+
(
35+
github.event.comment.body == '/microgrant' || github.event.comment.body == '/unmicrogrant'
36+
)
37+
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: ❌ @${{github.actor}} made an unauthorized attempt to use a Microgrant Program's command
42+
uses: actions/github-script@v7
43+
env:
44+
ACTOR: ${{ github.actor }}
45+
with:
46+
github-token: ${{ github.token }}
47+
script: |
48+
const commentText = `❌ @${process.env.ACTOR} is not authorized to use the Microgrant Program's commands.
49+
These commands can only be used by members of the [Microgrant Team](https://github.com/orgs/asyncapi/teams/microgrant_team).`;
50+
51+
console.log(`❌ @${process.env.ACTOR} made an unauthorized attempt to use a Microgrant Program's command.`);
52+
github.rest.issues.createComment({
53+
issue_number: context.issue.number,
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
body: commentText
57+
})
58+
59+
add-label-microgrant:
60+
name: Add microgrant label
61+
permissions:
62+
issues: write # required to read/create labels and add labels on the issue/PR
63+
pull-requests: write # required to read/create labels and add labels on the issue/PR
64+
if: >
65+
contains(fromJSON('["aeworxet","thulieblack"]'), github.actor) &&
66+
(
67+
github.event.comment.body == '/microgrant'
68+
)
69+
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Add label `microgrant`
73+
uses: actions/github-script@v7
74+
with:
75+
github-token: ${{ github.token }}
76+
script: |
77+
const MICROGRANT_PROGRAM_LABELS = JSON.parse(process.env.MICROGRANT_PROGRAM_LABELS_JSON);
78+
let LIST_OF_LABELS_FOR_REPO = await github.rest.issues.listLabelsForRepo({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
});
82+
83+
LIST_OF_LABELS_FOR_REPO = LIST_OF_LABELS_FOR_REPO.data.map(key => key.name);
84+
85+
if (!LIST_OF_LABELS_FOR_REPO.includes(MICROGRANT_PROGRAM_LABELS[0].name)) {
86+
await github.rest.issues.createLabel({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
name: MICROGRANT_PROGRAM_LABELS[0].name,
90+
color: MICROGRANT_PROGRAM_LABELS[0].color,
91+
description: MICROGRANT_PROGRAM_LABELS[0].description
92+
});
93+
}
94+
95+
console.log('Adding label `microgrant`...');
96+
github.rest.issues.addLabels({
97+
issue_number: context.issue.number,
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
labels: [MICROGRANT_PROGRAM_LABELS[0].name]
101+
})
102+
103+
remove-label-microgrant:
104+
name: Remove microgrant label
105+
permissions:
106+
issues: write # required to read/remove labels on the issue/PR
107+
pull-requests: write # required to read/remove labels on the issue/PR if it's a PR
108+
if: >
109+
contains(fromJSON('["aeworxet","thulieblack"]'), github.actor) &&
110+
(
111+
github.event.comment.body == '/unmicrogrant'
112+
)
113+
runs-on: ubuntu-latest
114+
steps:
115+
- name: Remove label `microgrant`
116+
uses: actions/github-script@v7
117+
with:
118+
github-token: ${{ github.token }}
119+
script: |
120+
const MICROGRANT_PROGRAM_LABELS = JSON.parse(process.env.MICROGRANT_PROGRAM_LABELS_JSON);
121+
let LIST_OF_LABELS_FOR_ISSUE = await github.rest.issues.listLabelsOnIssue({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
issue_number: context.issue.number,
125+
});
126+
127+
LIST_OF_LABELS_FOR_ISSUE = LIST_OF_LABELS_FOR_ISSUE.data.map(key => key.name);
128+
129+
if (LIST_OF_LABELS_FOR_ISSUE.includes(MICROGRANT_PROGRAM_LABELS[0].name)) {
130+
console.log('Removing label `microgrant`...');
131+
github.rest.issues.removeLabel({
132+
issue_number: context.issue.number,
133+
owner: context.repo.owner,
134+
repo: context.repo.repo,
135+
name: [MICROGRANT_PROGRAM_LABELS[0].name]
136+
})
137+
}

0 commit comments

Comments
 (0)