Commit b09baa1b authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Project: archive download helpers

This provides the way to test the repository download links
(which are backed by `hg archive` and `git archive`).
parent b2a5da28ceb5
import attr
from base64 import b64decode
import hashlib
from io import BytesIO
import logging
import os
import py
......@@ -287,6 +288,26 @@ class Project(object):
def make_storage_hashed(self):
self._change_storage(False)
def archive_url(self, gitlab_branch, file_ext):
base_file_name = '-'.join([self.name] + gitlab_branch.split('/'))
return '/'.join((self.url,
'-', 'archive',
gitlab_branch,
base_file_name + '.' + file_ext
))
def get_archive(self, gitlab_branch, fmt='tar'):
"""Retrieve a repository archive by URL.
:param fmt: the wished format. At this point, this is directly
mapped as a file extension in the request, and only the `tar`
value is tested.
:returns: the archive content, as a files-like object
"""
resp = requests.get(self.archive_url(gitlab_branch, fmt))
assert resp.status_code == 200
return BytesIO(resp.content)
def api_branches(self):
"""Retrieve and pre-sort branches info through the REST API."""
resp = self.owner_api_get(subpath='repository/branches')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment