-
Notifications
You must be signed in to change notification settings - Fork 4
88 lines (76 loc) · 3.3 KB
/
member-verification.yml
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
name: Member Verification Check
on:
pull_request:
types: [opened]
jobs:
verify-new-member:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check PR title format
id: check-title
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title;
if (!title.startsWith('[MEMBER]')) {
console.log('PR title does not start with [MEMBER], skipping verification check');
return 'skip';
}
return 'continue';
- name: Check user account age
if: steps.check-title.outputs.result == 'continue'
id: check-user
uses: actions/github-script@v7
env:
MIN_ACCOUNT_AGE_MONTHS: ${{ vars.MIN_ACCOUNT_AGE_MONTHS || '3' }} # Default to 3 months if not set
with:
script: |
const creator = context.payload.pull_request.user.login;
const response = await github.rest.users.getByUsername({
username: creator
});
const createdAt = new Date(response.data.created_at);
const now = new Date();
const accountAgeInMonths = (now - createdAt) / (1000 * 60 * 60 * 24 * 30);
const minAgeMonths = parseInt(process.env.MIN_ACCOUNT_AGE_MONTHS);
console.log(`Account age in months: ${accountAgeInMonths}`);
console.log(`Required minimum age in months: ${minAgeMonths}`);
if (accountAgeInMonths < minAgeMonths) {
const message = [
`👋 Hello @${creator}!`,
'',
`Thank you for your interest in joining our organization. We noticed that your GitHub account is less than ${minAgeMonths} months old.`,
'',
'To help us verify that you\'re a real person and maintain the security of our organization, please provide one of the following:',
'- A link to your LinkedIn profile',
'- Links to your other social media presence',
'- Any other form of verification that shows you\'re a real person',
'',
'Please provide this information in a comment on this PR.',
'',
'Note: This is an automated message to help prevent bot accounts from joining our organization.'
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
});
return 'new-account';
}
return 'existing-account';
- name: Add label if new account
if: steps.check-user.outputs.result == 'new-account' && steps.check-title.outputs.result == 'continue'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['verification-needed']
});