-
Notifications
You must be signed in to change notification settings - Fork 134
261 lines (221 loc) · 11.8 KB
/
process-submission.yml
File metadata and controls
261 lines (221 loc) · 11.8 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
name: Process Submission
on:
issues:
types: [opened]
jobs:
process:
if: |
startsWith(github.event.issue.title, '[Plugin]') ||
startsWith(github.event.issue.title, '[App]') ||
startsWith(github.event.issue.title, '[Library]') ||
startsWith(github.event.issue.title, '[Collection]')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: cd generator && npm ci
- name: Parse issue and create entry
id: parse
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const body = issue.body;
const title = issue.title;
// Determine type from title prefix
const isPlugin = title.startsWith('[Plugin]');
const isApp = title.startsWith('[App]');
const isLibrary = title.startsWith('[Library]');
const isCollection = title.startsWith('[Collection]');
// Parse form fields from issue body
const parseField = (fieldName) => {
const regex = new RegExp(`### ${fieldName}\\s*\\n\\s*([^\\n#]+)`, 'i');
const match = body.match(regex);
return match ? match[1].trim() : '';
};
const parseMultiSelect = (fieldName) => {
const regex = new RegExp(`### ${fieldName}\\s*\\n\\s*([^#]+?)(?=###|$)`, 'i');
const match = body.match(regex);
if (!match) return [];
return match[1].split(',').map(s => s.trim()).filter(s => s && s !== '_No response_');
};
let entry = {};
let targetFile = '';
let entryType = '';
if (isPlugin) {
entryType = 'plugin';
targetFile = 'data/plugins.json';
entry = {
name: parseField('Plugin Name'),
url: parseField('Plugin URL'),
description: parseField('Description'),
type: parseField('Plugin Type'),
frameworks: parseMultiSelect('Frameworks')
};
} else if (isApp) {
entryType = 'app';
targetFile = 'data/apps.json';
const repoType = parseField('Repository Type');
const repoUser = parseField('Repository User/Workspace');
const repoName = parseField('Repository Name');
let repository = {};
if (repoType === 'GitHub' || repoType === 'GitLab' || repoType === 'Codeberg' || repoType === 'SourceHut') {
repository = { type: repoType, user: repoUser, repo: repoName };
} else if (repoType === 'Bitbucket') {
repository = { type: repoType, workspace: repoUser, repo: repoName };
} else if (repoType === 'SourceForge') {
repository = { type: repoType, project: repoName };
} else if (repoType === 'Assembla') {
repository = { type: repoType, space: repoName };
}
entry = {
name: parseField('App Name'),
description: parseField('Description'),
repository: repository
};
const url = parseField('App URL \\(optional\\)');
if (url && url !== '_No response_') {
entry.url = url;
}
} else if (isLibrary) {
entryType = 'library';
targetFile = 'data/libraries.json';
const repoType = parseField('Repository Type');
const repoUser = parseField('Repository User/Workspace');
const repoName = parseField('Repository Name');
let repository = {};
if (repoType === 'GitHub' || repoType === 'GitLab' || repoType === 'Codeberg' || repoType === 'SourceHut') {
repository = { type: repoType, user: repoUser, repo: repoName };
} else if (repoType === 'Bitbucket') {
repository = { type: repoType, workspace: repoUser, repo: repoName };
} else if (repoType === 'SourceForge') {
repository = { type: repoType, project: repoName };
} else if (repoType === 'Assembla') {
repository = { type: repoType, space: repoName };
}
entry = {
name: parseField('Library Name'),
description: parseField('Description'),
repository: repository
};
const url = parseField('Library URL \\(optional\\)');
if (url && url !== '_No response_') {
entry.url = url;
}
} else if (isCollection) {
const collectionType = parseField('Type');
entryType = 'collection';
if (collectionType.toLowerCase().includes('resource')) {
targetFile = 'data/resources.json';
} else if (collectionType.toLowerCase().includes('sample')) {
targetFile = 'data/samples.json';
} else {
targetFile = 'data/collections.json';
}
entry = {
name: parseField('Name'),
url: parseField('URL'),
description: parseField('Description')
};
}
core.setOutput('entry', JSON.stringify(entry));
core.setOutput('targetFile', targetFile);
core.setOutput('entryType', entryType);
core.setOutput('entryName', entry.name);
- name: Insert entry into JSON file
run: |
node << 'EOF'
const fs = require('fs');
const path = require('path');
const entry = JSON.parse(process.env.ENTRY);
const targetFile = process.env.TARGET_FILE;
// Read existing data
const filePath = path.join(process.cwd(), targetFile);
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
// Find insertion index (alphabetical by name, case-insensitive)
const insertIndex = data.findIndex(item =>
item.name.toLowerCase() > entry.name.toLowerCase()
);
// Insert at correct position
if (insertIndex === -1) {
data.push(entry);
} else {
data.splice(insertIndex, 0, entry);
}
// Write back with consistent formatting
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n');
console.log(`Inserted "${entry.name}" into ${targetFile}`);
EOF
env:
ENTRY: ${{ steps.parse.outputs.entry }}
TARGET_FILE: ${{ steps.parse.outputs.targetFile }}
- name: Run validation tests
id: validate
run: |
cd generator
npm test -- --run 2>&1 | tee test-output.txt
echo "test_passed=$?" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Create Pull Request
if: steps.validate.outcome == 'success'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Add ${{ steps.parse.outputs.entryType }}: ${{ steps.parse.outputs.entryName }}"
branch: submission/${{ steps.parse.outputs.entryType }}/${{ github.event.issue.number }}
title: "Add ${{ steps.parse.outputs.entryType }}: ${{ steps.parse.outputs.entryName }}"
body: |
## Automated Submission
This PR was automatically generated from issue #${{ github.event.issue.number }}.
**Type:** ${{ steps.parse.outputs.entryType }}
**Name:** ${{ steps.parse.outputs.entryName }}
### Entry Details
```json
${{ steps.parse.outputs.entry }}
```
---
✅ Validation tests passed
Please review this submission before merging.
Closes #${{ github.event.issue.number }}
labels: |
submission
needs-review
- name: Comment on issue (success)
if: steps.validate.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `✅ Your submission has been processed successfully!\n\nA pull request has been created for review. Once approved by a maintainer, your entry will be added to the list.\n\nThank you for contributing!`
});
- name: Comment on issue (failure)
if: steps.validate.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const testOutput = fs.readFileSync('generator/test-output.txt', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `❌ Your submission could not be validated. Please check the details below and update your submission.\n\n<details>\n<summary>Validation Output</summary>\n\n\`\`\`\n${testOutput}\n\`\`\`\n</details>\n\nCommon issues:\n- Missing required fields\n- Invalid URL format\n- Invalid repository information`
});
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['validation-failed']
});