chore: Update issue template for creating themes

This commit is contained in:
Mauro Balades 2024-08-15 20:38:16 +02:00
parent 8cae01f735
commit 02469dc126
4 changed files with 159 additions and 2 deletions

View file

@ -44,4 +44,6 @@ body:
id: readme id: readme
attributes: attributes:
label: Readme label: Readme
description: The README file for the theme. description: The README file for the theme.
validations:
required: true

View file

@ -8,6 +8,13 @@ jobs:
name: Submit a theme name: Submit a theme
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Parse issue - name: Parse issue
id: parse id: parse
@ -22,10 +29,98 @@ jobs:
# them from being treated as special characters (e.g. $ or `) # them from being treated as special characters (e.g. $ or `)
echo '${{ steps.parse.outputs.payload }}' echo '${{ steps.parse.outputs.payload }}'
- if: startsWith(github.event.issue.title, '[create-theme]:') != 'true' - name: Export parsed payload into variables
id: export
run: |
export THEME_NAME='${{ fromJson(steps.parse.outputs.payload)["Name"] }}'
export THEME_DESCRIPTION='${{ fromJson(steps.parse.outputs.payload)["Description"] }}'
export THEME_HOMEPAGE='${{ fromJson(steps.parse.outputs.payload)["Homepage"] }}'
export THEME_STYLES='${{ fromJson(steps.parse.outputs.payload)["Theme Styles"] }}'
export THEME_README='${{ fromJson(steps.parse.outputs.payload)["Readme"] }}'
export THEME_AUTHOR='${{ github.actor }}'
- name: Setup Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create branch
run: |
git checkout -b create-theme-${{ github.event.issue.number }}
- name: Create theme content
run: |
export CREATION_OUTPUT=$(\
python3 scripts/create-theme.py \
--name "${THEME_NAME}" \
--description "${THEME_DESCRIPTION}" \
--homepage "${THEME_HOMEPAGE}" \
--styles "${THEME_STYLES}" \
--readme "${THEME_README}" \
--author "${THEME_AUTHOR}")
- name: Show error message
if: failure()
uses: peter-evans/close-issue@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
comment: |
# Error creating theme
Sorry about that! There was an error creating the theme. Please try again or contact the maintainers for help.
```
${{ steps.export.outputs.CREATION_OUTPUT }}
```
- if: success()
name: Commit changes
run: |
git add themes/
git commit -m "Add theme: $THEME_NAME"
git push origin create-theme-${{ github.event.issue.number }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Add theme: $THEME_NAME"
title: "Add theme: $THEME_NAME"
body: |
# Add theme: $THEME_NAME
This PR adds a new theme to the theme library.
## Theme Details
* **Name**: $THEME_NAME
* **Description**: $THEME_DESCRIPTION
* **Homepage**: $THEME_HOMEPAGE
* **Author**: @$THEME_AUTHOR
## Theme Styles
```css
$THEME_STYLES
```
## Theme README
```markdown
$THEME_README
```
branch: create-theme-${{ github.event.issue.number }}
base: main
- if: startsWith(github.event.issue.title, '[create-theme]:') != 'true' && success()
name: Close Issue name: Close Issue
uses: peter-evans/close-issue@v3 uses: peter-evans/close-issue@v3
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
comment: | comment: |
# Thank you for your contribution! # Thank you for your contribution!
Your theme has been successfully submitted. The maintainers will review it and get back to you soon.
Here are some details about your submission:
* Your theme has been requested into [this PR](${{ steps.createPR.outputs.pull-request-url }}).
* It has been created into the [create-theme-${{ github.event.issue.number }} branch](https://github.com/zen-browser/theme-store/tree/create-theme-${{ github.event.issue.number }}).
> If you have any questions or need help, feel free to ask in the comments below or in the PR.

60
scripts/submit-theme.py Normal file
View file

@ -0,0 +1,60 @@
import os
import argparse
import json
import uuid
STYLES_FILE = "chrome.css"
README_FILE = "readme.md"
def create_theme_id():
return str(uuid.uuid4())
def get_static_asset(theme_id, asset):
return f"https://raw.githubusercontent.com/zen-browser/theme-store/main/themes/{theme_id}/{asset}"
def main():
parser = argparse.ArgumentParser(description='Submit a theme to the theme repo.')
parser.add_argument('name', type=str, help='The theme to submit.')
parser.add_argument('description', type=str, help='The description of the theme.')
parser.add_argument('homepage', type=str, help='The homepage of the theme.')
parser.add_argument('style', type=str, help='The style of the theme.')
parser.add_argument('readme', type=str, help='The README of the theme.')
parser.add_argument('author', type=str, help='The author of the theme.')
args = parser.parse_args()
name = args.name
description = args.description
homepage = args.homepage
style = args.style
readme = args.readme
author = args.author
theme_id = create_theme_id()
theme = {
'id': theme_id,
'name': name,
'description': description,
'homepage': homepage,
'style': get_static_asset(theme_id, STYLES_FILE),
'readme': get_static_asset(theme_id, README_FILE),
'author': author
}
os.makedirs(f"themes/{theme_id}")
with open(f"themes/{theme_id}/theme.json", 'w') as f:
json.dump(theme, f)
with open(f"themes/{theme_id}/{STYLES_FILE}", 'w') as f:
f.write(style)
with open(f"themes/{theme_id}/{README_FILE}", 'w') as f:
f.write(readme)
print(f"Theme submitted with ID: {theme_id}")
for key, value in theme.items():
print(f"\t{key}: {value}")
if __name__ == '__main__':
main()

0
themes/.gitkeep Normal file
View file