From 007f04f9e9921b71ef230e083d5f0fd587ceba79 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 29 Jan 2023 20:44:57 +0100 Subject: [PATCH] Add plugin workflow (#114) * Add cups plugin * Add workflow to add plugins --- .github/collect_plugin.py | 67 ++++++++++++++++++++++++++++ .github/workflows/collect_plugin.yml | 41 +++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/collect_plugin.py create mode 100644 .github/workflows/collect_plugin.yml diff --git a/.github/collect_plugin.py b/.github/collect_plugin.py new file mode 100644 index 00000000..33103b79 --- /dev/null +++ b/.github/collect_plugin.py @@ -0,0 +1,67 @@ +import json +import os +from pathlib import Path +from urllib.request import urlopen, Request + +inp_project = os.environ.get('PROJECT') +inp_author = os.environ.get('AUTHOR') +file_name = Path(f'_repo/{inp_project}.md') +crowdin_projet_id = 452300 + + +def get_data(url, key=None, default=0, auth=None): + """Fetches data from remote endpoint""" + httprequest = Request(url, headers={"Accept": "application/json"}) + + if auth: + httprequest.add_header("Authorization", f"Bearer {auth}") + + with urlopen(httprequest) as response: + data = response.read().decode() + data = json.loads(data) + + if key: + data = data.get(key, default) + + return data + +pypi_data = get_data(f'https://pypi.org/pypi/{inp_project}/json') + +name = pypi_data['info']['name'] +tagline = pypi_data['info']['summary'] +author = inp_author or pypi_data['info']['author_email'] +license = pypi_data['info']['license'] +try: + version = pypi_data['info']['version'] + stable = int(version.split('.')[0])>1 +except: + stable = False +bugtracker = pypi_data['info']['bugtrack_url'] or pypi_data['info']['project_urls'].get('Bug Tracker') or '' +homepage = pypi_data['info']['home_page'] or pypi_data['info']['project_urls'].get('Homepage') +keywords = pypi_data['info']['keywords'] +readme = pypi_data['info']['description'] + +# Write data +file_name.write_text( +f"""--- +name: {name} +author: {author} +license: {license} +open_source: true +stable: {stable} +maintained: true +pypi: true +package_name: {name} +github: {homepage} +gitlab: +source: +issue_tracker:{bugtracker} +website: +categories: +tags: {keywords} +--- +{tagline} + +{readme} +""" +) diff --git a/.github/workflows/collect_plugin.yml b/.github/workflows/collect_plugin.yml new file mode 100644 index 00000000..4060083f --- /dev/null +++ b/.github/workflows/collect_plugin.yml @@ -0,0 +1,41 @@ +name: Collect plugin by PyPI listing + +on: + workflow_dispatch: + inputs: + project: + description: The name of the project on PyPi + required: true + author: + description: Enter the name of the author if you know it + +jobs: + build: + + runs-on: ubuntu-latest + permissions: {} + steps: + - uses: actions/checkout@v2 + with: + token: ${{ secrets.BOT_PAT }} + - name: Get Plugin file + run: python .github/collect_plugin.py + env: + PROJECT: ${{ github.event.inputs.project }} + AUTHOR: ${{ github.event.inputs.author }} + - name: Create Pull Request + uses: peter-evans/create-pull-request@v4 + with: + commit-message: "[REPO] Add plugin ${{ github.event.inputs.project }}" + branch: "plugin/${{ github.event.inputs.project }}" + title: "[REPO] Add plugin ${{ github.event.inputs.project }}" + body: | + Automated PR to add the plugin ${{ github.event.inputs.project }}. + You need to check this manually! + labels: | + plugin + assignees: | + matmair + ${{ github.event.inputs.author }} + reviewers: | + matmair