|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from urllib.parse import quote |
| 4 | + |
| 5 | +from github import Github |
| 6 | + |
| 7 | +# Authenticate with GitHub |
| 8 | +access_token = os.getenv("GITHUB_TOKEN") |
| 9 | +g = Github(access_token) |
| 10 | + |
| 11 | + |
| 12 | +repo_name = "widgetti/solara" |
| 13 | +pr_number = int(sys.argv[1]) # e.g 65 |
| 14 | +type = "solara" # streamlit/dash/vizro/solara/panel |
| 15 | + |
| 16 | +# your default code |
| 17 | +code = """import ipyreact |
| 18 | +
|
| 19 | +
|
| 20 | +class ConfettiWidget(ipyreact.ValueWidget): |
| 21 | + _esm = \""" |
| 22 | + import confetti from "canvas-confetti"; |
| 23 | + import * as React from "react"; |
| 24 | +
|
| 25 | + export default function({value, setValue}) { |
| 26 | + return <button onClick={() => confetti() && setValue(value + 1)}> |
| 27 | + {value || 0} times confetti |
| 28 | + </button> |
| 29 | + };\""" |
| 30 | +page = ConfettiWidget() |
| 31 | +""" |
| 32 | + |
| 33 | +# your default requirements |
| 34 | +requirements = """solara |
| 35 | +ipyreact |
| 36 | +""" |
| 37 | + |
| 38 | +# GitHub Python API |
| 39 | +repo = g.get_repo(repo_name) |
| 40 | +pr = repo.get_pull(pr_number) |
| 41 | + |
| 42 | +base_url = f"https://py.cafe/snippet/{type}/v1" |
| 43 | +url = f"{base_url}#code={quote(code)}&requirements={quote(requirements)}" |
| 44 | + |
| 45 | +commit_sha = pr.head.sha |
| 46 | + |
| 47 | +# Define the deployment status |
| 48 | +state = "success" # Options: 'error', 'failure', 'pending', 'success' |
| 49 | +description = "Test out this PR on a PyCafe environment" |
| 50 | +context = "PyCafe" |
| 51 | + |
| 52 | +# Create the status on the commit |
| 53 | +commit = repo.get_commit(commit_sha) |
| 54 | +commit.create_status(state="success", target_url=url, description="Test this PR in PyCafe environment", context="PyCafe") |
| 55 | +print(f"Deployment status added to commit {commit_sha}, PR https://github.com/{repo_name}/pull/{pr_number}") |
0 commit comments