2
0
mirror of https://github.com/inventree/inventree-website.git synced 2025-05-14 21:13:10 +00:00

Add translations to state section ()

* add option for auth

* get crowdin data

* factor out project name

* add dep

* add secret to env

* fix step name
This commit is contained in:
Matthias Mair 2022-12-09 00:29:13 +01:00 committed by GitHub
parent 6ef25cf8f0
commit 0977b97b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

25
.github/get_stats.py vendored

@ -1,18 +1,24 @@
from enum import Enum
import json
import os
from pathlib import Path
from urllib.request import urlopen, Request
file_name = Path('_data/general/stats.yml')
github_project = "inventree/inventree"
crowdin_projet_id = 452300
class ReturnMode(Enum):
data = 0
header = 1
def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data):
def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data, 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:
if mode == ReturnMode.data:
data = response.read().decode()
@ -26,13 +32,17 @@ def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data):
return data
docker = get_data('https://hub.docker.com/v2/repositories/inventree/inventree', 'pull_count')
gh_data = get_data('https://api.github.com/repos/inventree/inventree')
docker = get_data(f'https://hub.docker.com/v2/repositories/{github_project}', 'pull_count')
gh_data = get_data(f'https://api.github.com/repos/{github_project}')
stars = gh_data.get('stargazers_count', 0)
forks = gh_data.get('forks_count', 0)
# See https://stackoverflow.com/a/60458265/17860466 # to enabble anon add `&anon=true`
link = get_data('https://api.github.com/repos/inventree/inventree/contributors?per_page=1', mode=ReturnMode.header).get('Link')
link = get_data(f'https://api.github.com/repos/{github_project}/contributors?per_page=1', mode=ReturnMode.header).get('Link')
contributors = link.split('page=')[-1].split('>')[0]
# Crowdin
crowdin_data = get_data(f'https://api.crowdin.com/api/v2/projects/{crowdin_projet_id}?limit=1000', 'data', auth=os.environ.get('CROWDIN_TOKEN'))
languages = len(crowdin_data.get('targetLanguageIds', []))
#translators = get_data(f'https://api.crowdin.com/api/v2/projects/{crowdin_projet_id}/members', 'data', auth=crowdin_token)
# Write data
file_name.write_text(
@ -44,4 +54,9 @@ f"""stats:
- name: Forks
number: {forks}
- name: Contributors
number: {contributors}""")
number: {contributors}
- name: Languages
number: {languages}""")
#- name: Translators
# number: {translators}
# """)

@ -12,8 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set selected color
- name: Get Stats
run: python .github/get_stats.py
env:
CROWDIN_TOKEN: ${{ secrets.CROWDIN_TOKEN }}
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[Bot] Updated the stats"