|
| 1 | +name: Add Community Event |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + add-event: |
| 9 | + if: | |
| 10 | + github.event.label.name == 'approved' && |
| 11 | + contains(github.event.issue.labels.*.name, 'community-event') |
| 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 event 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 |
| 30 | +
|
| 31 | + body = os.environ['ISSUE_BODY'] |
| 32 | + issue_num = os.environ['ISSUE_NUMBER'] |
| 33 | +
|
| 34 | + def field(label): |
| 35 | + m = re.search(rf'### {re.escape(label)}\s+(.+?)(?=\n###|\Z)', body, re.DOTALL) |
| 36 | + if not m: |
| 37 | + return '' |
| 38 | + val = m.group(1).strip() |
| 39 | + return '' if val in ('_No response_', '') else val |
| 40 | +
|
| 41 | + name = field('Event Name') |
| 42 | + url = field('Event Website') |
| 43 | + start_date = field('Start Date') |
| 44 | + end_date = field('End Date') |
| 45 | + location = field('Location') |
| 46 | + virtual_s = field('Is this a virtual event?') |
| 47 | + description = field('Event Description') |
| 48 | +
|
| 49 | + virtual = 'true' if virtual_s.startswith(('Yes', 'Hybrid')) else 'false' |
| 50 | +
|
| 51 | + # Generate a URL-safe slug: name + year |
| 52 | + slug = re.sub(r'[^a-z0-9]+', '-', name.lower()).strip('-') |
| 53 | + slug = f"{slug}-{start_date[:4]}" |
| 54 | +
|
| 55 | + end_line = f'\nendDate: "{end_date}"' if end_date else '' |
| 56 | + content = f"""--- |
| 57 | + title: "{name}" |
| 58 | + startDate: "{start_date}"{end_line} |
| 59 | + where: "{location}" |
| 60 | + externalUrl: "{url}" |
| 61 | + virtual: {virtual} |
| 62 | + --- |
| 63 | + {description} |
| 64 | + """ |
| 65 | + # Dedent (the heredoc indents every line) |
| 66 | + import textwrap |
| 67 | + content = textwrap.dedent(content) |
| 68 | +
|
| 69 | + filepath = f'content/calendar/{slug}.md' |
| 70 | + os.makedirs('content/calendar', exist_ok=True) |
| 71 | + with open(filepath, 'w') as f: |
| 72 | + f.write(content) |
| 73 | +
|
| 74 | + with open(os.environ['GITHUB_OUTPUT'], 'a') as out: |
| 75 | + out.write(f'slug={slug}\n') |
| 76 | + out.write(f'filepath={filepath}\n') |
| 77 | + out.write(f'event_name={name}\n') |
| 78 | +
|
| 79 | + print(f'Created {filepath}') |
| 80 | + PYEOF |
| 81 | +
|
| 82 | + - name: Open PR |
| 83 | + env: |
| 84 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + SLUG: ${{ steps.parse.outputs.slug }} |
| 86 | + FILEPATH: ${{ steps.parse.outputs.filepath }} |
| 87 | + EVENT_NAME: ${{ steps.parse.outputs.event_name }} |
| 88 | + ISSUE_NUMBER: ${{ github.event.issue.number }} |
| 89 | + run: | |
| 90 | + BRANCH="event/issue-${ISSUE_NUMBER}-${SLUG}" |
| 91 | + git config user.name "github-actions[bot]" |
| 92 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 93 | + git checkout -b "$BRANCH" |
| 94 | + git add "$FILEPATH" |
| 95 | + git commit -m "Add event: ${EVENT_NAME} (closes #${ISSUE_NUMBER})" |
| 96 | + git push origin "$BRANCH" |
| 97 | + gh pr create \ |
| 98 | + --title "Add event: ${EVENT_NAME}" \ |
| 99 | + --body "Closes #${ISSUE_NUMBER} |
| 100 | +
|
| 101 | + Auto-generated from community event submission." \ |
| 102 | + --base main \ |
| 103 | + --head "$BRANCH" |
0 commit comments