Add GetArchive (#413)
Add GetArchive Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/413 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
4f53f33ebf
commit
595ceb32ff
2 changed files with 26 additions and 0 deletions
|
@ -390,3 +390,19 @@ func (c *Client) GetRepoLanguages(owner, repo string) (map[string]int64, error)
|
||||||
}
|
}
|
||||||
return langMap, nil
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -125,6 +125,16 @@ func TestDeleteRepo(t *testing.T) {
|
||||||
assert.NoError(t, c.DeleteRepo(repo.Owner.UserName, repo.Name))
|
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
|
// standard func to create a init repo for test routines
|
||||||
func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) {
|
func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) {
|
||||||
user, uErr := c.GetMyUserInfo()
|
user, uErr := c.GetMyUserInfo()
|
||||||
|
|
Loading…
Reference in a new issue