You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blob.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/modules/repofiles"
  9. )
  10. // GetBlob get the blob of a repository file.
  11. func GetBlob(ctx *context.APIContext) {
  12. // swagger:operation GET /repos/{owner}/{repo}/git/blobs/{sha} repository GetBlob
  13. // ---
  14. // summary: Gets the blob of a repository.
  15. // produces:
  16. // - application/json
  17. // parameters:
  18. // - name: owner
  19. // in: path
  20. // description: owner of the repo
  21. // type: string
  22. // required: true
  23. // - name: repo
  24. // in: path
  25. // description: name of the repo
  26. // type: string
  27. // required: true
  28. // - name: sha
  29. // in: path
  30. // description: sha of the commit
  31. // type: string
  32. // required: true
  33. // responses:
  34. // "200":
  35. // "$ref": "#/responses/GitBlobResponse"
  36. sha := ctx.Params("sha")
  37. if len(sha) == 0 {
  38. ctx.Error(http.StatusBadRequest, "", "sha not provided")
  39. return
  40. }
  41. if blob, err := repofiles.GetBlobBySHA(ctx.Repo.Repository, sha); err != nil {
  42. ctx.Error(http.StatusBadRequest, "", err)
  43. } else {
  44. ctx.JSON(http.StatusOK, blob)
  45. }
  46. }