@@ -35,6 +35,7 @@ async def update_repo(repo: Path, delivery: str, name: str):
35
35
raise web .HTTPServerError (
36
36
reason = f'{ delivery } : Checkout for { name } does not exist' )
37
37
38
+ log .info ('%s: Running git pull for %s at %s' , delivery , name , repo )
38
39
proc = await asyncio .create_subprocess_exec ('git' , 'pull' , cwd = repo )
39
40
try :
40
41
await asyncio .wait_for (proc .wait (), timeout = 60 )
@@ -117,14 +118,24 @@ async def github_webhook(request: web.Request):
117
118
if repository != repo :
118
119
raise web .HTTPBadRequest (reason = f'{ delivery } : incorrect repository' )
119
120
121
+ # Ping event
122
+ # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#ping
120
123
if event == 'ping' :
121
124
log .info ('%s: Ping %s: %s' , delivery , data ['hook_id' ], data ['zen' ])
122
125
return web .Response (status = 200 )
123
126
127
+ # Only allow push events otherwise
128
+ # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
124
129
if event != 'push' :
125
130
log .info ('%s: Ignoring webhook for unused event %s' , delivery , event )
126
131
return web .Response (status = 200 )
127
132
133
+ ref = data .get ('ref' , '' )
134
+ if ref != 'refs/heads/gh-pages' :
135
+ log .info ('%s: Ignoring push event on branch %s other than gh-pages' ,
136
+ delivery , ref )
137
+ return web .Response (status = 200 )
138
+
128
139
checkout = Path (os .environ .get ('SITE_DIR' , 'sites' ), repository )
129
140
await update_repo (checkout , delivery , f'{ organization } /{ repository } ' )
130
141
0 commit comments