Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit ba2d5c0

Browse files
committed
Use "deployment" event, not "deployment_status"
1 parent 06fc419 commit ba2d5c0

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

.github/workflows/detect_pull_request_preview.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Detect Pull Request Preview
2-
on: deployment_status
2+
on: deployment
33
jobs:
44
detect-deployment:
55
runs-on: ubuntu-18.04
@@ -12,8 +12,8 @@ jobs:
1212
./tools/ci/pr_preview.py
1313
--host http://api.github.com
1414
--github-project web-platform-tests/wpt-actions-test
15-
--target http://s92097608.onlinehome.us/tmp
1615
detect
16+
--target http://s92097608.onlinehome.us/tmp
1717
--timeout 600
1818
env:
1919
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pull_request_previews.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
./tools/ci/pr_preview.py
1515
--host https://api.github.com
1616
--github-project web-platform-tests/wpt-actions-test
17-
--target http://s92097608.onlinehome.us/tmp
1817
synchronize
1918
--remote origin
2019
--window 480

tools/ci/pr_preview.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,6 @@ def get_deployment(self, revision):
177177

178178
return deployments.pop() if len(deployments) else None
179179

180-
@guard('core')
181-
def deployment_is_pending(self, deployment):
182-
url = '{}/repos/{}/deployments/{}/statuses'.format(
183-
self._host, self._github_project, deployment['id']
184-
)
185-
186-
statuses = sorted(
187-
gh_request('GET', url),
188-
key=lambda status: status['created_at']
189-
)
190-
191-
if len(statuses) == 0:
192-
return False
193-
194-
return statuses[-1]['state'] == 'pending'
195-
196180
@guard('core')
197181
def update_deployment(self, target, deployment, state, description=''):
198182
if state in ('pending', 'success'):
@@ -263,7 +247,7 @@ def is_deployed(host, deployment):
263247

264248
return response.text.strip() == deployment['sha']
265249

266-
def synchronize(host, github_project, target, remote_name, window):
250+
def synchronize(host, github_project, remote_name, window):
267251
'''Inspect all pull requests which have been modified in a given window of
268252
time. Add or remove the "preview" label and update or delete the relevant
269253
git refs according to the status of each pull request.'''
@@ -304,14 +288,10 @@ def synchronize(host, github_project, target, remote_name, window):
304288
elif revision_open != revision_latest:
305289
project.update_ref(refspec_open, revision_latest)
306290

307-
deployment = project.get_deployment(revision_latest)
308-
if deployment is None:
309-
deployment = project.create_deployment(
291+
if project.get_deployment(revision_latest) is None:
292+
project.create_deployment(
310293
pull_request, revision_latest
311294
)
312-
313-
if not project.deployment_is_pending(deployment):
314-
project.update_deployment(target, deployment, 'pending')
315295
else:
316296
logger.info('Pull request should not be mirrored')
317297

@@ -333,22 +313,20 @@ def detect(host, github_project, target, timeout):
333313

334314
logger.info('Event data: %s', json.dumps(data, indent=2))
335315

336-
if data['deployment_status']['state'] != 'pending':
337-
logger.info('Deployment is not pending. Exiting.')
338-
return
339-
340316
deployment = data['deployment']
341317

342318
if not deployment['environment'].startswith('gh-'):
343319
logger.info('Deployment environment is unrecognized. Exiting.')
344320
return
345321

322+
message = 'Waiting up to %d seconds for deployment %s to be available on %s'
346323
logger.info(
347-
'Waiting up to %d seconds for deployment %s to be available on %s',
324+
message,
348325
timeout,
349326
deployment['environment'],
350327
target
351328
)
329+
project.update_deployment(target, deployment, 'pending', message)
352330

353331
start = time.time()
354332

@@ -372,7 +350,6 @@ def detect(host, github_project, target, timeout):
372350
help='''the GitHub organization and GitHub project name, separated by
373351
a forward slash (e.g. "web-platform-tests/wpt")'''
374352
)
375-
parser.add_argument('--target', required=True)
376353
subparsers = parser.add_subparsers(title='subcommands')
377354

378355
parser_sync = subparsers.add_parser(
@@ -383,6 +360,7 @@ def detect(host, github_project, target, timeout):
383360
parser_sync.set_defaults(func=synchronize)
384361

385362
parser_detect = subparsers.add_parser('detect', help=detect.__doc__)
363+
parser_detect.add_argument('--target', required=True)
386364
parser_detect.add_argument('--timeout', type=int, required=True)
387365
parser_detect.set_defaults(func=detect)
388366

0 commit comments

Comments
 (0)