|
|
@ -77,32 +77,53 @@ func Search(ctx *context.APIContext) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
|
|
|
func listUserRepositories(ctx *context.APIContext, username string) { |
|
|
|
func ListMyRepos(ctx *context.APIContext) { |
|
|
|
user, err := models.GetUserByName(username) |
|
|
|
ownRepos, err := models.GetUserRepositories(&models.UserRepoOptions{ |
|
|
|
if err != nil { |
|
|
|
UserID: ctx.User.ID, |
|
|
|
ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err) |
|
|
|
Private: true, |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only list public repositories if user requests someone else's repository list,
|
|
|
|
|
|
|
|
// or an organization isn't a member of.
|
|
|
|
|
|
|
|
var ownRepos []*models.Repository |
|
|
|
|
|
|
|
if user.IsOrganization() { |
|
|
|
|
|
|
|
ownRepos, _, err = user.GetUserRepositories(ctx.User.ID, 1, user.NumRepos) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ownRepos, err = models.GetUserRepositories(&models.UserRepoOptions{ |
|
|
|
|
|
|
|
UserID: user.ID, |
|
|
|
|
|
|
|
Private: ctx.User.ID == user.ID, |
|
|
|
Page: 1, |
|
|
|
Page: 1, |
|
|
|
PageSize: ctx.User.NumRepos, |
|
|
|
PageSize: user.NumRepos, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Error(500, "GetRepositories", err) |
|
|
|
ctx.Error(500, "GetUserRepositories", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
numOwnRepos := len(ownRepos) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accessibleRepos, err := ctx.User.GetRepositoryAccesses() |
|
|
|
if ctx.User.ID != user.ID { |
|
|
|
|
|
|
|
repos := make([]*api.Repository, len(ownRepos)) |
|
|
|
|
|
|
|
for i := range ownRepos { |
|
|
|
|
|
|
|
repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.JSON(200, &repos) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accessibleRepos, err := user.GetRepositoryAccesses() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Error(500, "GetRepositoryAccesses", err) |
|
|
|
ctx.Error(500, "GetRepositoryAccesses", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
numOwnRepos := len(ownRepos) |
|
|
|
repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) |
|
|
|
repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) |
|
|
|
for i := range ownRepos { |
|
|
|
for i := range ownRepos { |
|
|
|
repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true}) |
|
|
|
repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true}) |
|
|
|
} |
|
|
|
} |
|
|
|
i := numOwnRepos |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i := numOwnRepos |
|
|
|
for repo, access := range accessibleRepos { |
|
|
|
for repo, access := range accessibleRepos { |
|
|
|
repos[i] = repo.APIFormat(&api.Permission{ |
|
|
|
repos[i] = repo.APIFormat(&api.Permission{ |
|
|
|
Admin: access >= models.ACCESS_MODE_ADMIN, |
|
|
|
Admin: access >= models.ACCESS_MODE_ADMIN, |
|
|
@ -115,6 +136,18 @@ func ListMyRepos(ctx *context.APIContext) { |
|
|
|
ctx.JSON(200, &repos) |
|
|
|
ctx.JSON(200, &repos) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ListMyRepos(ctx *context.APIContext) { |
|
|
|
|
|
|
|
listUserRepositories(ctx, ctx.User.Name) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ListUserRepositories(ctx *context.APIContext) { |
|
|
|
|
|
|
|
listUserRepositories(ctx, ctx.Params(":username")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ListOrgRepositories(ctx *context.APIContext) { |
|
|
|
|
|
|
|
listUserRepositories(ctx, ctx.Params(":org")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) { |
|
|
|
func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) { |
|
|
|
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{ |
|
|
|
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{ |
|
|
|
Name: opt.Name, |
|
|
|
Name: opt.Name, |
|
|
|