MCPcopy Index your code
hub / github.com/sourcegraph/checkup / readFile

Method readFile

storage/github/github.go:107–128  ·  view source on GitHub ↗

readFile reads a file from the Git repository at its latest revision. This method returns the plaintext contents, the SHA associated with the contents If an error occurs, the contents and sha will be nil & empty.

(filename string)

Source from the content-addressed store, hash-verified

105// This method returns the plaintext contents, the SHA associated with the contents
106// If an error occurs, the contents and sha will be nil & empty.
107func (gh *Storage) readFile(filename string) ([]byte, string, error) {
108 if err := gh.ensureClient(); err != nil {
109 return nil, "", err
110 }
111
112 contents, _, resp, err := gh.client.Repositories.GetContents(
113 context.Background(),
114 gh.RepositoryOwner,
115 gh.RepositoryName,
116 gh.fullPathName(filename),
117 &github.RepositoryContentGetOptions{Ref: "heads/" + gh.Branch},
118 )
119 if err != nil {
120 if resp != nil && resp.StatusCode == http.StatusNotFound {
121 return nil, "", errFileNotFound
122 }
123 return nil, "", err
124 }
125
126 decoded, err := contents.GetContent()
127 return []byte(decoded), *contents.SHA, err
128}
129
130// writeFile commits the contents to the Git repo at the given filename & revision.
131// If the Git repo does not yet have a file at this filename, it will create the file.

Callers 4

readIndexMethod · 0.95
FetchMethod · 0.95
TestGitHubWithoutSubdirFunction · 0.95
TestGitHubWithSubdirFunction · 0.95

Implementers 5

fakecheckup_test.go
Storagestorage/sql/sql.go
Storagestorage/s3/s3.go
Storagestorage/github/github.go
Storagestorage/fs/fs.go

Calls 2

ensureClientMethod · 0.95
fullPathNameMethod · 0.95

Tested by 2

TestGitHubWithoutSubdirFunction · 0.76
TestGitHubWithSubdirFunction · 0.76