def list_github_directories(owner, repo, path, ref=None, username=None, password=None): subdirs = [] if ref: path += '?ref=%s' % urllib.quote(ref) dirlist = github_api(owner, repo, '/contents%s' % path, username=username, password=password) if 'message' in dirlist: # If the path was not found, return an empty list if dirlist['message'] == 'Not Found': return subdirs # Otherwise, we hit a real error and need to raise it raise ValueError(dirlist['message']) for item in dirlist: # Skip files, we only want directories if item['type'] != 'dir': continue subdirs.append(item['name']) return subdirs
def github_api(self, path, data=None, fork=None, as_contributor=None): if fork: owner = self.contributor.user.username username = self.github_token() password = '' else: owner = self.get_main_repo_owner() if as_contributor: username = self.github_token() password = '' else: username = self.package_version.github_username password = self.package_version.github_password return github_api( owner = owner, repo = self.get_main_repo_name(), subpath = path, data = data, username = username, password = password, )