Add GetRepoLanguages (#412)
Add GetRepoLanguages Add Migration Language Tests Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/412 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
1a3d9bf20c
commit
5904d8e622
2 changed files with 52 additions and 0 deletions
|
@ -376,3 +376,17 @@ func (c *Client) MirrorSync(owner, repo string) error {
|
||||||
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/mirror-sync", owner, repo), nil, nil)
|
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/mirror-sync", owner, repo), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRepoLanguages return language stats of a repo
|
||||||
|
func (c *Client) GetRepoLanguages(owner, repo string) (map[string]int64, error) {
|
||||||
|
langMap := make(map[string]int64)
|
||||||
|
|
||||||
|
data, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/languages", owner, repo), jsonHeader, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(data, &langMap); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return langMap, nil
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package gitea
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -31,6 +32,43 @@ func TestCreateRepo(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRepoMigrateAndLanguages(t *testing.T) {
|
||||||
|
log.Println("== TestMigrateRepo ==")
|
||||||
|
c := newTestClient()
|
||||||
|
user, uErr := c.GetMyUserInfo()
|
||||||
|
assert.NoError(t, uErr)
|
||||||
|
_, err := c.GetRepo(user.UserName, "sdk-mirror")
|
||||||
|
if err == nil {
|
||||||
|
_ = c.DeleteRepo(user.UserName, "sdk-mirror")
|
||||||
|
}
|
||||||
|
|
||||||
|
repoM, err := c.MigrateRepo(MigrateRepoOption{
|
||||||
|
CloneAddr: "https://gitea.com/gitea/go-sdk.git",
|
||||||
|
RepoName: "sdk-mirror",
|
||||||
|
UID: int(user.ID),
|
||||||
|
Mirror: true,
|
||||||
|
Private: false,
|
||||||
|
Description: "mirror sdk",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
repoG, err := c.GetRepo(repoM.Owner.UserName, repoM.Name)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, repoM.ID, repoG.ID)
|
||||||
|
assert.EqualValues(t, "master", repoG.DefaultBranch)
|
||||||
|
assert.True(t, repoG.Mirror)
|
||||||
|
assert.False(t, repoG.Empty)
|
||||||
|
assert.EqualValues(t, 1, repoG.Watchers)
|
||||||
|
|
||||||
|
log.Println("== TestRepoLanguages ==")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
lang, err := c.GetRepoLanguages(repoM.Owner.UserName, repoM.Name)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, lang, 2)
|
||||||
|
assert.True(t, 217441 < lang["Go"])
|
||||||
|
assert.EqualValues(t, 3578, lang["Makefile"])
|
||||||
|
}
|
||||||
|
|
||||||
func TestSearchRepo(t *testing.T) {
|
func TestSearchRepo(t *testing.T) {
|
||||||
log.Println("== TestSearchRepo ==")
|
log.Println("== TestSearchRepo ==")
|
||||||
c := newTestClient()
|
c := newTestClient()
|
||||||
|
|
Loading…
Reference in a new issue