Skip to content

Commit

Permalink
feat: Accept submissions via GitHub Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Oct 24, 2024
1 parent da53fe9 commit 7cbf88e
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 1 deletion.
54 changes: 54 additions & 0 deletions .github/ISSUE_TEMPLATE/new_submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Submission Form
description: Submit a new Frappe App or Resource to the Awesome Frappe list
title: "[Submission] - "
labels: ["new-submission"]
body:
- type: dropdown
id: category
attributes:
label: Category
multiple: false
options:
- Apps
- Developer Tooling
- Other Tooling
- Deployment Tools
- Resources
- Hosting
validations:
required: true
- type: dropdown
id: sub_category
attributes:
label: Sub Category
options:
# Apps
- Business Apps
- Utility Apps
- Plugins
- Integrations
- Themes
- Regional Apps
- Other Apps
# Developer Tooling
- SDKs & Libraries
- Templates
- type: input
id: app_link
attributes:
label: App or Resource URL
validations:
required: true
- type: input
id: app_label
attributes:
label: App or Resource Name
validations:
required: true
- type: textarea
id: app_description
attributes:
label: App or Resource Description
placeholder: A short description of the app or resource
validations:
required: true
29 changes: 29 additions & 0 deletions .github/helper/approval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
import os
import requests

ISSUE_NUMBER = os.environ.get("ISSUE_NUMBER") # "1200"
GITHUB_REPOSITORY = os.environ.get("GITHUB_REPOSITORY") # "octocat/Hello-World"
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") # "1234567890"

if __name__ == "__main__":
ENDPOINT_URL = f"https://api.github.com/repos/{GITHUB_REPOSITORY}/issues/{ISSUE_NUMBER}/comments"
COLLABORATOR_URL = f"https://api.github.com/repos/{GITHUB_REPOSITORY}/collaborators/{{username}}"
ISSUE_COMMENTS = requests.get(ENDPOINT_URL).json()

for comment in ISSUE_COMMENTS:
username = comment["user"]["login"]
comment_body = comment["body"]

if "LGTM" not in comment_body:
continue
print(f"LGTM found by {username}")

is_collaborator = requests.get(COLLABORATOR_URL.format(username=username), headers={"Authorization": f"token {GITHUB_TOKEN}"}).ok

if is_collaborator:
print(f"{username} is a collaborator and issue is approved")
sys.exit(0) # exit with success code if a collaborator has dropped a LGTM comment

print("No one has dropped a LGTM comment")
sys.exit(1) # exit with error code if no collaborator has approved the affirmation
File renamed without changes.
26 changes: 26 additions & 0 deletions .github/helper/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import json


if __name__ == "__main__":
WORKSPACE = os.environ.get("GITHUB_WORKSPACE")
AWESOME_FILE = f"{WORKSPACE}/README.md"

FILE_ENTRIES_BY_LINE = open(AWESOME_FILE).readlines()
USER_SUBMISSION: dict = json.loads(os.environ.get("submission_entry") or"{}")

# add user submission to affirmations file
category_index = FILE_ENTRIES_BY_LINE.index(f"### {USER_SUBMISSION['category']}\n")
insert_at_index = category_index + 1

if sub_category := USER_SUBMISSION['sub_category']:
sub_category_index = FILE_ENTRIES_BY_LINE.index(f"#### {USER_SUBMISSION['sub_category']}\n", category_index)
insert_at_index = sub_category_index + 1

FILE_ENTRIES_BY_LINE.insert(insert_at_index, f"- [{USER_SUBMISSION['app_name']}]({USER_SUBMISSION['app_label']}) - {USER_SUBMISSION['app_description']}\n")

# update affirmations file
with open(AWESOME_FILE, "w") as f:
f.write(FILE_ENTRIES_BY_LINE)

print(f"Updated {AWESOME_FILE} with {USER_SUBMISSION}")
64 changes: 64 additions & 0 deletions .github/workflows/contribute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Submissions via Issues
on:
issue_comment:
types: [created, edited]

jobs:
approval:
# this job only runs for issue comments
name: Check if submission is approved
runs-on: ubuntu-latest
if: ${{ github.event.issue.number }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Check if authorized member has approved submission
run: |
pip install requests
python ${GITHUB_WORKSPACE}/.github/helper/approval.py
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

contribution:
name: Extract, Commit & Push submission to default branch
runs-on: ubuntu-latest
needs: approval
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'

- uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: ${GITHUB_WORKSPACE}/.github/ISSUE_TEMPLATE/new_submission.yml

- name: Update submissions file
run: python ${GITHUB_WORKSPACE}/.github/helper/update.py
env:
submission_entry: ${{ steps.issue-parser.outputs.jsonString }}

- name: Record Sorter
run: python ${GITHUB_WORKSPACE}/.github/helper/record_sorter.py

- name: Commit + Push changes
uses: EndBug/add-and-commit@v9
with:
message: 'docs: New Submission via Issue'

cleanup:
name: Close Issue thread after successful contribution
runs-on: ubuntu-latest
needs: contribution
steps:
- name: Close Issue
uses: peter-evans/close-issue@v3
with:
issue-number: ${{ github.event.issue.number }}
comment: Auto-closing issue since commit has been pushed to main branch
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ repos:
hooks:
- id: records-sorter
name: Sort README
entry: python .github/record_sorter.py
entry: python .github/helper/record_sorter.py
language: system
types: [markdown]

0 comments on commit 7cbf88e

Please sign in to comment.