Skip to content

Commit

Permalink
Create commit-user-records.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Real-MullaC authored Jul 21, 2024
1 parent e6138fc commit 3036d02
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/commit-user-records.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Commit User Records

on:
push:
branches:
- main # or your default branch
workflow_dispatch:

jobs:
commit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
pip install PyGithub
- name: Commit and push user records
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python -c "
import os
import json
from github import Github

# GitHub repository details
GITHUB_REPO_OWNER = 'ChrisTitusTech'
GITHUB_REPO_NAME = 'WinUtil'
FILE_PATH = 'user_records.json'

# Load user records (simulate here, you may use actual logic)
user_records = {'example_user_id': {'github_username': 'example_user', 'contributions': 'some_status'}}

# Convert user records to JSON
file_content = json.dumps(user_records, indent=4)

# Initialize GitHub client
g = Github(os.getenv('GITHUB_TOKEN'))
repo = g.get_repo(f'{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}')

# Update or create file in the repository
try:
file = repo.get_contents(FILE_PATH)
repo.update_file(file.path, 'Update user records', file_content, file.sha)
except:
repo.create_file(FILE_PATH, 'Create user records file', file_content)

print('User records committed successfully.')
"

0 comments on commit 3036d02

Please sign in to comment.