-
Notifications
You must be signed in to change notification settings - Fork 466
273 lines (241 loc) · 11.1 KB
/
protocol-call-workflow.yml
File metadata and controls
273 lines (241 loc) · 11.1 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: Protocol Call Handler
on:
issues:
types: [opened, edited]
jobs:
check_label:
runs-on: ubuntu-latest
outputs:
has_protocol_label: ${{ steps.check_label.outputs.has_protocol_label }}
steps:
- name: Check for protocol-call label
id: check_label
env:
HAS_LABEL: ${{ contains(github.event.issue.labels.*.name, 'protocol-call') }}
run: |
if [[ "$HAS_LABEL" == "true" ]]; then
echo "has_protocol_label=true" >> $GITHUB_OUTPUT
echo "✅ Issue has protocol-call label"
else
echo "has_protocol_label=false" >> $GITHUB_OUTPUT
echo "❌ Issue does not have protocol-call label"
fi
check_membership:
needs: check_label
runs-on: ubuntu-latest
if: needs.check_label.outputs.has_protocol_label == 'true'
outputs:
is_member: ${{ steps.set_output.outputs.is_member }}
steps:
- name: Check Organization Membership
id: check_org_membership
uses: actions/github-script@v6
with:
github-token: ${{ secrets.ORG_READ_TOKEN }}
script: |
// Check if the user is a member of ethereum or ethcatherders orgs
let is_member = false;
const username = context.actor;
// Define trusted contributors list once at the beginning
const trustedContributors = [
"poojaranjan", "adietrichs", "carlbeek", "timbeiko", "nconsigny",
"justindrake", "vbuterin", "hwwhww", "mathhhewkeil", "jrudolf",
"soispoke", "pipermerriam", "potuz", "will-corcoran", "ralexstokes",
"samwilsn", "shemnon", "nixorokish", "dcrapis", "gabrocheleau",
"joshdavislight", "nerolation", "jihoonsong", "bomanaps", "misilva73",
"zsfelfoldi", "kevaundray", "jflo", "gcolvin", "asanso"
];
console.log(`Checking membership for user: ${username}`);
try {
// Try multiple methods to check membership to be thorough
// First, try direct membership check - this only works for public members or if token has sufficient permissions
async function checkDirectMembership(org, user) {
try {
await github.rest.orgs.checkMembershipForUser({
org: org,
username: user
});
return true;
} catch (error) {
console.log(`Direct membership check for ${user} in ${org} failed: ${error.message}`);
return false;
}
}
// Next, try to get both public and private members
async function getAllOrgMembers(org) {
const members = new Set();
const perPage = 100; // Maximum allowed
// Get public members
try {
console.log(`Fetching public members for ${org}...`);
for await (const response of github.paginate.iterator(
github.rest.orgs.listPublicMembers,
{ org, per_page: perPage }
)) {
for (const member of response.data) {
members.add(member.login.toLowerCase());
}
}
console.log(`Found ${members.size} public members in ${org}`);
} catch (error) {
console.log(`Error fetching public members for ${org}: ${error.message}`);
}
// Get all members (includes private, if token has permissions)
try {
console.log(`Fetching all members for ${org}...`);
for await (const response of github.paginate.iterator(
github.rest.orgs.listMembers,
{ org, per_page: perPage }
)) {
for (const member of response.data) {
members.add(member.login.toLowerCase());
}
}
console.log(`Found total of ${members.size} members in ${org} (public + private that token can see)`);
} catch (error) {
console.log(`Error fetching all members for ${org}: ${error.message}`);
}
return Array.from(members);
}
// Check Ethereum org
console.log('Checking ethereum organization membership...');
if (await checkDirectMembership('ethereum', username)) {
console.log(`✅ ${username} is confirmed as a member of ethereum org via direct API check`);
is_member = true;
} else {
const ethereumMembers = await getAllOrgMembers('ethereum');
console.log(`Collected ${ethereumMembers.length} ethereum members to check against`);
if (ethereumMembers.includes(username.toLowerCase())) {
console.log(`✅ ${username} is a member of ethereum org`);
is_member = true;
} else {
console.log(`❌ ${username} is not found in ethereum org member list`);
}
}
// If not in ethereum, check ethcatherders org
if (!is_member) {
console.log('Checking ethcatherders organization membership...');
if (await checkDirectMembership('ethcatherders', username)) {
console.log(`✅ ${username} is confirmed as a member of ethcatherders org via direct API check`);
is_member = true;
} else {
const catMembers = await getAllOrgMembers('ethcatherders');
console.log(`Collected ${catMembers.length} ethcatherders members to check against`);
if (catMembers.includes(username.toLowerCase())) {
console.log(`✅ ${username} is a member of ethcatherders org`);
is_member = true;
} else {
console.log(`❌ ${username} is not found in ethcatherders org member list`);
}
}
}
// Fallback to a list of trusted contributors if not in either org
if (!is_member) {
if (trustedContributors.includes(username.toLowerCase())) {
console.log(`✅ ${username} is in the trusted contributors list`);
is_member = true;
} else {
console.log(`❌ ${username} is not in the trusted contributors list`);
}
}
console.log(`Final membership determination for ${username}: ${is_member ? 'Approved ✅' : 'Not approved ❌'}`);
} catch (error) {
console.log(`Error in membership check: ${error.message}`);
console.log(`Stack trace: ${error.stack}`);
// If we're here, something went wrong with the API checks
// Check if user is in trusted list as a fallback
if (trustedContributors.includes(username.toLowerCase())) {
console.log(`✅ FALLBACK: ${username} is in the trusted contributors list`);
is_member = true;
}
}
return is_member;
- name: Set output
id: set_output
run: echo "is_member=${{ steps.check_org_membership.outputs.result }}" >> $GITHUB_OUTPUT
handle_protocol_call:
needs: check_membership
runs-on: ubuntu-latest
if: needs.check_membership.outputs.is_member == 'true'
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Upgrade pip, setuptools, and wheel
run: |
pip install --upgrade pip setuptools wheel
- name: Install PyGithub Explicitly
run: |
pip install PyGithub>=1.55.1
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -e .github/ACDbot/
pip install pytz google-api-python-client
pip install -r .github/ACDbot/requirements.txt
- name: Verify Installed Packages
run: |
pip list
- name: Log protocol call processing
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_LABELS: ${{ join(github.event.issue.labels.*.name, ', ') }}
run: |
echo "Processing protocol call issue #$ISSUE_NUMBER"
echo "Issue title: $ISSUE_TITLE"
echo "Issue labels: $ISSUE_LABELS"
- name: Handle protocol call
run: |
python .github/ACDbot/scripts/handle_protocol_call.py \
--issue_number "${{ github.event.issue.number }}" \
--repo "${{ github.repository }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ZOOM_CLIENT_ID: ${{ secrets.ZOOM_CLIENT_ID }}
ZOOM_CLIENT_SECRET: ${{ secrets.ZOOM_CLIENT_SECRET }}
ZOOM_ACCOUNT_ID: ${{ secrets.ZOOM_ACCOUNT_ID }}
ZOOM_ALTERNATIVE_HOSTS: ${{ secrets.ZOOM_ALTERNATIVE_HOSTS }}
ZOOM_REFRESH_TOKEN: ${{ secrets.ZOOM_REFRESH_TOKEN }}
DISCOURSE_API_KEY: ${{ secrets.DISCOURSE_API_KEY }}
DISCOURSE_API_USERNAME: ${{ secrets.DISCOURSE_API_USERNAME }}
DISCOURSE_BASE_URL: ${{ vars.DISCOURSE_BASE_URL }}
GCAL_ID: ${{ vars.GCAL_ID }}
GCAL_SERVICE_ACCOUNT_KEY: ${{ secrets.GCAL_SERVICE_ACCOUNT_KEY }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
YOUTUBE_REFRESH_TOKEN: ${{ secrets.YOUTUBE_REFRESH_TOKEN }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ vars.TELEGRAM_CHAT_ID }}
MATTERMOST_BOT_WEBHOOK_URL: ${{ secrets.MATTERMOST_BOT_WEBHOOK_URL }}
SENDER_EMAIL: ${{ secrets.SENDER_EMAIL }}
SENDER_EMAIL_PASSWORD: ${{ secrets.SENDER_EMAIL_PASSWORD }}
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
- name: Commit mapping file
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if git diff --quiet .github/ACDbot/meeting_topic_mapping.json; then
echo "No changes to mapping file"
else
git add .github/ACDbot/meeting_topic_mapping.json
git commit -m "Update mapping for issue $ISSUE_NUMBER"
git push
echo "Committed mapping file changes"
fi
permissions:
contents: write
issues: write
# Prevent concurrent runs of the same issue
concurrency:
group: issue-${{ github.event.issue.number }}
cancel-in-progress: true