gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "net/http"
  6. repo_model "code.gitea.io/gitea/models/repo"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/services/context"
  9. )
  10. // GetLicenses returns licenses
  11. func GetLicenses(ctx *context.APIContext) {
  12. // swagger:operation GET /repos/{owner}/{repo}/licenses repository repoGetLicenses
  13. // ---
  14. // summary: Get repo licenses
  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. // responses:
  29. // "404":
  30. // "$ref": "#/responses/notFound"
  31. // "200":
  32. // "$ref": "#/responses/LicensesList"
  33. licenses, err := repo_model.GetRepoLicenses(ctx, ctx.Repo.Repository)
  34. if err != nil {
  35. log.Error("GetRepoLicenses failed: %v", err)
  36. ctx.APIErrorInternal(err)
  37. return
  38. }
  39. resp := make([]string, len(licenses))
  40. for i := range licenses {
  41. resp[i] = licenses[i].License
  42. }
  43. ctx.JSON(http.StatusOK, resp)
  44. }