Skip to content

Commit

Permalink
Merge branch 'master' into git_simple_pr
Browse files Browse the repository at this point in the history
* master:
  Add support for ref parameter to get raw file API (go-gitea#14602)
  • Loading branch information
a1012112796 committed Feb 9, 2021
2 parents 7294bfa + b337c60 commit c1291fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 21 additions & 1 deletion routers/api/v1/repo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func GetRawFile(ctx *context.APIContext) {
// 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: success
Expand All @@ -54,7 +59,22 @@ func GetRawFile(ctx *context.APIContext) {
return
}

blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
commit := ctx.Repo.Commit

if ref := ctx.QueryTrim("ref"); len(ref) > 0 {
var err error
commit, err = ctx.Repo.GitRepo.GetCommit(ref)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetBlobByPath", err)
}
return
}
}

blob, err := commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound()
Expand Down
6 changes: 6 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7845,6 +7845,12 @@
"name": "filepath",
"in": "path",
"required": true
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
"name": "ref",
"in": "query"
}
],
"responses": {
Expand Down

0 comments on commit c1291fa

Please sign in to comment.