Skip to content

Commit e88d2d6

Browse files
committed
add routine to fetch build targets for docker testbot
1 parent 1bc12cb commit e88d2d6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

obspy_github_api/obspy_github_api.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,60 @@ def set_all_updated_pull_requests_docker_testbot_pending(verbose=False):
295295
description="docker testbot results not available yet",
296296
only_when_no_status_yet=True,
297297
verbose=verbose)
298+
299+
300+
def get_docker_build_targets(
301+
context="docker-testbot", branches=["master", "maintenance_1.0.x"],
302+
prs=True):
303+
"""
304+
Returns a list of build targets that need a build of a given context.
305+
306+
Checks potential build targets, i.e. tips of open pull requests and tips of
307+
main branches (like "master"), whether they have a commit status of a given
308+
context or not.
309+
Returns a (space separated) string representation of the list of build
310+
targets as interpreted by the docker testing script in obspy/misc/docker
311+
(space separated list, individual build targets as `PRNUMBER_REPO:REF`,
312+
e.g.
313+
'XXX_obspy:master 1541_obspy:3edade31350b945620447a3b78f80c26782407ae').
314+
315+
:type context: str
316+
:param context: Commit status context to check.
317+
:type branches: list
318+
:param branches: Branches to include as potential build targets.
319+
:type prs: bool
320+
:param prs: Whether to include open pull requests as potential build
321+
targets or not.
322+
:returns: String representation of list of build targets for use in docker
323+
testbot bash script (obspy/misc/docker).
324+
:rtype: string
325+
"""
326+
if not branches and not prs:
327+
return ''
328+
329+
status_needs_build = (None, 'pending')
330+
targets = []
331+
repo = gh.repository('obspy', 'obspy')
332+
333+
if branches:
334+
for name in branches:
335+
branch = repo.branch(name)
336+
sha = branch.commit.sha
337+
status = get_commit_status(sha)
338+
if status not in status_needs_build:
339+
continue
340+
# branches don't have a PR number, use dummy placeholder 'XXX' so
341+
# that variable splitting in bash still works
342+
targets.append('XXX_obspy:{}'.format(sha))
343+
344+
if prs:
345+
open_prs = get_pull_requests(state='open')
346+
for pr in open_prs:
347+
fork = pr.head.user
348+
sha = pr.head.sha
349+
status = get_commit_status(sha)
350+
if status not in status_needs_build:
351+
continue
352+
targets.append('{}_{}:{}'.format(str(pr.number), fork, sha))
353+
354+
return ' '.join(targets)

0 commit comments

Comments
 (0)