File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import os
1111import requests
1212import json
13- from uuid6 import uuid7
1413from base64 import b64encode
1514from 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 )
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ Jinja2==3.1.2
22python-dotenv == 0.20.0
33requests == 2.28.1
44starlette == 0.20.4
5- uuid6 == 2022.6.25
65uvicorn == 0.18.2
76bcrypt == 3.2.2
87cryptography == 37.0.4
You can’t perform that action at this time.
0 commit comments