Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Jan 5, 2024
1 parent 9bea285 commit f37b717
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pr_views_to_core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: PR Views to PrefectHQ/prefect

on:
pull_request:
branches:
- main
- pr-worker-view
paths:
- 'views/aggregate-worker-metadata.json'

jobs:
update-views:
name: Send updated views to PrefectHQ/prefect
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: pip
cache-dependency-path: requirements*.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade --upgrade-strategy eager -e ".[dev]"
- name: Open PRs to PrefectHQ/prefect
run: src/pr_views_to_core.py

44 changes: 44 additions & 0 deletions src/pr_views_to_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import subprocess
import sys
import asyncio
import httpx
from datetime import datetime

GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
SOURCE_REPO_URL = 'https://raw.githubusercontent.com/PrefectHQ/prefect-collection-registry/main/views/aggregate-worker-metadata.json'
TARGET_FILE_PATH = 'src/prefect/server/api/collections_data/views/aggregate-worker-metadata.json' # noqa E501
TARGET_ORG = 'PrefectHQ'
TARGET_REPO = 'prefect'
NEW_BRANCH = f'update-worker-metadata-{datetime.now().strftime("%Y%m%d%H%M%S")}'

commands = f"""
mkdir -p {os.path.dirname(TARGET_FILE_PATH)} &&
curl -o {TARGET_FILE_PATH} {SOURCE_REPO_URL} &&
git checkout -b {NEW_BRANCH} &&
git add {TARGET_FILE_PATH} &&
git commit -m "Update aggregate-worker-metadata.json" &&
git push -u origin {NEW_BRANCH}
"""
subprocess.check_call(commands, shell=True)

async def create_pull_request(new_branch: str):
async with httpx.AsyncClient() as client:
response = await client.post(
f'https://api.github.com/repos/{TARGET_ORG}/{TARGET_REPO}/pulls',
headers={'Authorization': f'token {GITHUB_TOKEN}'},
json={
'title': 'Automated PR for Worker Metadata Update',
'head': new_branch,
'base': 'main'
}
)

if response.status_code == 201:
print('Pull request created successfully.')
else:
print('Failed to create pull request:', response.json())

if __name__ == '__main__':
new_branch = sys.argv[1] if len(sys.argv) > 1 else NEW_BRANCH
asyncio.run(create_pull_request(new_branch))

0 comments on commit f37b717

Please sign in to comment.