diff options
author | Richard Mahn <richmahn@users.noreply.github.com> | 2019-06-29 16:51:10 -0400 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-06-29 16:51:10 -0400 |
commit | cd96dee9822c8b744526ba862fd8b5ec0e2c30ff (patch) | |
tree | d7bbf2f2b7adf80b17f3ab3971ae49bae7b010c4 /modules | |
parent | 738285a4aac5df2e60f4038aa79be3e9fe921bdb (diff) | |
download | gitea-cd96dee9822c8b744526ba862fd8b5ec0e2c30ff.tar.gz gitea-cd96dee9822c8b744526ba862fd8b5ec0e2c30ff.zip |
Fixes #7292 - API File Contents bug (#7301)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/blob.go | 13 | ||||
-rw-r--r-- | modules/git/repo_object.go | 17 | ||||
-rw-r--r-- | modules/repofiles/content.go | 189 | ||||
-rw-r--r-- | modules/repofiles/content_test.go | 154 | ||||
-rw-r--r-- | modules/repofiles/file.go | 4 | ||||
-rw-r--r-- | modules/repofiles/file_test.go | 35 | ||||
-rw-r--r-- | modules/structs/repo_file.go | 41 |
7 files changed, 372 insertions, 81 deletions
diff --git a/modules/git/blob.go b/modules/git/blob.go index 73ac89dfdf..68147673a3 100644 --- a/modules/git/blob.go +++ b/modules/git/blob.go @@ -37,6 +37,19 @@ func (b *Blob) Name() string { return b.name } +// GetBlobContent Gets the content of the blob as raw text +func (b *Blob) GetBlobContent() (string, error) { + dataRc, err := b.DataAsync() + if err != nil { + return "", err + } + defer dataRc.Close() + buf := make([]byte, 1024) + n, _ := dataRc.Read(buf) + buf = buf[:n] + return string(buf), nil +} + // GetBlobContentBase64 Reads the content of the blob with a base64 encode and returns the encoded string func (b *Blob) GetBlobContentBase64() (string, error) { dataRc, err := b.DataAsync() diff --git a/modules/git/repo_object.go b/modules/git/repo_object.go index 67060e30b0..d4d638a743 100644 --- a/modules/git/repo_object.go +++ b/modules/git/repo_object.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -22,6 +23,8 @@ const ( ObjectBlob ObjectType = "blob" // ObjectTag tag object type ObjectTag ObjectType = "tag" + // ObjectBranch branch object type + ObjectBranch ObjectType = "branch" ) // HashObject takes a reader and returns SHA1 hash for that reader @@ -44,3 +47,17 @@ func (repo *Repository) hashObject(reader io.Reader) (string, error) { } return strings.TrimSpace(stdout.String()), nil } + +// GetRefType gets the type of the ref based on the string +func (repo *Repository) GetRefType(ref string) ObjectType { + if repo.IsTagExist(ref) { + return ObjectTag + } else if repo.IsBranchExist(ref) { + return ObjectBranch + } else if repo.IsCommitExist(ref) { + return ObjectCommit + } else if _, err := repo.GetBlob(ref); err == nil { + return ObjectBlob + } + return ObjectType("invalid") +} diff --git a/modules/repofiles/content.go b/modules/repofiles/content.go index 3098087dc6..9637658e78 100644 --- a/modules/repofiles/content.go +++ b/modules/repofiles/content.go @@ -5,26 +5,52 @@ package repofiles import ( + "fmt" "net/url" + "path" + "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" ) -// GetFileContents gets the meta data on a file's contents -func GetFileContents(repo *models.Repository, treePath, ref string) (*api.FileContentResponse, error) { +// ContentType repo content type +type ContentType string + +// The string representations of different content types +const ( + // ContentTypeRegular regular content type (file) + ContentTypeRegular ContentType = "file" + // ContentTypeDir dir content type (dir) + ContentTypeDir ContentType = "dir" + // ContentLink link content type (symlink) + ContentTypeLink ContentType = "symlink" + // ContentTag submodule content type (submodule) + ContentTypeSubmodule ContentType = "submodule" +) + +// String gets the string of ContentType +func (ct *ContentType) String() string { + return string(*ct) +} + +// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree +// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag +func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) { if ref == "" { ref = repo.DefaultBranch } + origRef := ref // Check that the path given in opts.treePath is valid (not a git path) - treePath = CleanUploadFileName(treePath) - if treePath == "" { + cleanTreePath := CleanUploadFileName(treePath) + if cleanTreePath == "" && treePath != "" { return nil, models.ErrFilenameInvalid{ Path: treePath, } } + treePath = cleanTreePath gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { @@ -42,32 +68,145 @@ func GetFileContents(repo *models.Repository, treePath, ref string) (*api.FileCo return nil, err } - urlRef := ref - if _, err := gitRepo.GetBranchCommit(ref); err == nil { - urlRef = "branch/" + ref + if entry.Type() != "tree" { + return GetContents(repo, treePath, origRef, false) + } + + // We are in a directory, so we return a list of FileContentResponse objects + var fileList []*api.ContentsResponse + + gitTree, err := commit.SubTree(treePath) + if err != nil { + return nil, err + } + entries, err := gitTree.ListEntries() + if err != nil { + return nil, err + } + for _, e := range entries { + subTreePath := path.Join(treePath, e.Name()) + fileContentResponse, err := GetContents(repo, subTreePath, origRef, true) + if err != nil { + return nil, err + } + fileList = append(fileList, fileContentResponse) + } + return fileList, nil +} + +// GetContents gets the meta data on a file's contents. Ref can be a branch, commit or tag +func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) { + if ref == "" { + ref = repo.DefaultBranch } + origRef := ref - selfURL, _ := url.Parse(repo.APIURL() + "/contents/" + treePath) - gitURL, _ := url.Parse(repo.APIURL() + "/git/blobs/" + entry.ID.String()) - downloadURL, _ := url.Parse(repo.HTMLURL() + "/raw/" + urlRef + "/" + treePath) - htmlURL, _ := url.Parse(repo.HTMLURL() + "/blob/" + ref + "/" + treePath) + // Check that the path given in opts.treePath is valid (not a git path) + cleanTreePath := CleanUploadFileName(treePath) + if cleanTreePath == "" && treePath != "" { + return nil, models.ErrFilenameInvalid{ + Path: treePath, + } + } + treePath = cleanTreePath + + gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + return nil, err + } - fileContent := &api.FileContentResponse{ - Name: entry.Name(), - Path: treePath, - SHA: entry.ID.String(), - Size: entry.Size(), - URL: selfURL.String(), - HTMLURL: htmlURL.String(), - GitURL: gitURL.String(), - DownloadURL: downloadURL.String(), - Type: entry.Type(), + // Get the commit object for the ref + commit, err := gitRepo.GetCommit(ref) + if err != nil { + return nil, err + } + commitID := commit.ID.String() + if len(ref) >= 4 && strings.HasPrefix(commitID, ref) { + ref = commit.ID.String() + } + + entry, err := commit.GetTreeEntryByPath(treePath) + if err != nil { + return nil, err + } + + refType := gitRepo.GetRefType(ref) + if refType == "invalid" { + return nil, fmt.Errorf("no commit found for the ref [ref: %s]", ref) + } + + selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", repo.APIURL(), treePath, origRef)) + if err != nil { + return nil, err + } + selfURLString := selfURL.String() + + // All content types have these fields in populated + contentsResponse := &api.ContentsResponse{ + Name: entry.Name(), + Path: treePath, + SHA: entry.ID.String(), + Size: entry.Size(), + URL: &selfURLString, Links: &api.FileLinksResponse{ - Self: selfURL.String(), - GitURL: gitURL.String(), - HTMLURL: htmlURL.String(), + Self: &selfURLString, }, } - return fileContent, nil + // Now populate the rest of the ContentsResponse based on entry type + if entry.IsRegular() { + contentsResponse.Type = string(ContentTypeRegular) + if blobResponse, err := GetBlobBySHA(repo, entry.ID.String()); err != nil { + return nil, err + } else if !forList { + // We don't show the content if we are getting a list of FileContentResponses + contentsResponse.Encoding = &blobResponse.Encoding + contentsResponse.Content = &blobResponse.Content + } + } else if entry.IsDir() { + contentsResponse.Type = string(ContentTypeDir) + } else if entry.IsLink() { + contentsResponse.Type = string(ContentTypeLink) + // The target of a symlink file is the content of the file + targetFromContent, err := entry.Blob().GetBlobContent() + if err != nil { + return nil, err + } + contentsResponse.Target = &targetFromContent + } else if entry.IsSubModule() { + contentsResponse.Type = string(ContentTypeSubmodule) + submodule, err := commit.GetSubModule(treePath) + if err != nil { + return nil, err + } + contentsResponse.SubmoduleGitURL = &submodule.URL + } + // Handle links + if entry.IsRegular() || entry.IsLink() { + downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)) + if err != nil { + return nil, err + } + downloadURLString := downloadURL.String() + contentsResponse.DownloadURL = &downloadURLString + } + if !entry.IsSubModule() { + htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)) + if err != nil { + return nil, err + } + htmlURLString := htmlURL.String() + contentsResponse.HTMLURL = &htmlURLString + contentsResponse.Links.HTMLURL = &htmlURLString + + gitURL, err := url.Parse(fmt.Sprintf("%s/git/blobs/%s", repo.APIURL(), entry.ID.String())) + if err != nil { + return nil, err + } + gitURLString := gitURL.String() + contentsResponse.GitURL = &gitURLString + contentsResponse.Links.GitURL = &gitURLString + } + + return contentsResponse, nil } diff --git a/modules/repofiles/content_test.go b/modules/repofiles/content_test.go index ce3f5f3678..ef6c5eafc2 100644 --- a/modules/repofiles/content_test.go +++ b/modules/repofiles/content_test.go @@ -9,7 +9,7 @@ import ( "testing" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/structs" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/test" "github.com/stretchr/testify/assert" @@ -19,7 +19,36 @@ func TestMain(m *testing.M) { models.MainTest(m, filepath.Join("..", "..")) } -func TestGetFileContents(t *testing.T) { +func getExpectedReadmeContentsResponse() *api.ContentsResponse { + treePath := "README.md" + sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f" + encoding := "base64" + content := "IyByZXBvMQoKRGVzY3JpcHRpb24gZm9yIHJlcG8x" + selfURL := "https://try.gitea.io/api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master" + htmlURL := "https://try.gitea.io/user2/repo1/src/branch/master/" + treePath + gitURL := "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/" + sha + downloadURL := "https://try.gitea.io/user2/repo1/raw/branch/master/" + treePath + return &api.ContentsResponse{ + Name: treePath, + Path: treePath, + SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f", + Type: "file", + Size: 30, + Encoding: &encoding, + Content: &content, + URL: &selfURL, + HTMLURL: &htmlURL, + GitURL: &gitURL, + DownloadURL: &downloadURL, + Links: &api.FileLinksResponse{ + Self: &selfURL, + GitURL: &gitURL, + HTMLURL: &htmlURL, + }, + } +} + +func TestGetContents(t *testing.T) { models.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") @@ -30,37 +59,110 @@ func TestGetFileContents(t *testing.T) { treePath := "README.md" ref := ctx.Repo.Repository.DefaultBranch - expectedFileContentResponse := &structs.FileContentResponse{ - Name: treePath, - Path: treePath, - SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f", - Size: 30, - URL: "https://try.gitea.io/api/v1/repos/user2/repo1/contents/README.md", - HTMLURL: "https://try.gitea.io/user2/repo1/blob/master/README.md", - GitURL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/4b4851ad51df6a7d9f25c979345979eaeb5b349f", - DownloadURL: "https://try.gitea.io/user2/repo1/raw/branch/master/README.md", - Type: "blob", - Links: &structs.FileLinksResponse{ - Self: "https://try.gitea.io/api/v1/repos/user2/repo1/contents/README.md", - GitURL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/4b4851ad51df6a7d9f25c979345979eaeb5b349f", - HTMLURL: "https://try.gitea.io/user2/repo1/blob/master/README.md", - }, + expectedContentsResponse := getExpectedReadmeContentsResponse() + + t.Run("Get README.md contents with GetContents()", func(t *testing.T) { + fileContentResponse, err := GetContents(ctx.Repo.Repository, treePath, ref, false) + assert.EqualValues(t, expectedContentsResponse, fileContentResponse) + assert.Nil(t, err) + }) + + t.Run("Get REAMDE.md contents with ref as empty string (should then use the repo's default branch) with GetContents()", func(t *testing.T) { + fileContentResponse, err := GetContents(ctx.Repo.Repository, treePath, "", false) + assert.EqualValues(t, expectedContentsResponse, fileContentResponse) + assert.Nil(t, err) + }) +} + +func TestGetContentsOrListForDir(t *testing.T) { + models.PrepareTestEnv(t) + ctx := test.MockContext(t, "user2/repo1") + ctx.SetParams(":id", "1") + test.LoadRepo(t, ctx, 1) + test.LoadRepoCommit(t, ctx) + test.LoadUser(t, ctx, 2) + test.LoadGitRepo(t, ctx) + treePath := "" // root dir + ref := ctx.Repo.Repository.DefaultBranch + + readmeContentsResponse := getExpectedReadmeContentsResponse() + // because will be in a list, doesn't have encoding and content + readmeContentsResponse.Encoding = nil + readmeContentsResponse.Content = nil + + expectedContentsListResponse := []*api.ContentsResponse{ + readmeContentsResponse, } - t.Run("Get README.md contents", func(t *testing.T) { - fileContentResponse, err := GetFileContents(ctx.Repo.Repository, treePath, ref) - assert.EqualValues(t, expectedFileContentResponse, fileContentResponse) + t.Run("Get root dir contents with GetContentsOrList()", func(t *testing.T) { + fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, ref) + assert.EqualValues(t, expectedContentsListResponse, fileContentResponse) + assert.Nil(t, err) + }) + + t.Run("Get root dir contents with ref as empty string (should then use the repo's default branch) with GetContentsOrList()", func(t *testing.T) { + fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, "") + assert.EqualValues(t, expectedContentsListResponse, fileContentResponse) + assert.Nil(t, err) + }) +} + +func TestGetContentsOrListForFile(t *testing.T) { + models.PrepareTestEnv(t) + ctx := test.MockContext(t, "user2/repo1") + ctx.SetParams(":id", "1") + test.LoadRepo(t, ctx, 1) + test.LoadRepoCommit(t, ctx) + test.LoadUser(t, ctx, 2) + test.LoadGitRepo(t, ctx) + treePath := "README.md" + ref := ctx.Repo.Repository.DefaultBranch + + expectedContentsResponse := getExpectedReadmeContentsResponse() + + t.Run("Get README.md contents with GetContentsOrList()", func(t *testing.T) { + fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, ref) + assert.EqualValues(t, expectedContentsResponse, fileContentResponse) assert.Nil(t, err) }) - t.Run("Get REAMDE.md contents with ref as empty string (should then use the repo's default branch)", func(t *testing.T) { - fileContentResponse, err := GetFileContents(ctx.Repo.Repository, treePath, "") - assert.EqualValues(t, expectedFileContentResponse, fileContentResponse) + t.Run("Get REAMDE.md contents with ref as empty string (should then use the repo's default branch) with GetContentsOrList()", func(t *testing.T) { + fileContentResponse, err := GetContentsOrList(ctx.Repo.Repository, treePath, "") + assert.EqualValues(t, expectedContentsResponse, fileContentResponse) assert.Nil(t, err) }) } -func TestGetFileContentsErrors(t *testing.T) { +func TestGetContentsErrors(t *testing.T) { + models.PrepareTestEnv(t) + ctx := test.MockContext(t, "user2/repo1") + ctx.SetParams(":id", "1") + test.LoadRepo(t, ctx, 1) + test.LoadRepoCommit(t, ctx) + test.LoadUser(t, ctx, 2) + test.LoadGitRepo(t, ctx) + repo := ctx.Repo.Repository + treePath := "README.md" + ref := repo.DefaultBranch + + t.Run("bad treePath", func(t *testing.T) { + badTreePath := "bad/tree.md" + fileContentResponse, err := GetContents(repo, badTreePath, ref, false) + assert.Error(t, err) + assert.EqualError(t, err, "object does not exist [id: , rel_path: bad]") + assert.Nil(t, fileContentResponse) + }) + + t.Run("bad ref", func(t *testing.T) { + badRef := "bad_ref" + fileContentResponse, err := GetContents(repo, treePath, badRef, false) + assert.Error(t, err) + assert.EqualError(t, err, "object does not exist [id: "+badRef+", rel_path: ]") + assert.Nil(t, fileContentResponse) + }) +} + +func TestGetContentsOrListErrors(t *testing.T) { models.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1") ctx.SetParams(":id", "1") @@ -74,7 +176,7 @@ func TestGetFileContentsErrors(t *testing.T) { t.Run("bad treePath", func(t *testing.T) { badTreePath := "bad/tree.md" - fileContentResponse, err := GetFileContents(repo, badTreePath, ref) + fileContentResponse, err := GetContentsOrList(repo, badTreePath, ref) assert.Error(t, err) assert.EqualError(t, err, "object does not exist [id: , rel_path: bad]") assert.Nil(t, fileContentResponse) @@ -82,7 +184,7 @@ func TestGetFileContentsErrors(t *testing.T) { t.Run("bad ref", func(t *testing.T) { badRef := "bad_ref" - fileContentResponse, err := GetFileContents(repo, treePath, badRef) + fileContentResponse, err := GetContentsOrList(repo, treePath, badRef) assert.Error(t, err) assert.EqualError(t, err, "object does not exist [id: "+badRef+", rel_path: ]") assert.Nil(t, fileContentResponse) diff --git a/modules/repofiles/file.go b/modules/repofiles/file.go index 70fd57bba0..801f770e02 100644 --- a/modules/repofiles/file.go +++ b/modules/repofiles/file.go @@ -17,8 +17,8 @@ import ( // GetFileResponseFromCommit Constructs a FileResponse from a Commit object func GetFileResponseFromCommit(repo *models.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) { - fileContents, _ := GetFileContents(repo, treeName, branch) // ok if fails, then will be nil - fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil + fileContents, _ := GetContents(repo, treeName, branch, false) // ok if fails, then will be nil + fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil verification := GetPayloadCommitVerification(commit) fileResponse := &api.FileResponse{ Content: fileContents, diff --git a/modules/repofiles/file_test.go b/modules/repofiles/file_test.go index 5f6320a938..00feb93fff 100644 --- a/modules/repofiles/file_test.go +++ b/modules/repofiles/file_test.go @@ -5,6 +5,7 @@ package repofiles import ( + "code.gitea.io/gitea/modules/setting" "testing" "code.gitea.io/gitea/models" @@ -16,21 +17,31 @@ import ( ) func getExpectedFileResponse() *api.FileResponse { + treePath := "README.md" + sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f" + encoding := "base64" + content := "IyByZXBvMQoKRGVzY3JpcHRpb24gZm9yIHJlcG8x" + selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master" + htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + treePath + gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/" + sha + downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath return &api.FileResponse{ - Content: &api.FileContentResponse{ - Name: "README.md", - Path: "README.md", - SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f", + Content: &api.ContentsResponse{ + Name: treePath, + Path: treePath, + SHA: sha, + Type: "file", Size: 30, - URL: "https://try.gitea.io/api/v1/repos/user2/repo1/contents/README.md", - HTMLURL: "https://try.gitea.io/user2/repo1/blob/master/README.md", - GitURL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/4b4851ad51df6a7d9f25c979345979eaeb5b349f", - DownloadURL: "https://try.gitea.io/user2/repo1/raw/branch/master/README.md", - Type: "blob", + Encoding: &encoding, + Content: &content, + URL: &selfURL, + HTMLURL: &htmlURL, + GitURL: &gitURL, + DownloadURL: &downloadURL, Links: &api.FileLinksResponse{ - Self: "https://try.gitea.io/api/v1/repos/user2/repo1/contents/README.md", - GitURL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/4b4851ad51df6a7d9f25c979345979eaeb5b349f", - HTMLURL: "https://try.gitea.io/user2/repo1/blob/master/README.md", + Self: &selfURL, + GitURL: &gitURL, + HTMLURL: &htmlURL, }, }, Commit: &api.FileCommitResponse{ diff --git a/modules/structs/repo_file.go b/modules/structs/repo_file.go index e5be9ce108..b2eeb7f13a 100644 --- a/modules/structs/repo_file.go +++ b/modules/structs/repo_file.go @@ -49,23 +49,32 @@ type UpdateFileOptions struct { // FileLinksResponse contains the links for a repo's file type FileLinksResponse struct { - Self string `json:"url"` - GitURL string `json:"git_url"` - HTMLURL string `json:"html_url"` + Self *string `json:"self"` + GitURL *string `json:"git"` + HTMLURL *string `json:"html"` } -// FileContentResponse contains information about a repo's file stats and content -type FileContentResponse struct { - Name string `json:"name"` - Path string `json:"path"` - SHA string `json:"sha"` - Size int64 `json:"size"` - URL string `json:"url"` - HTMLURL string `json:"html_url"` - GitURL string `json:"git_url"` - DownloadURL string `json:"download_url"` - Type string `json:"type"` - Links *FileLinksResponse `json:"_links"` +// ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content +type ContentsResponse struct { + Name string `json:"name"` + Path string `json:"path"` + SHA string `json:"sha"` + // `type` will be `file`, `dir`, `symlink`, or `submodule` + Type string `json:"type"` + Size int64 `json:"size"` + // `encoding` is populated when `type` is `file`, otherwise null + Encoding *string `json:"encoding"` + // `content` is populated when `type` is `file`, otherwise null + Content *string `json:"content"` + // `target` is populated when `type` is `symlink`, otherwise null + Target *string `json:"target"` + URL *string `json:"url"` + HTMLURL *string `json:"html_url"` + GitURL *string `json:"git_url"` + DownloadURL *string `json:"download_url"` + // `submodule_git_url` is populated when `type` is `submodule`, otherwise null + SubmoduleGitURL *string `json:"submodule_git_url"` + Links *FileLinksResponse `json:"_links"` } // FileCommitResponse contains information generated from a Git commit for a repo's file. @@ -81,7 +90,7 @@ type FileCommitResponse struct { // FileResponse contains information about a repo's file type FileResponse struct { - Content *FileContentResponse `json:"content"` + Content *ContentsResponse `json:"content"` Commit *FileCommitResponse `json:"commit"` Verification *PayloadCommitVerification `json:"verification"` } |