From d861f9b646a027306013f11778ce3abb5ffeb7d1 Mon Sep 17 00:00:00 2001 From: jakedt Date: Mon, 24 Feb 2014 13:56:21 -0500 Subject: [PATCH] Add some code for finding Dockerfiles in the repository. --- endpoints/trigger.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/endpoints/trigger.py b/endpoints/trigger.py index cd9066766..7634c74a3 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -1,5 +1,6 @@ import logging import io +import os.path from github import Github, UnknownObjectException, GithubException from tempfile import SpooledTemporaryFile @@ -42,6 +43,13 @@ class BuildTrigger(object): """ raise NotImplementedError + def list_build_subdirs(self, auth_token, config): + """ + Take the auth information and the specified config so far and list all of + the possible subdirs containing dockerfiles. + """ + raise NotImplementedError + def handle_trigger_request(self, request, auth_token, config): """ Transform the incoming request data into a set of actions. @@ -132,7 +140,7 @@ class GithubBuildTrigger(BuildTrigger): for org in usr.get_orgs(): repo_list = [] - for repo in org.get_repos(): + for repo in org.get_repos(type='member'): repo_list.append(repo.full_name) repos_by_org.append({ @@ -146,6 +154,18 @@ class GithubBuildTrigger(BuildTrigger): return repos_by_org + def list_build_subdirs(self, auth_token, config): + gh_client = self._get_client(auth_token) + source = config['build_source'] + + repo = gh_client.get_repo(source) + default_commit = repo.get_branch(repo.default_branch).commit + commit_tree = repo.get_git_tree(default_commit.sha, recursive=True) + + return [os.path.dirname(elem.path) for elem in commit_tree.tree + if (elem.type == u'blob' and + os.path.basename(elem.path) == u'Dockerfile')] + def handle_trigger_request(self, request, auth_token, config): payload = request.get_json()