Add some code for finding Dockerfiles in the repository.

This commit is contained in:
jakedt 2014-02-24 13:56:21 -05:00
parent 86e93a2c0f
commit d861f9b646

View file

@ -1,5 +1,6 @@
import logging import logging
import io import io
import os.path
from github import Github, UnknownObjectException, GithubException from github import Github, UnknownObjectException, GithubException
from tempfile import SpooledTemporaryFile from tempfile import SpooledTemporaryFile
@ -42,6 +43,13 @@ class BuildTrigger(object):
""" """
raise NotImplementedError 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): def handle_trigger_request(self, request, auth_token, config):
""" """
Transform the incoming request data into a set of actions. Transform the incoming request data into a set of actions.
@ -132,7 +140,7 @@ class GithubBuildTrigger(BuildTrigger):
for org in usr.get_orgs(): for org in usr.get_orgs():
repo_list = [] repo_list = []
for repo in org.get_repos(): for repo in org.get_repos(type='member'):
repo_list.append(repo.full_name) repo_list.append(repo.full_name)
repos_by_org.append({ repos_by_org.append({
@ -146,6 +154,18 @@ class GithubBuildTrigger(BuildTrigger):
return repos_by_org 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): def handle_trigger_request(self, request, auth_token, config):
payload = request.get_json() payload = request.get_json()