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.

53 lines
1.3 KiB

  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. // "400":
  37. // "$ref": "#/responses/error"
  38. sha := ctx.Params("sha")
  39. if len(sha) == 0 {
  40. ctx.Error(http.StatusBadRequest, "", "sha not provided")
  41. return
  42. }
  43. if blob, err := repofiles.GetBlobBySHA(ctx.Repo.Repository, sha); err != nil {
  44. ctx.Error(http.StatusBadRequest, "", err)
  45. } else {
  46. ctx.JSON(http.StatusOK, blob)
  47. }
  48. }