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

repo.go 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package tech
  2. import (
  3. "code.gitea.io/gitea/models"
  4. "code.gitea.io/gitea/modules/auth"
  5. "code.gitea.io/gitea/modules/context"
  6. api "code.gitea.io/gitea/modules/structs"
  7. "code.gitea.io/gitea/routers/response"
  8. "code.gitea.io/gitea/services/repository"
  9. techService "code.gitea.io/gitea/services/tech"
  10. "fmt"
  11. "net/http"
  12. )
  13. //CommitOpenIRepo 新建启智项目申请页面提交
  14. func CommitOpenIRepo(ctx *context.APIContext, form api.OpenITechRepo) {
  15. //解析项目路径,查找项目
  16. repo, err := repository.FindRepoByUrl(form.Url)
  17. if err != nil {
  18. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  19. return
  20. }
  21. //查找项目编号
  22. tech, err := models.GetTechByTechNo(form.TechNo)
  23. if err != nil {
  24. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  25. return
  26. }
  27. //判断承接单位是否在科技项目的参与单位中
  28. if !tech.IsValidInstitution(form.Institution) {
  29. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr("tech.institution_not_valid")))
  30. return
  31. }
  32. //判断是否已经存在了该项目
  33. exist, err := techService.IsValidRepoConvergeExists(repo.ID, tech.ID)
  34. if err != nil {
  35. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  36. return
  37. }
  38. if exist {
  39. ctx.JSON(http.StatusOK, response.OuterServerError(fmt.Sprintf(ctx.Tr("tech.repo_converge_exists"), tech.ProjectName, repo.Alias)))
  40. return
  41. }
  42. //写入数据库
  43. rci := &models.RepoConvergeInfo{
  44. RepoID: repo.ID,
  45. Url: form.Url,
  46. BaseInfoID: tech.ID,
  47. Institution: form.Institution,
  48. UID: ctx.User.ID,
  49. Status: models.DefaultTechApprovedStatus,
  50. }
  51. err = rci.InsertOrUpdate()
  52. if err != nil {
  53. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  54. return
  55. }
  56. ctx.JSON(http.StatusOK, response.OuterSuccess())
  57. }
  58. //CommitNotOpenIRepo 新建非启智项目申请页面提交
  59. func CommitNotOpenIRepo(ctx *context.APIContext, form api.NotOpenITechRepo) {
  60. //触发更新迁移状态
  61. go techService.UpdateTechMigrateStatus()
  62. //查找项目编号
  63. tech, err := models.GetTechByTechNo(form.TechNo)
  64. if err != nil {
  65. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  66. return
  67. }
  68. //判断承接单位是否在科技项目的参与单位中
  69. if !tech.IsValidInstitution(form.Institution) {
  70. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr("tech.institution_not_valid")))
  71. return
  72. }
  73. //调用迁移接口
  74. bizErr := repository.MigrateSubmit(ctx.User, auth.MigrateRepoForm{
  75. CloneAddr: form.Url,
  76. UID: form.UID,
  77. RepoName: form.RepoName,
  78. Alias: form.Alias,
  79. Description: form.Description,
  80. Labels: true,
  81. Mirror: true,
  82. })
  83. if bizErr != nil {
  84. if bizErr.Code == 3 {
  85. ctx.JSON(http.StatusOK, response.OuterError(bizErr.Code, ctx.Tr("tech.to_migrate_repo_exists")))
  86. return
  87. }
  88. ctx.JSON(http.StatusOK, response.OuterError(bizErr.Code, ctx.Tr(bizErr.Err)))
  89. return
  90. }
  91. repo, err := models.GetRepositoryByName(form.UID, form.RepoName)
  92. if err != nil {
  93. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  94. return
  95. }
  96. //判断是否已经存在了该项目
  97. exist, err := techService.IsValidRepoConvergeExists(repo.ID, tech.ID)
  98. if err != nil {
  99. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  100. return
  101. }
  102. if exist {
  103. ctx.JSON(http.StatusOK, response.OuterServerError(fmt.Sprintf(ctx.Tr("tech.repo_converge_exists"), tech.ProjectName, repo.Alias)))
  104. return
  105. }
  106. //写入数据库
  107. rci := &models.RepoConvergeInfo{
  108. RepoID: repo.ID,
  109. Url: form.Url,
  110. BaseInfoID: tech.ID,
  111. Institution: form.Institution,
  112. UID: ctx.User.ID,
  113. Status: models.DefaultTechApprovedStatus,
  114. }
  115. err = rci.InsertOrUpdate()
  116. if err != nil {
  117. ctx.JSON(http.StatusOK, response.OuterServerError(ctx.Tr(err.Error())))
  118. return
  119. }
  120. ctx.JSON(http.StatusOK, response.OuterSuccess())
  121. }