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.

config.go 1.8 kB

3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package task
  2. import (
  3. "code.gitea.io/gitea/models"
  4. "code.gitea.io/gitea/modules/context"
  5. "code.gitea.io/gitea/modules/log"
  6. "code.gitea.io/gitea/routers/response"
  7. "code.gitea.io/gitea/services/task"
  8. "errors"
  9. "net/http"
  10. )
  11. func GetTaskConfigList(ctx *context.Context) {
  12. page := ctx.QueryInt("Page")
  13. status := ctx.QueryInt("Status")
  14. action := ctx.Query("Action")
  15. r, err := task.GetTaskConfigWithLimitList(models.GetTaskConfigOpts{
  16. ListOptions: models.ListOptions{PageSize: 20, Page: page},
  17. Status: status,
  18. TaskType: action,
  19. })
  20. if err != nil {
  21. log.Error("GetTaskConfigList error.%v", err)
  22. ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
  23. return
  24. }
  25. ctx.JSON(http.StatusOK, response.SuccessWithData(r))
  26. }
  27. func OperateTaskConfig(ctx *context.Context, config models.TaskConfigWithLimit) {
  28. action := ctx.Params(":action")
  29. var err error
  30. switch action {
  31. case "edit":
  32. err = task.EditTaskConfig(config, ctx.User)
  33. case "new":
  34. err = task.AddTaskConfig(config, ctx.User)
  35. case "del":
  36. err = task.DelTaskConfig(config.ID, ctx.User)
  37. default:
  38. err = errors.New("action type error")
  39. }
  40. if err != nil {
  41. log.Error("OperateTaskConfig error ,%v", err)
  42. ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
  43. return
  44. }
  45. ctx.JSON(http.StatusOK, response.Success())
  46. }
  47. func BatchAddTaskConfig(ctx *context.Context, list models.BatchLimitConfigVO) {
  48. successCount := 0
  49. failCount := 0
  50. for _, config := range list.ConfigList {
  51. err := task.AddTaskConfig(config, ctx.User)
  52. if err != nil {
  53. failCount++
  54. } else {
  55. successCount++
  56. }
  57. }
  58. r := make(map[string]int, 2)
  59. r["successCount"] = successCount
  60. r["failCount"] = failCount
  61. log.Debug("BatchAddTaskConfig success.result=%v", r)
  62. ctx.JSON(http.StatusOK, response.SuccessWithData(r))
  63. }