-
Notifications
You must be signed in to change notification settings - Fork 127
Description
I use the gogs api for fetching repo content:
https://github.com/gogs/gogs/blob/master/internal/route/api/v1/api.go#L274-L276
I realized that for all executable files (mostly bash scripts), I get the following as the file content:
{"message":"the entry is not a blob","url":"https://github.com/gogs/docs-api"}
Digging a little bit, I realized that the (t *Tree) Blob(subpath string, opts ...LsTreeOptions) (*Blob, error)
func only returns Blob() if the entry is of type Blob
:
// Blob returns the blob object by given subpath of the tree.
func (t *Tree) Blob(subpath string, opts ...LsTreeOptions) (*Blob, error) {
e, err := t.TreeEntry(subpath, opts...)
if err != nil {
return nil, err
}
if e.IsBlob() {
return e.Blob(), nil
}
return nil, ErrNotBlob
}
https://github.com/gogs/git-module/blob/master/tree_blob.go#L56
I think this is why the gogs
conents api returns error message:
switch {
case entry.IsBlob(), entry.IsExec():
content.Type = "file"
p, err := entry.Blob().Bytes()
if err != nil {
return nil, errors.Wrap(err, "get blob content")
}
content.Encoding = "base64"
content.Content = base64.StdEncoding.EncodeToString(p)
content.GitURL = fmt.Sprintf("%s/git/blobs/%s", repoURL, entry.ID().String())
....
https://github.com/gogs/gogs/blob/master/internal/route/api/v1/repo/contents.go#L87-L91
Can we make (t *Tree) Blob(subpath string, opts ...LsTreeOptions) (*Blob, error)
func return contents for EntryExec
and EntryBlob
. @unknwon is this acceptable, or do you think that I got this all wrong and the fix should be somewhere else?