mirror of
https://github.com/inventree/inventree-website.git
synced 2025-04-28 05:26:44 +00:00
commit
ed2c99c137
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}""")
|
35
.github/workflows/get_stats.yml
vendored
35
.github/workflows/get_stats.yml
vendored
@ -2,28 +2,8 @@ name: Get stats
|
||||
|
||||
on:
|
||||
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
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@ -33,9 +13,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set selected color
|
||||
run: echo '::set-output name=SELECTED_COLOR::green'
|
||||
id: random-color-generator
|
||||
- name: Docker stats
|
||||
run: |
|
||||
curl -s https://hub.docker.com/v2/repositories/inventree/inventree/ | jq -r ".pull_count"
|
||||
id: docker-pulls
|
||||
run: python .github/get_stats.py
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: "[Bot] Updated the stats"
|
||||
branch: main
|
||||
|
33
.github/workflows/preview.yml
vendored
33
.github/workflows/preview.yml
vendored
@ -1,33 +0,0 @@
|
||||
name: Deploy PR previews
|
||||
concurrency: preview-${{ github.ref }}
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
- closed
|
||||
jobs:
|
||||
deploy-preview:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.7
|
||||
bundler-cache: true
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
- run: npm install
|
||||
- name: Build site
|
||||
uses: limjh16/jekyll-action-ts@v2
|
||||
with:
|
||||
enable_cache: true
|
||||
- uses: rossjrw/pr-preview-action@v1
|
||||
with:
|
||||
source-dir: .
|
||||
preview-branch: gh-pages
|
||||
umbrella-dir: _site/pr-preview
|
||||
action: auto
|
Loading…
x
Reference in New Issue
Block a user