mirror of
https://github.com/inventree/inventree-website.git
synced 2025-04-28 05:26:44 +00:00
Add plugin workflow (#114)
* Add cups plugin * Add workflow to add plugins
This commit is contained in:
parent
bc3ca14bb6
commit
007f04f9e9
67
.github/collect_plugin.py
vendored
Normal file
67
.github/collect_plugin.py
vendored
Normal file
@ -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}
|
||||
"""
|
||||
)
|
41
.github/workflows/collect_plugin.yml
vendored
Normal file
41
.github/workflows/collect_plugin.yml
vendored
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user