-
Notifications
You must be signed in to change notification settings - Fork 137
124 lines (102 loc) · 5.48 KB
/
Copy pathvote-monitor.yml
File metadata and controls
124 lines (102 loc) · 5.48 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
name: Vote Monitor and Onboarding Automation
on:
issues:
types: [labeled, unlabeled]
workflow_dispatch:
inputs:
process_existing:
description: 'Process existing issues with gitvote/passed label'
required: false
default: false
type: boolean
permissions:
issues: write
contents: read
# Prevent duplicate runs for the same issue to avoid race conditions
# that could create duplicate onboarding issues
concurrency:
group: vote-monitor-${{ github.event.issue.number || 'manual' }}
cancel-in-progress: false
jobs:
create-onboarding-issue:
runs-on: ubuntu-latest
if: |
(github.event_name == 'issues' && (github.event.action == 'labeled' || github.event.action == 'unlabeled')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.process_existing == 'true')
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Process application vote
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const { createOnboardingIssue, commentAndClose, ROLE_TYPES } = require('./.github/scripts/create-onboarding-issue.js');
// Helper function to detect application type from issue title
function detectApplicationType(title) {
const maintainerMatch = title.match(/^New Maintainer - (.+)$/);
if (maintainerMatch) {
return { roleType: ROLE_TYPES.MAINTAINER, applicantName: maintainerMatch[1].trim() };
}
const contributorMatch = title.match(/^New Contributor - (.+)$/);
if (contributorMatch) {
return { roleType: ROLE_TYPES.CONTRIBUTOR, applicantName: contributorMatch[1].trim() };
}
return null;
}
if (context.eventName === 'workflow_dispatch') {
// Manual trigger - process existing issues
console.log('🔍 Processing existing issues with gitvote/passed label...');
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'gitvote/passed'
});
console.log(`Found ${issues.data.length} issues with gitvote/passed label`);
for (const issue of issues.data) {
const appType = detectApplicationType(issue.title);
if (!appType) {
console.log(`⚠️ Skipping issue #${issue.number} - not a recognized application issue`);
continue;
}
const { roleType, applicantName } = appType;
console.log(`📝 Processing ${roleType} application issue #${issue.number}: "${applicantName}"`);
try {
const result = await createOnboardingIssue(github, context, applicantName, issue.number, roleType);
if (result.alreadyExists) {
console.log(`⏭️ Skipped creating onboarding issue for #${issue.number} - already exists: #${result.issueNumber} (${result.state})`);
continue;
}
await commentAndClose(github, context, issue.number, result.issueNumber, applicantName, roleType);
console.log(`✅ Processed issue #${issue.number} -> created ${roleType} onboarding issue #${result.issueNumber}`);
} catch (error) {
console.error(`❌ Error processing issue #${issue.number}:`, error.message);
}
}
} else {
// Label add/remove trigger - process single issue based on current labels
const issue = context.payload.issue;
// Ensure we only proceed for application issues with a passed vote
const labels = issue.labels || [];
const labelNames = labels.map(l => (typeof l === 'string' ? l : l.name));
const hasVotePassed = labelNames.includes('gitvote/passed');
if (!hasVotePassed) {
console.log('ℹ️ Skipping: issue does not have gitvote/passed label.');
return;
}
// Detect application type from issue title
const appType = detectApplicationType(issue.title);
if (!appType) {
console.log('ℹ️ Skipping: not a recognized application issue (maintainer or contributor).');
return;
}
const { roleType, applicantName } = appType;
console.log(`🎉 Vote passed for ${roleType} application. Creating onboarding issue...`);
const result = await createOnboardingIssue(github, context, applicantName, issue.number, roleType);
if (result.alreadyExists) {
console.log(`⏭️ Onboarding issue already exists for "${applicantName}": #${result.issueNumber} (${result.state})`);
return;
}
await commentAndClose(github, context, issue.number, result.issueNumber, applicantName, roleType);
console.log(`✅ Successfully created ${roleType} onboarding issue #${result.issueNumber} and closed issue #${issue.number}`);
}