diff --git a/gitea/repo.go b/gitea/repo.go index afd6e40..3546ef2 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -390,3 +390,19 @@ func (c *Client) GetRepoLanguages(owner, repo string) (map[string]int64, error) } return langMap, nil } + +// ArchiveType represent supported archive formats by gitea +type ArchiveType string + +const ( + // ZipArchive represent zip format + ZipArchive ArchiveType = ".zip" + // TarGZArchive represent tar.gz format + TarGZArchive ArchiveType = ".tar.gz" +) + +// GetArchive get an archive of a repository by git reference +// e.g.: ref -> master, 70b7c74b33, v1.2.1, ... +func (c *Client) GetArchive(owner, repo, ref string, ext ArchiveType) ([]byte, error) { + return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/archive/%s%s", owner, repo, url.PathEscape(ref), ext), nil, nil) +} diff --git a/gitea/repo_test.go b/gitea/repo_test.go index 709a218..0899850 100644 --- a/gitea/repo_test.go +++ b/gitea/repo_test.go @@ -125,6 +125,16 @@ func TestDeleteRepo(t *testing.T) { assert.NoError(t, c.DeleteRepo(repo.Owner.UserName, repo.Name)) } +func TestGetArchive(t *testing.T) { + log.Println("== TestGetArchive ==") + c := newTestClient() + repo, _ := createTestRepo(t, "ToDownload", c) + time.Sleep(time.Second / 2) + archive, err := c.GetArchive(repo.Owner.UserName, repo.Name, "master", ZipArchive) + assert.NoError(t, err) + assert.EqualValues(t, 1620, len(archive)) +} + // standard func to create a init repo for test routines func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) { user, uErr := c.GetMyUserInfo()