mirror of
https://github.com/inventree/inventree-website.git
synced 2025-04-28 05:26:44 +00:00
use python script for updates
This commit is contained in:
parent
c7790a4aaf
commit
5583d8b3a5
47
.github/get_stats.py
vendored
Normal file
47
.github/get_stats.py
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from enum import Enum
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from urllib.request import urlopen, Request
|
||||||
|
|
||||||
|
file_name = Path('_data/general/stats.yml')
|
||||||
|
|
||||||
|
class ReturnMode(Enum):
|
||||||
|
data = 0
|
||||||
|
header = 1
|
||||||
|
|
||||||
|
def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data):
|
||||||
|
"""Fetches data from remote endpoint"""
|
||||||
|
httprequest = Request(url, headers={"Accept": "application/json"})
|
||||||
|
|
||||||
|
with urlopen(httprequest) as response:
|
||||||
|
if mode == ReturnMode.data:
|
||||||
|
data = response.read().decode()
|
||||||
|
data = json.loads(data)
|
||||||
|
|
||||||
|
elif mode == ReturnMode.header:
|
||||||
|
data = dict(response.headers.items())
|
||||||
|
|
||||||
|
if key:
|
||||||
|
data = data.get(key, default)
|
||||||
|
|
||||||
|
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')
|
||||||
|
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')
|
||||||
|
contributors = link.split('page=')[-1].split('>')[0]
|
||||||
|
|
||||||
|
# Write data
|
||||||
|
file_name.write_text(
|
||||||
|
f"""stats:
|
||||||
|
- name: Docker pulls
|
||||||
|
number: {docker}
|
||||||
|
- name: GitHub Stars
|
||||||
|
number: {stars}
|
||||||
|
- name: Forks
|
||||||
|
number: {forks}
|
||||||
|
- name: Contributors
|
||||||
|
number: {contributors}""")
|
33
.github/workflows/get_stats.yml
vendored
33
.github/workflows/get_stats.yml
vendored
@ -2,28 +2,6 @@ name: Get stats
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
|
||||||
logLevel:
|
|
||||||
description: 'Log level'
|
|
||||||
required: true
|
|
||||||
default: 'warning'
|
|
||||||
type: choice
|
|
||||||
options:
|
|
||||||
- info
|
|
||||||
- warning
|
|
||||||
- debug
|
|
||||||
print_tags:
|
|
||||||
description: 'True to print to STDOUT'
|
|
||||||
required: true
|
|
||||||
type: boolean
|
|
||||||
tags:
|
|
||||||
description: 'Test scenario tags'
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
environment:
|
|
||||||
description: 'Environment to run tests against'
|
|
||||||
type: environment
|
|
||||||
required: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -33,9 +11,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set selected color
|
- name: Set selected color
|
||||||
run: echo '::set-output name=SELECTED_COLOR::green'
|
run: python .github/get_stats.py
|
||||||
id: random-color-generator
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
- name: Docker stats
|
with:
|
||||||
run: |
|
commit_message: "[Bot] Updated the stats"
|
||||||
curl -s https://hub.docker.com/v2/repositories/inventree/inventree/ | jq -r ".pull_count"
|
branch: main
|
||||||
id: docker-pulls
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user