mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-23 09:30:50 +00:00
feat: API GET /repos/{owner}/{repo}/git/blobs
This commit is contained in:
parent
07e8684a61
commit
a4ea74020f
6 changed files with 167 additions and 7 deletions
|
@ -250,6 +250,23 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
|
|||
return contentsResponse, nil
|
||||
}
|
||||
|
||||
// GetBlobsBySHA gets multiple GitBlobs of a repository by sha hash.
|
||||
func GetBlobsBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, shas []string) ([]*api.GitBlob, error) {
|
||||
if len(shas) > setting.API.MaxResponseItems {
|
||||
shas = shas[:setting.API.MaxResponseItems]
|
||||
}
|
||||
|
||||
blobs := make([]*api.GitBlob, 0, len(shas))
|
||||
for _, sha := range shas {
|
||||
blob, err := GetBlobBySHA(ctx, repo, gitRepo, sha)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blobs = append(blobs, blob)
|
||||
}
|
||||
return blobs, nil
|
||||
}
|
||||
|
||||
// GetBlobBySHA get the GitBlob of a repository using a sha hash.
|
||||
func GetBlobBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, sha string) (*api.GitBlob, error) {
|
||||
gitBlob, err := gitRepo.GetBlob(sha)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue