2014-11-16 20:27:04 -05:00
|
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2018-11-28 06:26:14 -05:00
|
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2014-11-16 20:27:04 -05:00
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
2015-12-04 17:16:42 -05:00
|
|
|
|
package repo
|
2014-11-16 21:32:26 -05:00
|
|
|
|
|
|
|
|
|
import (
|
2022-06-04 08:17:53 -05:00
|
|
|
|
"bytes"
|
2019-04-17 11:06:35 -05:00
|
|
|
|
"encoding/base64"
|
2020-05-31 15:59:34 -05:00
|
|
|
|
"fmt"
|
2022-06-04 08:17:53 -05:00
|
|
|
|
"io"
|
2019-04-17 11:06:35 -05:00
|
|
|
|
"net/http"
|
2022-05-09 10:54:51 -05:00
|
|
|
|
"path"
|
2019-12-23 21:33:52 -05:00
|
|
|
|
"time"
|
2019-04-17 11:06:35 -05:00
|
|
|
|
|
2016-11-10 11:24:48 -05:00
|
|
|
|
"code.gitea.io/gitea/models"
|
2022-06-12 10:51:54 -05:00
|
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
2021-12-09 20:27:50 -05:00
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-09 14:57:58 -05:00
|
|
|
|
"code.gitea.io/gitea/models/unit"
|
2022-05-09 10:54:51 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/cache"
|
2016-11-10 11:24:48 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2019-03-27 04:33:00 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
2022-06-04 08:17:53 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/httpcache"
|
|
|
|
|
"code.gitea.io/gitea/modules/lfs"
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2022-05-09 10:54:51 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2022-06-04 08:17:53 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/storage"
|
2019-05-11 05:21:34 -05:00
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2021-01-26 10:36:53 -05:00
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-06-08 18:33:54 -05:00
|
|
|
|
"code.gitea.io/gitea/routers/common"
|
2021-06-23 16:12:38 -05:00
|
|
|
|
"code.gitea.io/gitea/routers/web/repo"
|
2021-11-24 02:56:24 -05:00
|
|
|
|
files_service "code.gitea.io/gitea/services/repository/files"
|
2014-11-16 21:32:26 -05:00
|
|
|
|
)
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
const giteaObjectTypeHeader = "X-Gitea-Object-Type"
|
|
|
|
|
|
2016-11-24 02:04:31 -05:00
|
|
|
|
// GetRawFile get a file by path on a repository
|
2016-03-13 17:49:16 -05:00
|
|
|
|
func GetRawFile(ctx *context.APIContext) {
|
2017-11-13 02:02:25 -05:00
|
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/raw/{filepath} repository repoGetRawFile
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Get a file from a repository
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
|
|
|
|
// description: filepath of the file to get
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
2021-02-08 19:15:47 -05:00
|
|
|
|
// - name: ref
|
|
|
|
|
// in: query
|
|
|
|
|
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
|
|
|
|
// type: string
|
|
|
|
|
// required: false
|
2017-11-13 02:02:25 -05:00
|
|
|
|
// responses:
|
2018-06-01 00:51:49 -05:00
|
|
|
|
// 200:
|
2022-04-28 09:57:56 -05:00
|
|
|
|
// description: Returns raw file content.
|
2019-12-20 12:07:12 -05:00
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
2019-01-17 19:01:04 -05:00
|
|
|
|
if ctx.Repo.Repository.IsEmpty {
|
2019-03-18 21:29:43 -05:00
|
|
|
|
ctx.NotFound()
|
2017-06-10 21:57:28 -05:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
blob, entry, lastModified := getBlobForEntry(ctx)
|
2022-05-09 10:54:51 -05:00
|
|
|
|
if ctx.Written() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
|
|
|
|
|
2022-05-09 10:54:51 -05:00
|
|
|
|
if err := common.ServeBlob(ctx.Context, blob, lastModified); err != nil {
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, "ServeBlob", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-04 08:17:53 -05:00
|
|
|
|
// GetRawFileOrLFS get a file by repo's path, redirecting to LFS if necessary.
|
|
|
|
|
func GetRawFileOrLFS(ctx *context.APIContext) {
|
|
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/media/{filepath} repository repoGetRawFileOrLFS
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Get a file or it's LFS object from a repository
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
|
|
|
|
// description: filepath of the file to get
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: ref
|
|
|
|
|
// in: query
|
|
|
|
|
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
|
|
|
|
// type: string
|
|
|
|
|
// required: false
|
|
|
|
|
// responses:
|
|
|
|
|
// 200:
|
|
|
|
|
// description: Returns raw file content.
|
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
|
|
|
|
if ctx.Repo.Repository.IsEmpty {
|
|
|
|
|
ctx.NotFound()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
blob, entry, lastModified := getBlobForEntry(ctx)
|
2022-06-04 08:17:53 -05:00
|
|
|
|
if ctx.Written() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
|
|
|
|
|
2022-06-04 08:17:53 -05:00
|
|
|
|
// LFS Pointer files are at most 1024 bytes - so any blob greater than 1024 bytes cannot be an LFS file
|
|
|
|
|
if blob.Size() > 1024 {
|
|
|
|
|
// First handle caching for the blob
|
|
|
|
|
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK not cached - serve!
|
|
|
|
|
if err := common.ServeBlob(ctx.Context, blob, lastModified); err != nil {
|
|
|
|
|
ctx.ServerError("ServeBlob", err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK, now the blob is known to have at most 1024 bytes we can simply read this in in one go (This saves reading it twice)
|
|
|
|
|
dataRc, err := blob.DataAsync()
|
|
|
|
|
if err != nil {
|
|
|
|
|
ctx.ServerError("DataAsync", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf, err := io.ReadAll(dataRc)
|
|
|
|
|
if err != nil {
|
|
|
|
|
_ = dataRc.Close()
|
|
|
|
|
ctx.ServerError("DataAsync", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := dataRc.Close(); err != nil {
|
|
|
|
|
log.Error("Error whilst closing blob %s reader in %-v. Error: %v", blob.ID, ctx.Context.Repo.Repository, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the blob represents a pointer
|
|
|
|
|
pointer, _ := lfs.ReadPointer(bytes.NewReader(buf))
|
|
|
|
|
|
|
|
|
|
// if its not a pointer just serve the data directly
|
|
|
|
|
if !pointer.IsValid() {
|
|
|
|
|
// First handle caching for the blob
|
|
|
|
|
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK not cached - serve!
|
|
|
|
|
if err := common.ServeData(ctx.Context, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf)); err != nil {
|
|
|
|
|
ctx.ServerError("ServeBlob", err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now check if there is a meta object for this pointer
|
2022-06-12 10:51:54 -05:00
|
|
|
|
meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid)
|
2022-06-04 08:17:53 -05:00
|
|
|
|
|
|
|
|
|
// If there isn't one just serve the data directly
|
2022-06-12 10:51:54 -05:00
|
|
|
|
if err == git_model.ErrLFSObjectNotExist {
|
2022-06-04 08:17:53 -05:00
|
|
|
|
// Handle caching for the blob SHA (not the LFS object OID)
|
|
|
|
|
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := common.ServeData(ctx.Context, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf)); err != nil {
|
|
|
|
|
ctx.ServerError("ServeBlob", err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
} else if err != nil {
|
|
|
|
|
ctx.ServerError("GetLFSMetaObjectByOid", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle caching for the LFS object OID
|
|
|
|
|
if httpcache.HandleGenericETagCache(ctx.Req, ctx.Resp, `"`+pointer.Oid+`"`) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if setting.LFS.ServeDirect {
|
|
|
|
|
// If we have a signed url (S3, object storage), redirect to this directly.
|
|
|
|
|
u, err := storage.LFS.URL(pointer.RelativePath(), blob.Name())
|
|
|
|
|
if u != nil && err == nil {
|
|
|
|
|
ctx.Redirect(u.String())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lfsDataRc, err := lfs.ReadMetaObject(meta.Pointer)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ctx.ServerError("ReadMetaObject", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer lfsDataRc.Close()
|
|
|
|
|
|
|
|
|
|
if err := common.ServeData(ctx.Context, ctx.Repo.TreePath, meta.Size, lfsDataRc); err != nil {
|
|
|
|
|
ctx.ServerError("ServeData", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEntry, lastModified time.Time) {
|
2022-05-09 10:54:51 -05:00
|
|
|
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
2014-11-16 21:32:26 -05:00
|
|
|
|
if err != nil {
|
2015-12-09 20:46:05 -05:00
|
|
|
|
if git.IsErrNotExist(err) {
|
2019-03-18 21:29:43 -05:00
|
|
|
|
ctx.NotFound()
|
2014-11-16 21:32:26 -05:00
|
|
|
|
} else {
|
2022-05-09 10:54:51 -05:00
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetTreeEntryByPath", err)
|
2014-11-16 21:32:26 -05:00
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-05-09 10:54:51 -05:00
|
|
|
|
|
|
|
|
|
if entry.IsDir() || entry.IsSubModule() {
|
|
|
|
|
ctx.NotFound("getBlobForEntry", nil)
|
|
|
|
|
return
|
2014-11-16 21:32:26 -05:00
|
|
|
|
}
|
2022-05-09 10:54:51 -05:00
|
|
|
|
|
|
|
|
|
var c *git.LastCommitCache
|
|
|
|
|
if setting.CacheService.LastCommit.Enabled && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount {
|
|
|
|
|
c = git.NewLastCommitCache(ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, setting.LastCommitCacheTTLSeconds, cache.GetCache())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info, _, err := git.Entries([]*git.TreeEntry{entry}).GetCommitsInfo(ctx, ctx.Repo.Commit, path.Dir("/" + ctx.Repo.TreePath)[1:], c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetCommitsInfo", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(info) == 1 {
|
|
|
|
|
// Not Modified
|
|
|
|
|
lastModified = info[0].Commit.Committer.When
|
|
|
|
|
}
|
|
|
|
|
blob = entry.Blob()
|
|
|
|
|
|
2022-07-21 14:18:41 -05:00
|
|
|
|
return blob, entry, lastModified
|
2014-11-16 21:32:26 -05:00
|
|
|
|
}
|
2015-09-02 08:54:35 -05:00
|
|
|
|
|
2016-11-24 02:04:31 -05:00
|
|
|
|
// GetArchive get archive of a repository
|
2016-03-13 17:49:16 -05:00
|
|
|
|
func GetArchive(ctx *context.APIContext) {
|
2018-06-12 09:59:22 -05:00
|
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/archive/{archive} repository repoGetArchive
|
2017-11-13 02:02:25 -05:00
|
|
|
|
// ---
|
|
|
|
|
// summary: Get an archive of a repository
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: archive
|
|
|
|
|
// in: path
|
2020-09-06 11:23:47 -05:00
|
|
|
|
// description: the git reference for download with attached archive format (e.g. master.zip)
|
2017-11-13 02:02:25 -05:00
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// responses:
|
2018-06-01 00:51:49 -05:00
|
|
|
|
// 200:
|
|
|
|
|
// description: success
|
2019-12-20 12:07:12 -05:00
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
|
repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
2021-09-17 19:54:15 -05:00
|
|
|
|
if ctx.Repo.GitRepo == nil {
|
2022-03-29 14:13:41 -05:00
|
|
|
|
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
2021-09-17 19:54:15 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ctx.Repo.GitRepo = gitRepo
|
|
|
|
|
defer gitRepo.Close()
|
2015-09-02 08:54:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 16:12:38 -05:00
|
|
|
|
repo.Download(ctx.Context)
|
2015-09-02 08:54:35 -05:00
|
|
|
|
}
|
2016-08-30 18:18:40 -05:00
|
|
|
|
|
2016-11-24 02:04:31 -05:00
|
|
|
|
// GetEditorconfig get editor config of a repository
|
2016-08-30 18:18:40 -05:00
|
|
|
|
func GetEditorconfig(ctx *context.APIContext) {
|
2017-11-13 02:02:25 -05:00
|
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/editorconfig/{filepath} repository repoGetEditorConfig
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Get the EditorConfig definitions of a file in a repository
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
|
|
|
|
// description: filepath of file to get
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
2022-04-21 10:17:57 -05:00
|
|
|
|
// - name: ref
|
|
|
|
|
// in: query
|
|
|
|
|
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
|
|
|
|
// type: string
|
|
|
|
|
// required: false
|
2017-11-13 02:02:25 -05:00
|
|
|
|
// responses:
|
2018-06-01 00:51:49 -05:00
|
|
|
|
// 200:
|
|
|
|
|
// description: success
|
2019-12-20 12:07:12 -05:00
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
2022-04-21 10:17:57 -05:00
|
|
|
|
ec, err := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
|
2016-08-30 18:18:40 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
if git.IsErrNotExist(err) {
|
2019-03-18 21:29:43 -05:00
|
|
|
|
ctx.NotFound(err)
|
2016-08-30 18:18:40 -05:00
|
|
|
|
} else {
|
2019-04-17 11:06:35 -05:00
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetEditorconfig", err)
|
2016-08-30 18:18:40 -05:00
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileName := ctx.Params("filename")
|
2019-10-16 19:15:02 -05:00
|
|
|
|
def, err := ec.GetDefinitionForFilename(fileName)
|
2016-08-30 18:18:40 -05:00
|
|
|
|
if def == nil {
|
2019-03-18 21:29:43 -05:00
|
|
|
|
ctx.NotFound(err)
|
2016-08-30 18:18:40 -05:00
|
|
|
|
return
|
|
|
|
|
}
|
2019-04-17 11:06:35 -05:00
|
|
|
|
ctx.JSON(http.StatusOK, def)
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 11:20:22 -05:00
|
|
|
|
// canWriteFiles returns true if repository is editable and user has proper access level.
|
2022-04-28 10:45:33 -05:00
|
|
|
|
func canWriteFiles(ctx *context.APIContext, branch string) bool {
|
2022-05-11 05:09:36 -05:00
|
|
|
|
return ctx.Repo.CanWriteToBranch(ctx.Doer, branch) &&
|
2022-04-28 10:45:33 -05:00
|
|
|
|
!ctx.Repo.Repository.IsMirror &&
|
|
|
|
|
!ctx.Repo.Repository.IsArchived
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 11:20:22 -05:00
|
|
|
|
// canReadFiles returns true if repository is readable and user has proper access level.
|
|
|
|
|
func canReadFiles(r *context.Repository) bool {
|
2021-11-09 14:57:58 -05:00
|
|
|
|
return r.Permission.CanRead(unit.TypeCode)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateFile handles API call for creating a file
|
2021-01-26 10:36:53 -05:00
|
|
|
|
func CreateFile(ctx *context.APIContext) {
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// swagger:operation POST /repos/{owner}/{repo}/contents/{filepath} repository repoCreateFile
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Create a file in a repository
|
|
|
|
|
// consumes:
|
|
|
|
|
// - application/json
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
|
|
|
|
// description: path of the file to create
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: body
|
|
|
|
|
// in: body
|
2019-05-30 12:57:55 -05:00
|
|
|
|
// required: true
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// schema:
|
|
|
|
|
// "$ref": "#/definitions/CreateFileOptions"
|
|
|
|
|
// responses:
|
|
|
|
|
// "201":
|
|
|
|
|
// "$ref": "#/responses/FileResponse"
|
2020-05-31 15:59:34 -05:00
|
|
|
|
// "403":
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
// "422":
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
|
2021-01-26 10:36:53 -05:00
|
|
|
|
apiOpts := web.GetForm(ctx).(*api.CreateFileOptions)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
|
2020-04-20 11:47:05 -05:00
|
|
|
|
if apiOpts.BranchName == "" {
|
|
|
|
|
apiOpts.BranchName = ctx.Repo.Repository.DefaultBranch
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 02:56:24 -05:00
|
|
|
|
opts := &files_service.UpdateRepoFileOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Content: apiOpts.Content,
|
|
|
|
|
IsNewFile: true,
|
|
|
|
|
Message: apiOpts.Message,
|
|
|
|
|
TreePath: ctx.Params("*"),
|
|
|
|
|
OldBranch: apiOpts.BranchName,
|
|
|
|
|
NewBranch: apiOpts.NewBranchName,
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Committer: &files_service.IdentityOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Name: apiOpts.Committer.Name,
|
|
|
|
|
Email: apiOpts.Committer.Email,
|
|
|
|
|
},
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Author: &files_service.IdentityOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Name: apiOpts.Author.Name,
|
|
|
|
|
Email: apiOpts.Author.Email,
|
|
|
|
|
},
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Dates: &files_service.CommitDateOptions{
|
2019-12-23 21:33:52 -05:00
|
|
|
|
Author: apiOpts.Dates.Author,
|
|
|
|
|
Committer: apiOpts.Dates.Committer,
|
|
|
|
|
},
|
2021-01-29 03:57:45 -05:00
|
|
|
|
Signoff: apiOpts.Signoff,
|
2019-12-23 21:33:52 -05:00
|
|
|
|
}
|
|
|
|
|
if opts.Dates.Author.IsZero() {
|
|
|
|
|
opts.Dates.Author = time.Now()
|
|
|
|
|
}
|
|
|
|
|
if opts.Dates.Committer.IsZero() {
|
|
|
|
|
opts.Dates.Committer = time.Now()
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
2019-06-29 10:19:24 -05:00
|
|
|
|
|
|
|
|
|
if opts.Message == "" {
|
|
|
|
|
opts.Message = ctx.Tr("repo.editor.add", opts.TreePath)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 11:06:35 -05:00
|
|
|
|
if fileResponse, err := createOrUpdateFile(ctx, opts); err != nil {
|
2020-05-31 15:59:34 -05:00
|
|
|
|
handleCreateOrUpdateFileError(ctx, err)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
} else {
|
|
|
|
|
ctx.JSON(http.StatusCreated, fileResponse)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateFile handles API call for updating a file
|
2021-01-26 10:36:53 -05:00
|
|
|
|
func UpdateFile(ctx *context.APIContext) {
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// swagger:operation PUT /repos/{owner}/{repo}/contents/{filepath} repository repoUpdateFile
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Update a file in a repository
|
|
|
|
|
// consumes:
|
|
|
|
|
// - application/json
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
|
|
|
|
// description: path of the file to update
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: body
|
|
|
|
|
// in: body
|
2019-05-30 12:57:55 -05:00
|
|
|
|
// required: true
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// schema:
|
|
|
|
|
// "$ref": "#/definitions/UpdateFileOptions"
|
|
|
|
|
// responses:
|
|
|
|
|
// "200":
|
|
|
|
|
// "$ref": "#/responses/FileResponse"
|
2020-05-31 15:59:34 -05:00
|
|
|
|
// "403":
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
// "422":
|
|
|
|
|
// "$ref": "#/responses/error"
|
2021-01-26 10:36:53 -05:00
|
|
|
|
apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions)
|
2020-05-31 15:59:34 -05:00
|
|
|
|
if ctx.Repo.Repository.IsEmpty {
|
|
|
|
|
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
|
|
|
|
|
}
|
2019-04-17 11:06:35 -05:00
|
|
|
|
|
2020-04-20 11:47:05 -05:00
|
|
|
|
if apiOpts.BranchName == "" {
|
|
|
|
|
apiOpts.BranchName = ctx.Repo.Repository.DefaultBranch
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 02:56:24 -05:00
|
|
|
|
opts := &files_service.UpdateRepoFileOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Content: apiOpts.Content,
|
|
|
|
|
SHA: apiOpts.SHA,
|
|
|
|
|
IsNewFile: false,
|
|
|
|
|
Message: apiOpts.Message,
|
|
|
|
|
FromTreePath: apiOpts.FromPath,
|
|
|
|
|
TreePath: ctx.Params("*"),
|
|
|
|
|
OldBranch: apiOpts.BranchName,
|
|
|
|
|
NewBranch: apiOpts.NewBranchName,
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Committer: &files_service.IdentityOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Name: apiOpts.Committer.Name,
|
|
|
|
|
Email: apiOpts.Committer.Email,
|
|
|
|
|
},
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Author: &files_service.IdentityOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Name: apiOpts.Author.Name,
|
|
|
|
|
Email: apiOpts.Author.Email,
|
|
|
|
|
},
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Dates: &files_service.CommitDateOptions{
|
2019-12-23 21:33:52 -05:00
|
|
|
|
Author: apiOpts.Dates.Author,
|
|
|
|
|
Committer: apiOpts.Dates.Committer,
|
|
|
|
|
},
|
2021-01-29 03:57:45 -05:00
|
|
|
|
Signoff: apiOpts.Signoff,
|
2019-12-23 21:33:52 -05:00
|
|
|
|
}
|
|
|
|
|
if opts.Dates.Author.IsZero() {
|
|
|
|
|
opts.Dates.Author = time.Now()
|
|
|
|
|
}
|
|
|
|
|
if opts.Dates.Committer.IsZero() {
|
|
|
|
|
opts.Dates.Committer = time.Now()
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 10:19:24 -05:00
|
|
|
|
if opts.Message == "" {
|
|
|
|
|
opts.Message = ctx.Tr("repo.editor.update", opts.TreePath)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 11:06:35 -05:00
|
|
|
|
if fileResponse, err := createOrUpdateFile(ctx, opts); err != nil {
|
2020-05-31 15:59:34 -05:00
|
|
|
|
handleCreateOrUpdateFileError(ctx, err)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
} else {
|
|
|
|
|
ctx.JSON(http.StatusOK, fileResponse)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 15:59:34 -05:00
|
|
|
|
func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) {
|
|
|
|
|
if models.IsErrUserCannotCommit(err) || models.IsErrFilePathProtected(err) {
|
|
|
|
|
ctx.Error(http.StatusForbidden, "Access", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if models.IsErrBranchAlreadyExists(err) || models.IsErrFilenameInvalid(err) || models.IsErrSHADoesNotMatch(err) ||
|
|
|
|
|
models.IsErrFilePathInvalid(err) || models.IsErrRepoFileAlreadyExists(err) {
|
|
|
|
|
ctx.Error(http.StatusUnprocessableEntity, "Invalid", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-06-07 12:30:58 -05:00
|
|
|
|
if models.IsErrBranchDoesNotExist(err) || git.IsErrBranchNotExist(err) {
|
|
|
|
|
ctx.Error(http.StatusNotFound, "BranchDoesNotExist", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-05-31 15:59:34 -05:00
|
|
|
|
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, "UpdateFile", err)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// Called from both CreateFile or UpdateFile to handle both
|
2021-11-24 02:56:24 -05:00
|
|
|
|
func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoFileOptions) (*api.FileResponse, error) {
|
2022-04-28 10:45:33 -05:00
|
|
|
|
if !canWriteFiles(ctx, opts.OldBranch) {
|
2022-06-13 04:37:59 -05:00
|
|
|
|
return nil, repo_model.ErrUserDoesNotHaveAccessToRepo{
|
2022-03-22 02:03:22 -05:00
|
|
|
|
UserID: ctx.Doer.ID,
|
2019-04-17 11:06:35 -05:00
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content, err := base64.StdEncoding.DecodeString(opts.Content)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
opts.Content = string(content)
|
|
|
|
|
|
2022-03-22 02:03:22 -05:00
|
|
|
|
return files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.Doer, opts)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 04:32:37 -05:00
|
|
|
|
// DeleteFile Delete a file in a repository
|
2021-01-26 10:36:53 -05:00
|
|
|
|
func DeleteFile(ctx *context.APIContext) {
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// swagger:operation DELETE /repos/{owner}/{repo}/contents/{filepath} repository repoDeleteFile
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Delete a file in a repository
|
|
|
|
|
// consumes:
|
|
|
|
|
// - application/json
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
|
|
|
|
// description: path of the file to delete
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: body
|
|
|
|
|
// in: body
|
2019-05-30 12:57:55 -05:00
|
|
|
|
// required: true
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// schema:
|
|
|
|
|
// "$ref": "#/definitions/DeleteFileOptions"
|
|
|
|
|
// responses:
|
|
|
|
|
// "200":
|
|
|
|
|
// "$ref": "#/responses/FileDeleteResponse"
|
2020-04-15 00:18:51 -05:00
|
|
|
|
// "400":
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
// "403":
|
|
|
|
|
// "$ref": "#/responses/error"
|
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/error"
|
2019-12-20 12:07:12 -05:00
|
|
|
|
|
2021-01-26 10:36:53 -05:00
|
|
|
|
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
2022-04-28 10:45:33 -05:00
|
|
|
|
if !canWriteFiles(ctx, apiOpts.BranchName) {
|
2022-06-13 04:37:59 -05:00
|
|
|
|
ctx.Error(http.StatusForbidden, "DeleteFile", repo_model.ErrUserDoesNotHaveAccessToRepo{
|
2022-03-22 02:03:22 -05:00
|
|
|
|
UserID: ctx.Doer.ID,
|
2019-04-17 11:06:35 -05:00
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 11:47:05 -05:00
|
|
|
|
if apiOpts.BranchName == "" {
|
|
|
|
|
apiOpts.BranchName = ctx.Repo.Repository.DefaultBranch
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 02:56:24 -05:00
|
|
|
|
opts := &files_service.DeleteRepoFileOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Message: apiOpts.Message,
|
|
|
|
|
OldBranch: apiOpts.BranchName,
|
|
|
|
|
NewBranch: apiOpts.NewBranchName,
|
|
|
|
|
SHA: apiOpts.SHA,
|
|
|
|
|
TreePath: ctx.Params("*"),
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Committer: &files_service.IdentityOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Name: apiOpts.Committer.Name,
|
|
|
|
|
Email: apiOpts.Committer.Email,
|
|
|
|
|
},
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Author: &files_service.IdentityOptions{
|
2019-04-17 11:06:35 -05:00
|
|
|
|
Name: apiOpts.Author.Name,
|
|
|
|
|
Email: apiOpts.Author.Email,
|
|
|
|
|
},
|
2021-11-24 02:56:24 -05:00
|
|
|
|
Dates: &files_service.CommitDateOptions{
|
2019-12-23 21:33:52 -05:00
|
|
|
|
Author: apiOpts.Dates.Author,
|
|
|
|
|
Committer: apiOpts.Dates.Committer,
|
|
|
|
|
},
|
2021-01-29 03:57:45 -05:00
|
|
|
|
Signoff: apiOpts.Signoff,
|
2019-12-23 21:33:52 -05:00
|
|
|
|
}
|
|
|
|
|
if opts.Dates.Author.IsZero() {
|
|
|
|
|
opts.Dates.Author = time.Now()
|
|
|
|
|
}
|
|
|
|
|
if opts.Dates.Committer.IsZero() {
|
|
|
|
|
opts.Dates.Committer = time.Now()
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 10:19:24 -05:00
|
|
|
|
if opts.Message == "" {
|
|
|
|
|
opts.Message = ctx.Tr("repo.editor.delete", opts.TreePath)
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-22 02:03:22 -05:00
|
|
|
|
if fileResponse, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.Doer, opts); err != nil {
|
2020-04-15 00:18:51 -05:00
|
|
|
|
if git.IsErrBranchNotExist(err) || models.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
|
|
|
|
|
ctx.Error(http.StatusNotFound, "DeleteFile", err)
|
|
|
|
|
return
|
|
|
|
|
} else if models.IsErrBranchAlreadyExists(err) ||
|
|
|
|
|
models.IsErrFilenameInvalid(err) ||
|
|
|
|
|
models.IsErrSHADoesNotMatch(err) ||
|
|
|
|
|
models.IsErrCommitIDDoesNotMatch(err) ||
|
|
|
|
|
models.IsErrSHAOrCommitIDNotProvided(err) {
|
|
|
|
|
ctx.Error(http.StatusBadRequest, "DeleteFile", err)
|
|
|
|
|
return
|
|
|
|
|
} else if models.IsErrUserCannotCommit(err) {
|
|
|
|
|
ctx.Error(http.StatusForbidden, "DeleteFile", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-04-17 11:06:35 -05:00
|
|
|
|
ctx.Error(http.StatusInternalServerError, "DeleteFile", err)
|
|
|
|
|
} else {
|
2020-04-15 00:18:51 -05:00
|
|
|
|
ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 15:51:10 -05:00
|
|
|
|
// GetContents Get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
|
|
|
|
|
func GetContents(ctx *context.APIContext) {
|
|
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/contents/{filepath} repository repoGetContents
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// ---
|
2019-06-29 15:51:10 -05:00
|
|
|
|
// summary: Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: filepath
|
|
|
|
|
// in: path
|
2019-06-29 15:51:10 -05:00
|
|
|
|
// description: path of the dir, file, symlink or submodule in the repo
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: ref
|
|
|
|
|
// in: query
|
|
|
|
|
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
|
|
|
|
// type: string
|
2019-06-29 15:51:10 -05:00
|
|
|
|
// required: false
|
2019-04-17 11:06:35 -05:00
|
|
|
|
// responses:
|
|
|
|
|
// "200":
|
2019-06-29 15:51:10 -05:00
|
|
|
|
// "$ref": "#/responses/ContentsResponse"
|
2020-04-15 00:18:51 -05:00
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
2019-04-17 11:06:35 -05:00
|
|
|
|
|
2020-04-24 11:20:22 -05:00
|
|
|
|
if !canReadFiles(ctx.Repo) {
|
2022-06-13 04:37:59 -05:00
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", repo_model.ErrUserDoesNotHaveAccessToRepo{
|
2022-03-22 02:03:22 -05:00
|
|
|
|
UserID: ctx.Doer.ID,
|
2019-04-17 11:06:35 -05:00
|
|
|
|
RepoName: ctx.Repo.Repository.LowerName,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
treePath := ctx.Params("*")
|
2021-07-28 20:42:15 -05:00
|
|
|
|
ref := ctx.FormTrim("ref")
|
2019-04-17 11:06:35 -05:00
|
|
|
|
|
2022-01-19 18:26:57 -05:00
|
|
|
|
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
|
2020-04-15 00:18:51 -05:00
|
|
|
|
if git.IsErrNotExist(err) {
|
|
|
|
|
ctx.NotFound("GetContentsOrList", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-06-29 15:51:10 -05:00
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
} else {
|
2019-06-29 15:51:10 -05:00
|
|
|
|
ctx.JSON(http.StatusOK, fileList)
|
2019-04-17 11:06:35 -05:00
|
|
|
|
}
|
2016-08-30 18:18:40 -05:00
|
|
|
|
}
|
2019-06-29 15:51:10 -05:00
|
|
|
|
|
|
|
|
|
// GetContentsList Get the metadata of all the entries of the root dir
|
|
|
|
|
func GetContentsList(ctx *context.APIContext) {
|
|
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/contents repository repoGetContentsList
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Gets the metadata of all the entries of the root dir
|
|
|
|
|
// produces:
|
|
|
|
|
// - application/json
|
|
|
|
|
// parameters:
|
|
|
|
|
// - name: owner
|
|
|
|
|
// in: path
|
|
|
|
|
// description: owner of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: repo
|
|
|
|
|
// in: path
|
|
|
|
|
// description: name of the repo
|
|
|
|
|
// type: string
|
|
|
|
|
// required: true
|
|
|
|
|
// - name: ref
|
|
|
|
|
// in: query
|
|
|
|
|
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
|
|
|
|
// type: string
|
|
|
|
|
// required: false
|
|
|
|
|
// responses:
|
|
|
|
|
// "200":
|
|
|
|
|
// "$ref": "#/responses/ContentsListResponse"
|
2020-04-15 00:18:51 -05:00
|
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
2019-06-29 15:51:10 -05:00
|
|
|
|
|
|
|
|
|
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface
|
|
|
|
|
GetContents(ctx)
|
|
|
|
|
}
|