mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-02 08:15:43 +02:00
Some work
This commit is contained in:
parent
34dd91a476
commit
7fefa37271
@ -3,7 +3,13 @@
|
||||
|
||||
package project
|
||||
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
type WorkflowEvent string
|
||||
|
||||
@ -19,12 +25,52 @@ const (
|
||||
WorkflowEventAutoCloseIssue WorkflowEvent = "auto_close_issue"
|
||||
)
|
||||
|
||||
type ProjectWorkflow struct {
|
||||
ID int64
|
||||
ProjectID int64 `xorm:"index"`
|
||||
WorkflowEvent WorkflowEvent `xorm:"index"`
|
||||
type WorkflowActionType string
|
||||
|
||||
const (
|
||||
WorkflowActionTypeScope WorkflowActionType = "scope" // issue, pull_request, etc.
|
||||
WorkflowActionTypeLabel WorkflowActionType = "label" // choose one or more labels
|
||||
WorkflowActionTypeColumn WorkflowActionType = "column" // choose one column
|
||||
WorkflowActionTypeClose WorkflowActionType = "close" // close the issue
|
||||
)
|
||||
|
||||
type WorkflowAction struct {
|
||||
ActionType WorkflowActionType
|
||||
ActionValue string
|
||||
}
|
||||
|
||||
type ProjectWorkflowEvent struct {
|
||||
ID int64
|
||||
ProjectID int64 `xorm:"unique(s)"`
|
||||
WorkflowEvent WorkflowEvent `xorm:"unique(s)"`
|
||||
WorkflowActions []WorkflowAction `xorm:"TEXT json"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(ProjectWorkflow))
|
||||
db.RegisterModel(new(ProjectWorkflowEvent))
|
||||
}
|
||||
|
||||
func FindWorkflowEvents(ctx context.Context, projectID int64) (map[WorkflowEvent]ProjectWorkflowEvent, error) {
|
||||
events := make(map[WorkflowEvent]ProjectWorkflowEvent)
|
||||
if err := db.GetEngine(ctx).Where("project_id=?", projectID).Find(&events); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make(map[WorkflowEvent]ProjectWorkflowEvent, len(events))
|
||||
for _, event := range events {
|
||||
res[event.WorkflowEvent] = event
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func GetWorkflowEventByID(ctx context.Context, id int64) (*ProjectWorkflowEvent, error) {
|
||||
p, exist, err := db.GetByID[ProjectWorkflowEvent](ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exist {
|
||||
return nil, util.ErrNotExist
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
14
routers/web/projects/workflows.go
Normal file
14
routers/web/projects/workflows.go
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package projects
|
||||
|
||||
import "code.gitea.io/gitea/services/context"
|
||||
|
||||
var tmplWorkflows = "projects/workflows"
|
||||
|
||||
func Workflows(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func WorkflowEdit(ctx *context.Context) {
|
||||
}
|
@ -34,6 +34,7 @@ import (
|
||||
"code.gitea.io/gitea/routers/web/misc"
|
||||
"code.gitea.io/gitea/routers/web/org"
|
||||
org_setting "code.gitea.io/gitea/routers/web/org/setting"
|
||||
"code.gitea.io/gitea/routers/web/projects"
|
||||
"code.gitea.io/gitea/routers/web/repo"
|
||||
"code.gitea.io/gitea/routers/web/repo/actions"
|
||||
repo_setting "code.gitea.io/gitea/routers/web/repo/setting"
|
||||
@ -1402,7 +1403,8 @@ func registerRoutes(m *web.Router) {
|
||||
m.Get("", repo.Projects)
|
||||
m.Get("/{id}", repo.ViewProject)
|
||||
m.Group("/{id}/workflows", func() {
|
||||
m.Get("", repo.Workflows)
|
||||
m.Get("", projects.Workflows)
|
||||
m.Get("/{workflow_id}", projects.WorkflowEdit)
|
||||
})
|
||||
m.Group("", func() { //nolint:dupl
|
||||
m.Get("/new", repo.RenderNewProject)
|
||||
|
Loading…
x
Reference in New Issue
Block a user