Move Repo APIFormat to convert package (#13787)
* Move Repo APIFormat to convert package * tweek
This commit is contained in:
parent
2b4a08e962
commit
7ac8a770e1
18 changed files with 201 additions and 193 deletions
|
@ -492,7 +492,7 @@ func GetTeamRepos(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
||||
return
|
||||
}
|
||||
repos[i] = repo.APIFormat(access)
|
||||
repos[i] = convert.ToRepo(repo, access)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, repos)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
|
@ -58,7 +59,7 @@ func ListForks(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
return
|
||||
}
|
||||
apiForks[i] = fork.APIFormat(access)
|
||||
apiForks[i] = convert.ToRepo(fork, access)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, apiForks)
|
||||
}
|
||||
|
@ -125,5 +126,5 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
|
|||
}
|
||||
|
||||
//TODO change back to 201
|
||||
ctx.JSON(http.StatusAccepted, fork.APIFormat(models.AccessModeOwner))
|
||||
ctx.JSON(http.StatusAccepted, convert.ToRepo(fork, models.AccessModeOwner))
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ func TestHook(ctx *context.APIContext) {
|
|||
Commits: []*api.PayloadCommit{
|
||||
convert.ToPayloadCommit(ctx.Repo.Repository, ctx.Repo.Commit),
|
||||
},
|
||||
Repo: ctx.Repo.Repository.APIFormat(models.AccessModeNone),
|
||||
Repo: convert.ToRepo(ctx.Repo.Repository, models.AccessModeNone),
|
||||
Pusher: convert.ToUser(ctx.User, ctx.IsSigned, false),
|
||||
Sender: convert.ToUser(ctx.User, ctx.IsSigned, false),
|
||||
}); err != nil {
|
||||
|
|
|
@ -21,13 +21,13 @@ import (
|
|||
func appendPrivateInformation(apiKey *api.DeployKey, key *models.DeployKey, repository *models.Repository) (*api.DeployKey, error) {
|
||||
apiKey.ReadOnly = key.Mode == models.AccessModeRead
|
||||
if repository.ID == key.RepoID {
|
||||
apiKey.Repository = repository.APIFormat(key.Mode)
|
||||
apiKey.Repository = convert.ToRepo(repository, key.Mode)
|
||||
} else {
|
||||
repo, err := models.GetRepositoryByID(key.RepoID)
|
||||
if err != nil {
|
||||
return apiKey, err
|
||||
}
|
||||
apiKey.Repository = repo.APIFormat(key.Mode)
|
||||
apiKey.Repository = convert.ToRepo(repo, key.Mode)
|
||||
}
|
||||
return apiKey, nil
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
|
|||
}
|
||||
|
||||
log.Trace("Repository migrated: %s/%s", repoOwner.Name, form.RepoName)
|
||||
ctx.JSON(http.StatusCreated, repo.APIFormat(models.AccessModeAdmin))
|
||||
ctx.JSON(http.StatusCreated, convert.ToRepo(repo, models.AccessModeAdmin))
|
||||
}
|
||||
|
||||
func handleMigrateError(ctx *context.APIContext, repoOwner *models.User, remoteAddr string, err error) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -217,7 +218,7 @@ func Search(ctx *context.APIContext) {
|
|||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
results[i] = repo.APIFormat(accessMode)
|
||||
results[i] = convert.ToRepo(repo, accessMode)
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(count), opts.PageSize)
|
||||
|
@ -265,7 +266,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
|||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, repo.APIFormat(models.AccessModeOwner))
|
||||
ctx.JSON(http.StatusCreated, convert.ToRepo(repo, models.AccessModeOwner))
|
||||
}
|
||||
|
||||
// Create one repository of mine
|
||||
|
@ -406,7 +407,7 @@ func Get(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/Repository"
|
||||
|
||||
ctx.JSON(http.StatusOK, ctx.Repo.Repository.APIFormat(ctx.Repo.AccessMode))
|
||||
ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode))
|
||||
}
|
||||
|
||||
// GetByID returns a single Repository
|
||||
|
@ -445,7 +446,7 @@ func GetByID(ctx *context.APIContext) {
|
|||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, repo.APIFormat(perm.AccessMode))
|
||||
ctx.JSON(http.StatusOK, convert.ToRepo(repo, perm.AccessMode))
|
||||
}
|
||||
|
||||
// Edit edit repository properties
|
||||
|
@ -494,7 +495,7 @@ func Edit(ctx *context.APIContext, opts api.EditRepoOption) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, ctx.Repo.Repository.APIFormat(ctx.Repo.AccessMode))
|
||||
ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode))
|
||||
}
|
||||
|
||||
// updateBasicProperties updates the basic properties of a repo: Name, Description, Website and Visibility
|
||||
|
|
|
@ -300,7 +300,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
|
|||
retStatus := &combinedCommitStatus{
|
||||
SHA: sha,
|
||||
TotalCount: len(statuses),
|
||||
Repo: repo.APIFormat(ctx.Repo.AccessMode),
|
||||
Repo: convert.ToRepo(repo, ctx.Repo.AccessMode),
|
||||
URL: "",
|
||||
}
|
||||
|
||||
|
|
|
@ -105,5 +105,5 @@ func Transfer(ctx *context.APIContext, opts api.TransferRepoOption) {
|
|||
}
|
||||
|
||||
log.Trace("Repository transferred: %s -> %s", ctx.Repo.Repository.FullName(), newOwner.Name)
|
||||
ctx.JSON(http.StatusAccepted, newRepo.APIFormat(models.AccessModeAdmin))
|
||||
ctx.JSON(http.StatusAccepted, convert.ToRepo(newRepo, models.AccessModeAdmin))
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
@ -37,7 +38,7 @@ func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
|
|||
return
|
||||
}
|
||||
if ctx.IsSigned && ctx.User.IsAdmin || access >= models.AccessModeRead {
|
||||
apiRepos = append(apiRepos, repos[i].APIFormat(access))
|
||||
apiRepos = append(apiRepos, convert.ToRepo(repos[i], access))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,7 +126,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
}
|
||||
results[i] = repo.APIFormat(accessMode)
|
||||
results[i] = convert.ToRepo(repo, accessMode)
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(count), opts.ListOptions.PageSize)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
@ -28,7 +29,7 @@ func getStarredRepos(user *models.User, private bool, listOptions models.ListOpt
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repos[i] = starred.APIFormat(access)
|
||||
repos[i] = convert.ToRepo(starred, access)
|
||||
}
|
||||
return repos, nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
@ -27,7 +28,7 @@ func getWatchedRepos(user *models.User, private bool, listOptions models.ListOpt
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repos[i] = watched.APIFormat(access)
|
||||
repos[i] = convert.ToRepo(watched, access)
|
||||
}
|
||||
return repos, nil
|
||||
}
|
||||
|
|
|
@ -1073,7 +1073,7 @@ func TestWebhook(ctx *context.Context) {
|
|||
},
|
||||
},
|
||||
},
|
||||
Repo: ctx.Repo.Repository.APIFormat(models.AccessModeNone),
|
||||
Repo: convert.ToRepo(ctx.Repo.Repository, models.AccessModeNone),
|
||||
Pusher: apiUser,
|
||||
Sender: apiUser,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue