@@ -61,13 +61,10 @@ const ( | |||||
ActionCreateGrampusNPUTrainTask //32 | ActionCreateGrampusNPUTrainTask //32 | ||||
ActionCreateGrampusGPUTrainTask //33 | ActionCreateGrampusGPUTrainTask //33 | ||||
ActionBindWechat //34 | ActionBindWechat //34 | ||||
ActionCreateCloudbrainTask //35 | |||||
ActionDatasetRecommended //36 | |||||
ActionCreateImage //37 | |||||
ActionImageRecommend //38 | |||||
ActionChangeUserAvatar //39 | |||||
ActionPushCommits //40 | |||||
ActionForkRepo //41 | |||||
ActionDatasetRecommended //35 | |||||
ActionCreateImage //36 | |||||
ActionImageRecommend //37 | |||||
ActionChangeUserAvatar //38 | |||||
) | ) | ||||
@@ -95,6 +92,7 @@ type Action struct { | |||||
type ActionShow struct { | type ActionShow struct { | ||||
OpType ActionType | OpType ActionType | ||||
TaskType TaskType | |||||
RepoLink string | RepoLink string | ||||
ShortRepoFullDisplayName string | ShortRepoFullDisplayName string | ||||
Content string | Content string | ||||
@@ -241,7 +239,8 @@ func (a *Action) GetRepoLink() string { | |||||
func (a *Action) ToShow() *ActionShow { | func (a *Action) ToShow() *ActionShow { | ||||
actionShow := &ActionShow{} | actionShow := &ActionShow{} | ||||
actionShow.OpType = GetTaskOptType(*a) | |||||
actionShow.OpType = a.OpType | |||||
actionShow.TaskType = GetTaskTypeFromAction(a.OpType) | |||||
actionShow.Content = a.Content | actionShow.Content = a.Content | ||||
actionShow.RefName = a.RefName | actionShow.RefName = a.RefName | ||||
@@ -272,14 +271,6 @@ func (a *Action) ToShow() *ActionShow { | |||||
return actionShow | return actionShow | ||||
} | } | ||||
func GetTaskOptType(action Action) ActionType { | |||||
//Convert all types of cloudbrain tasks action into ActionCreateCloudbrainTask | |||||
if action.IsCloudbrainAction() { | |||||
return ActionCreateCloudbrainTask | |||||
} | |||||
return action.OpType | |||||
} | |||||
// GetRepositoryFromMatch returns a *Repository from a username and repo strings | // GetRepositoryFromMatch returns a *Repository from a username and repo strings | ||||
func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) { | func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) { | ||||
var err error | var err error | ||||
@@ -2,7 +2,6 @@ package models | |||||
import ( | import ( | ||||
"code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
"fmt" | |||||
"strconv" | "strconv" | ||||
"strings" | "strings" | ||||
"xorm.io/builder" | "xorm.io/builder" | ||||
@@ -355,7 +354,7 @@ type RewardRecordListOpts struct { | |||||
OperateType RewardOperateType | OperateType RewardOperateType | ||||
RewardType RewardType | RewardType RewardType | ||||
SourceType string | SourceType string | ||||
ActionType int | |||||
TaskType string | |||||
SerialNo string | SerialNo string | ||||
OrderBy RewardOperateOrderBy | OrderBy RewardOperateOrderBy | ||||
IsAdmin bool | IsAdmin bool | ||||
@@ -381,8 +380,8 @@ func (opts *RewardRecordListOpts) toCond() builder.Cond { | |||||
if opts.SourceType != "" { | if opts.SourceType != "" { | ||||
cond = cond.And(builder.Eq{"reward_operate_record.source_type": opts.SourceType}) | cond = cond.And(builder.Eq{"reward_operate_record.source_type": opts.SourceType}) | ||||
} | } | ||||
if opts.ActionType > 0 { | |||||
cond = cond.And(builder.Eq{"reward_operate_record.source_template_id": fmt.Sprint(opts.ActionType)}) | |||||
if opts.TaskType != "" { | |||||
cond = cond.And(builder.Eq{"reward_operate_record.source_template_id": opts.TaskType}) | |||||
} | } | ||||
if opts.SerialNo != "" { | if opts.SerialNo != "" { | ||||
cond = cond.And(builder.Like{"reward_operate_record.serial_no", opts.SerialNo}) | cond = cond.And(builder.Like{"reward_operate_record.serial_no", opts.SerialNo}) | ||||
@@ -2,7 +2,6 @@ package models | |||||
import ( | import ( | ||||
"code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
"fmt" | |||||
"xorm.io/builder" | "xorm.io/builder" | ||||
) | ) | ||||
@@ -11,6 +10,66 @@ const ( | |||||
PeriodDaily = "DAILY" | PeriodDaily = "DAILY" | ||||
) | ) | ||||
type TaskType string | |||||
const ( | |||||
TaskCreatePublicRepo TaskType = "CreatePublicRepo" | |||||
TaskCreateIssue TaskType = "CreateIssue" | |||||
TaskCreatePullRequest TaskType = "CreatePullRequest" | |||||
TaskCommentIssue TaskType = "CommentIssue" | |||||
TaskUploadAttachment TaskType = "UploadAttachment" | |||||
TaskCreateNewModelTask TaskType = "CreateNewModelTask" | |||||
TaskBindWechat TaskType = "BindWechat" | |||||
TaskCreateCloudbrainTask TaskType = "CreateCloudbrainTask" | |||||
TaskDatasetRecommended TaskType = "DatasetRecommended " | |||||
TaskCreateImage TaskType = "CreateImage" | |||||
TaskImageRecommend TaskType = "ImageRecommend" | |||||
TaskChangeUserAvatar TaskType = "ChangeUserAvatar" | |||||
TaskPushCommits TaskType = "PushCommits" | |||||
) | |||||
func GetTaskTypeFromAction(a ActionType) TaskType { | |||||
switch a { | |||||
case ActionCreateDebugGPUTask, | |||||
ActionCreateDebugNPUTask, | |||||
ActionCreateTrainTask, | |||||
ActionCreateInferenceTask, | |||||
ActionCreateBenchMarkTask, | |||||
ActionCreateGPUTrainTask, | |||||
ActionCreateGrampusNPUTrainTask, | |||||
ActionCreateGrampusGPUTrainTask: | |||||
return TaskCreateCloudbrainTask | |||||
case ActionCreateRepo: | |||||
return TaskCreatePublicRepo | |||||
case ActionCreatePullRequest: | |||||
return TaskCreatePullRequest | |||||
case ActionCommentIssue: | |||||
return TaskCommentIssue | |||||
case ActionUploadAttachment: | |||||
return TaskUploadAttachment | |||||
case ActionCreateNewModelTask: | |||||
return TaskCreateNewModelTask | |||||
case ActionBindWechat: | |||||
return TaskBindWechat | |||||
case ActionDatasetRecommended: | |||||
return TaskDatasetRecommended | |||||
case ActionImageRecommend: | |||||
return TaskImageRecommend | |||||
case ActionCreateImage: | |||||
return TaskCreateImage | |||||
case ActionChangeUserAvatar: | |||||
return TaskChangeUserAvatar | |||||
case ActionCommitRepo, | |||||
ActionDeleteBranch, | |||||
ActionPushTag, | |||||
ActionDeleteTag: | |||||
return TaskPushCommits | |||||
case ActionCreateIssue: | |||||
return TaskCreateIssue | |||||
} | |||||
return "" | |||||
} | |||||
//PointTaskConfig Only add and delete are allowed, edit is not allowed | //PointTaskConfig Only add and delete are allowed, edit is not allowed | ||||
//so if you want to edit config for some task code,please delete first and add new one | //so if you want to edit config for some task code,please delete first and add new one | ||||
type TaskConfig struct { | type TaskConfig struct { | ||||
@@ -124,8 +183,8 @@ func GetTaskConfigList() ([]*TaskConfig, error) { | |||||
type GetTaskConfigOpts struct { | type GetTaskConfigOpts struct { | ||||
ListOptions | ListOptions | ||||
Status int //1 normal 2 deleted | |||||
ActionType int | |||||
Status int //1 normal 2 deleted | |||||
TaskType string | |||||
} | } | ||||
func GetTaskConfigPageWithDeleted(opt GetTaskConfigOpts) ([]*TaskAndLimiterConfig, int64, error) { | func GetTaskConfigPageWithDeleted(opt GetTaskConfigOpts) ([]*TaskAndLimiterConfig, int64, error) { | ||||
@@ -133,8 +192,8 @@ func GetTaskConfigPageWithDeleted(opt GetTaskConfigOpts) ([]*TaskAndLimiterConfi | |||||
opt.Page = 1 | opt.Page = 1 | ||||
} | } | ||||
cond := builder.NewCond() | cond := builder.NewCond() | ||||
if opt.ActionType > 0 { | |||||
cond = cond.And(builder.Eq{"task_code": fmt.Sprint(opt.ActionType)}) | |||||
if opt.TaskType != "" { | |||||
cond = cond.And(builder.Eq{"task_code": opt.TaskType}) | |||||
} | } | ||||
var count int64 | var count int64 | ||||
@@ -428,19 +428,3 @@ func (t *actionNotifier) NotifyChangeUserAvatar(user *models.User, form auth.Ava | |||||
log.Error("notifyWatchers: %v", err) | log.Error("notifyWatchers: %v", err) | ||||
} | } | ||||
} | } | ||||
func (t *actionNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { | |||||
act := &models.Action{ | |||||
ActUserID: pusher.ID, | |||||
ActUser: pusher, | |||||
OpType: models.ActionPushCommits, | |||||
RepoID: repo.ID, | |||||
Repo: repo, | |||||
RefName: refName, | |||||
IsPrivate: repo.IsPrivate, | |||||
Content: fmt.Sprintf("%s|%s", oldCommitID, newCommitID), | |||||
} | |||||
if err := models.NotifyWatchers(act); err != nil { | |||||
log.Error("notifyWatchers: %v", err) | |||||
} | |||||
} |
@@ -141,7 +141,7 @@ func GetAdminRewardList(ctx *context.Context) { | |||||
func buildAdminRewardRecordListOpts(ctx *context.Context) (*models.RewardRecordListOpts, error) { | func buildAdminRewardRecordListOpts(ctx *context.Context) (*models.RewardRecordListOpts, error) { | ||||
operateType := ctx.Query("operate") | operateType := ctx.Query("operate") | ||||
sourceType := ctx.Query("source") | sourceType := ctx.Query("source") | ||||
actionType := ctx.QueryInt("action") | |||||
taskType := ctx.Query("action") | |||||
serialNo := ctx.Query("serialNo") | serialNo := ctx.Query("serialNo") | ||||
status := ctx.Query("status") | status := ctx.Query("status") | ||||
@@ -161,7 +161,7 @@ func buildAdminRewardRecordListOpts(ctx *context.Context) (*models.RewardRecordL | |||||
RewardType: models.RewardTypePoint, | RewardType: models.RewardTypePoint, | ||||
OrderBy: orderBy, | OrderBy: orderBy, | ||||
SourceType: sourceType, | SourceType: sourceType, | ||||
ActionType: actionType, | |||||
TaskType: taskType, | |||||
SerialNo: serialNo, | SerialNo: serialNo, | ||||
IsAdmin: true, | IsAdmin: true, | ||||
Status: status, | Status: status, | ||||
@@ -13,11 +13,11 @@ import ( | |||||
func GetTaskConfigList(ctx *context.Context) { | func GetTaskConfigList(ctx *context.Context) { | ||||
page := ctx.QueryInt("Page") | page := ctx.QueryInt("Page") | ||||
status := ctx.QueryInt("Status") | status := ctx.QueryInt("Status") | ||||
action := ctx.QueryInt("Action") | |||||
action := ctx.Query("Action") | |||||
r, err := task.GetTaskConfigWithLimitList(models.GetTaskConfigOpts{ | r, err := task.GetTaskConfigWithLimitList(models.GetTaskConfigOpts{ | ||||
ListOptions: models.ListOptions{PageSize: 20, Page: page}, | ListOptions: models.ListOptions{PageSize: 20, Page: page}, | ||||
Status: status, | Status: status, | ||||
ActionType: action, | |||||
TaskType: action, | |||||
}) | }) | ||||
if err != nil { | if err != nil { | ||||
log.Error("GetTaskConfigList error.%v", err) | log.Error("GetTaskConfigList error.%v", err) | ||||
@@ -15,19 +15,24 @@ func Accomplish(action models.Action) { | |||||
log.Error("PANIC:%v", combinedErr) | log.Error("PANIC:%v", combinedErr) | ||||
} | } | ||||
}() | }() | ||||
action.OpType = models.GetTaskOptType(action) | |||||
switch action.OpType { | |||||
taskType := models.GetTaskTypeFromAction(action.OpType) | |||||
if taskType == "" { | |||||
log.Info("Accomplish finished.taskType is not exist.action.ID=%d", action.ID) | |||||
return | |||||
} | |||||
switch taskType { | |||||
//only creating public repo can be rewarded | //only creating public repo can be rewarded | ||||
case models.ActionCreateRepo: | |||||
case models.TaskCreatePublicRepo: | |||||
if action.Repo.IsPrivate { | if action.Repo.IsPrivate { | ||||
return | return | ||||
} | } | ||||
//only creating public image can be rewarded | //only creating public image can be rewarded | ||||
case models.ActionCreateImage: | |||||
case models.TaskCreateImage: | |||||
if action.IsPrivate { | if action.IsPrivate { | ||||
return | return | ||||
} | } | ||||
case models.ActionBindWechat: | |||||
case models.TaskBindWechat: | |||||
n, err := models.CountWechatBindLog(action.Content, models.WECHAT_BIND) | n, err := models.CountWechatBindLog(action.Content, models.WECHAT_BIND) | ||||
if err != nil { | if err != nil { | ||||
log.Error("CountWechatBindLog error when accomplish task,err=%v", err) | log.Error("CountWechatBindLog error when accomplish task,err=%v", err) | ||||
@@ -40,10 +45,10 @@ func Accomplish(action models.Action) { | |||||
} | } | ||||
} | } | ||||
go accomplish(action) | |||||
go accomplish(action, taskType) | |||||
} | } | ||||
func accomplish(action models.Action) error { | |||||
func accomplish(action models.Action, taskType models.TaskType) error { | |||||
defer func() { | defer func() { | ||||
if err := recover(); err != nil { | if err := recover(); err != nil { | ||||
combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) | combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) | ||||
@@ -51,10 +56,9 @@ func accomplish(action models.Action) error { | |||||
} | } | ||||
}() | }() | ||||
userId := action.ActUserID | userId := action.ActUserID | ||||
taskType := fmt.Sprint(action.OpType) | |||||
//get task config | //get task config | ||||
config, err := GetTaskConfig(taskType) | |||||
config, err := GetTaskConfig(string(taskType)) | |||||
if err != nil { | if err != nil { | ||||
log.Error("GetTaskConfig error,%v", err) | log.Error("GetTaskConfig error,%v", err) | ||||
return err | return err | ||||
@@ -86,7 +90,7 @@ func accomplish(action models.Action) error { | |||||
reward.Operate(&models.RewardOperateContext{ | reward.Operate(&models.RewardOperateContext{ | ||||
SourceType: models.SourceTypeAccomplishTask, | SourceType: models.SourceTypeAccomplishTask, | ||||
SourceId: fmt.Sprint(action.ID), | SourceId: fmt.Sprint(action.ID), | ||||
SourceTemplateId: fmt.Sprint(action.OpType), | |||||
SourceTemplateId: string(taskType), | |||||
Title: config.Title, | Title: config.Title, | ||||
Reward: models.Reward{ | Reward: models.Reward{ | ||||
Amount: config.AwardAmount, | Amount: config.AwardAmount, | ||||