Skip to content

Commit 62592c1

Browse files
committed
#6 autorun deploy workflow
shorten app generated name
1 parent 74fc43f commit 62592c1

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

app.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import os
1111
import requests
1212
import json
13-
from uuid6 import uuid7
1413
from base64 import b64encode
1514
from nacl import encoding, public
1615

@@ -109,8 +108,8 @@ async def githubcallback(request):
109108
headers = {"Authorization": f"token {access_token}"}
110109
headers["Accept"] = "application/vnd.github+json"
111110
# Create unique repo name
112-
uuid = uuid7()
113-
repo_name = f"container-hosting-{uuid}"
111+
random_string = secrets.token_urlsafe(5).lower()
112+
repo_name = f"container-hosting-{random_string}"
114113
data = {
115114
"name": repo_name,
116115
"description": "Repository created",
@@ -258,6 +257,15 @@ async def githubcallback(request):
258257
data=json.dumps(data),
259258
)
260259

260+
# Get the deploy workflow id
261+
import time;time.sleep(3) # TODO hook/poll
262+
req = requests.get(f"https://api.github.com/repos/{username}/{repo_name}/actions/workflows", headers=headers)
263+
deploy_workflow_id = req.json()['workflows'][0]['id']
264+
# Start the deploy.yml workflow action
265+
data = {"ref":"main"}
266+
267+
req = requests.post(f'https://api.github.com/repos/{username}/{repo_name}/actions/workflows/{deploy_workflow_id}/dispatches', headers=headers, data=json.dumps(data))
268+
261269
return templates.TemplateResponse(
262270
"welcome.html", {"repo_url": repo_url, "request": request}
263271
)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Jinja2==3.1.2
22
python-dotenv==0.20.0
33
requests==2.28.1
44
starlette==0.20.4
5-
uuid6==2022.6.25
65
uvicorn==0.18.2
76
bcrypt==3.2.2
87
cryptography==37.0.4

0 commit comments

Comments
 (0)