|
| 1 | +name: Add User Group |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + add-user-group: |
| 9 | + if: | |
| 10 | + github.event.label.name == 'approved' && |
| 11 | + contains(github.event.issue.labels.*.name, 'user-group') |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Parse issue and create user group content file |
| 22 | + id: parse |
| 23 | + env: |
| 24 | + ISSUE_BODY: ${{ github.event.issue.body }} |
| 25 | + ISSUE_NUMBER: ${{ github.event.issue.number }} |
| 26 | + ISSUE_TITLE: ${{ github.event.issue.title }} |
| 27 | + run: | |
| 28 | + python3 - <<'PYEOF' |
| 29 | + import os, re, yaml |
| 30 | +
|
| 31 | + body = os.environ['ISSUE_BODY'] |
| 32 | +
|
| 33 | + def field(label): |
| 34 | + m = re.search(rf'### {re.escape(label)}\s+(.+?)(?=\n###|\Z)', body, re.DOTALL) |
| 35 | + if not m: |
| 36 | + return '' |
| 37 | + val = m.group(1).strip() |
| 38 | + return '' if val in ('_No response_', '') else val |
| 39 | +
|
| 40 | + name = field('Group Name') |
| 41 | + location = field('Location') |
| 42 | + fmt = field('Meeting Format') |
| 43 | + schedule = field('Meeting Schedule') |
| 44 | + website = field('Website') |
| 45 | + meetup_url = field('Meetup / Registration URL') |
| 46 | + organizers = field('Organizer(s)') |
| 47 | + logo_url = field('Logo URL') |
| 48 | + description = field('Short Description') |
| 49 | + about = field('About the Group') |
| 50 | +
|
| 51 | + def strip_html(s): |
| 52 | + # Strip raw HTML to prevent stored XSS via goldmark unsafe mode. |
| 53 | + return re.sub(r'<[^>]+>', '', s).strip() |
| 54 | +
|
| 55 | + # Organizers: split on commas / newlines into a clean list. |
| 56 | + org_list = [o.strip() for o in re.split(r'[,\n]+', organizers) if o.strip()] |
| 57 | +
|
| 58 | + # Links: only reference Font Awesome icons already in the committed subset |
| 59 | + # (fas fa-globe, fab fa-meetup). New icons would need `npm run build:icons`. |
| 60 | + links = [] |
| 61 | + if website: |
| 62 | + links.append({'name': 'Website', 'url': website, 'icon': 'fas fa-globe'}) |
| 63 | + if meetup_url: |
| 64 | + if 'meetup.com' in meetup_url.lower(): |
| 65 | + links.append({'name': 'Meetup', 'url': meetup_url, 'icon': 'fab fa-meetup'}) |
| 66 | + else: |
| 67 | + links.append({'name': 'Register', 'url': meetup_url, 'icon': 'fas fa-globe'}) |
| 68 | +
|
| 69 | + slug = re.sub(r'[^a-z0-9]+', '-', name.lower()).strip('-') |
| 70 | +
|
| 71 | + fm = { |
| 72 | + 'title': name, |
| 73 | + 'description': strip_html(description), |
| 74 | + 'location': location, |
| 75 | + 'format': fmt, |
| 76 | + 'meeting_schedule': schedule, |
| 77 | + } |
| 78 | + if org_list: |
| 79 | + fm['organizers'] = org_list |
| 80 | + if logo_url: |
| 81 | + fm['logo'] = logo_url |
| 82 | + if links: |
| 83 | + fm['links'] = links |
| 84 | +
|
| 85 | + content = '---\n' + yaml.safe_dump(fm, default_flow_style=False, allow_unicode=True, sort_keys=False) + '---\n' |
| 86 | + about = strip_html(about) |
| 87 | + if about: |
| 88 | + content += about + '\n' |
| 89 | +
|
| 90 | + filepath = f'content/user-groups/{slug}.md' |
| 91 | + os.makedirs('content/user-groups', exist_ok=True) |
| 92 | + with open(filepath, 'w') as f: |
| 93 | + f.write(content) |
| 94 | +
|
| 95 | + with open(os.environ['GITHUB_OUTPUT'], 'a') as out: |
| 96 | + out.write(f'slug={slug}\n') |
| 97 | + out.write(f'filepath={filepath}\n') |
| 98 | + out.write(f'group_name={name}\n') |
| 99 | +
|
| 100 | + print(f'Created {filepath}') |
| 101 | + PYEOF |
| 102 | +
|
| 103 | + - name: Open PR |
| 104 | + env: |
| 105 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + SLUG: ${{ steps.parse.outputs.slug }} |
| 107 | + FILEPATH: ${{ steps.parse.outputs.filepath }} |
| 108 | + GROUP_NAME: ${{ steps.parse.outputs.group_name }} |
| 109 | + ISSUE_NUMBER: ${{ github.event.issue.number }} |
| 110 | + run: | |
| 111 | + BRANCH="user-group/issue-${ISSUE_NUMBER}-${SLUG}" |
| 112 | + git config user.name "github-actions[bot]" |
| 113 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 114 | + git checkout -b "$BRANCH" |
| 115 | + git add "$FILEPATH" |
| 116 | + git commit -m "Add user group: ${GROUP_NAME} (closes #${ISSUE_NUMBER})" |
| 117 | + git push origin "$BRANCH" |
| 118 | + gh pr create \ |
| 119 | + --title "Add user group: ${GROUP_NAME}" \ |
| 120 | + --body "Closes #${ISSUE_NUMBER} |
| 121 | +
|
| 122 | + Auto-generated from user group submission." \ |
| 123 | + --base main \ |
| 124 | + --head "$BRANCH" |
0 commit comments