Skip to content

Commit 546ae82

Browse files
committed
Add support for ref parameter to get raw file API
Fix go-gitea#14597 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 5f248d0 commit 546ae82

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

routers/api/v1/repo/file.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func GetRawFile(ctx *context.APIContext) {
4343
// description: filepath of the file to get
4444
// type: string
4545
// required: true
46+
// - name: ref
47+
// in: query
48+
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
49+
// type: string
50+
// required: false
4651
// responses:
4752
// 200:
4853
// description: success
@@ -54,7 +59,22 @@ func GetRawFile(ctx *context.APIContext) {
5459
return
5560
}
5661

57-
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
62+
commit := ctx.Repo.Commit
63+
64+
if ref := ctx.QueryTrim("ref"); len(ref) > 0 {
65+
var err error
66+
commit, err = ctx.Repo.GitRepo.GetCommit(ref)
67+
if err != nil {
68+
if git.IsErrNotExist(err) {
69+
ctx.NotFound()
70+
} else {
71+
ctx.Error(http.StatusInternalServerError, "GetBlobByPath", err)
72+
}
73+
return
74+
}
75+
}
76+
77+
blob, err := commit.GetBlobByPath(ctx.Repo.TreePath)
5878
if err != nil {
5979
if git.IsErrNotExist(err) {
6080
ctx.NotFound()

templates/swagger/v1_json.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -7845,6 +7845,12 @@
78457845
"name": "filepath",
78467846
"in": "path",
78477847
"required": true
7848+
},
7849+
{
7850+
"type": "string",
7851+
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
7852+
"name": "ref",
7853+
"in": "query"
78487854
}
78497855
],
78507856
"responses": {

0 commit comments

Comments
 (0)