-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add project workflow feature so users can define how to execute steps when project related events fired #30205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lunny
wants to merge
81
commits into
go-gitea:main
Choose a base branch
from
lunny:lunny/project_workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,410
−68
Draft
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
64e0ba1
Add project workflow feature so users can define how to execute steps…
lunny 95cecbb
Add NewIssue events
lunny 5d78be4
Merge branch 'main' into lunny/project_workflow
lunny 9d0a599
Merge branch 'main' into lunny/project_workflow
lunny f2c7d32
Merge branch 'main' into lunny/project_workflow
lunny fb12ed2
add workflow
lunny 34dd91a
Merge branch 'main' into lunny/project_workflow
lunny 7fefa37
Some work
lunny b37cb32
Add web routers for project workflow
lunny e7365c7
Merge branch 'main' into lunny/project_workflow
lunny cb036a3
Merge branch 'main' into lunny/project_workflow
lunny 7c66abc
Use database to store the project workflow data
lunny a4f8408
Merge branch 'main' into lunny/project_workflow
lunny bf9511e
Merge branch 'main' into lunny/project_workflow
lunny 5481800
some improvements
lunny 6af5045
new layout
lunny e5b16f9
remove unnecessary button
lunny dd63558
improvements
lunny 20b4ce5
improvements
lunny ad4c17b
Fix url change
lunny 0fe622a
Fix switch events
lunny 5cd2901
Fix clone
lunny af5ba85
improvements
lunny f681274
enable/disable
lunny 6411e21
disabled status
lunny 990d800
improvements
lunny 58a3680
adjust workflow page header
lunny a18eba0
fix
lunny f7b8f6e
Merge branch 'main' into lunny/project_workflow
lunny b191ded
Fix
lunny 8115684
replace alert
lunny 836bf98
Remove clone support at the time
lunny 74fc30f
Support add labels and remove labels for issue's project column chang…
lunny 822387a
support labels filter
lunny ab5fa40
fix clone
lunny cc4a85b
fix
lunny 829fa15
fix
lunny 7240b2b
fix
lunny 60bf918
Fix enable/disable
lunny 6c4160d
fix
lunny 7eb5673
fix
lunny 623388c
Merge branch 'main' into lunny/project_workflow
lunny c2419f8
improvements
lunny 903d605
improvements
lunny 323a24e
Fix bug
lunny 3d081b3
Fix bug
lunny 635649d
add translations
lunny f68eee5
Fix translations
lunny e1d2cf4
Fix bug
lunny d6958c5
Fix lint
lunny 12feb0e
Add unit test and integration test
lunny 1bffdfe
Merge branch 'main' into lunny/project_workflow
lunny 65dbaa5
Remove log
lunny ae28239
Fix lint and fix wrong migrations
lunny 3719626
improvements
lunny 3aef130
improvements
lunny 4efc69c
Fix dark theme
lunny 3d636fc
fix bug and add label selector
lunny 045945d
Fix label menu
lunny 4a2734a
remove unused code
lunny fdd3bf0
remove unused code
lunny 418a7bb
Add tests for project workflow execution
lunny b04d42b
Merge branch 'main' into lunny/project_workflow
lunny b840641
revert label component change
lunny 3f9f725
revert label component change
lunny b4ebf1b
Fix lint
lunny e21fb90
Fix migration
lunny df50690
Merge branch 'main' into lunny/project_workflow
lunny 0b41bfa
Add valid when saving project workflow event
lunny 984d4b0
Fix lint
lunny 4c4a16c
Merge branch 'main' into lunny/project_workflow
lunny 507c6de
Merge branch 'main' into lunny/project_workflow
lunny c6bd967
Merge branch 'main' into lunny/project_workflow
lunny 7db5b85
fix clone workflow
lunny be143bd
Delete unused code
lunny 883718e
Fix unnecessary comment when moving an issue to the same column
lunny bf841a8
Merge branch 'main' into lunny/project_workflow
lunny 8feb5f9
Merge add labels and remove labels as one operation when firing proje…
lunny 08d2809
Merge branch 'main' into lunny/project_workflow
lunny bc8b385
Merge branch 'main' into lunny/project_workflow
lunny 79c014e
Merge branch 'main' into lunny/project_workflow
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_26 | ||
|
|
||
| import ( | ||
| "code.gitea.io/gitea/modules/timeutil" | ||
|
|
||
| "xorm.io/xorm" | ||
| ) | ||
|
|
||
| func AddProjectWorkflow(x *xorm.Engine) error { | ||
| type ProjectWorkflow struct { | ||
| ID int64 | ||
| ProjectID int64 `xorm:"INDEX"` | ||
| WorkflowEvent string `xorm:"INDEX"` | ||
| WorkflowFilters string `xorm:"TEXT JSON"` | ||
| WorkflowActions string `xorm:"TEXT JSON"` | ||
| Enabled bool `xorm:"DEFAULT true"` | ||
| CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||
| UpdatedUnix timeutil.TimeStamp `xorm:"updated"` | ||
| } | ||
|
|
||
| return x.Sync(&ProjectWorkflow{}) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package project | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "code.gitea.io/gitea/models/db" | ||
| "code.gitea.io/gitea/modules/log" | ||
| "code.gitea.io/gitea/modules/timeutil" | ||
| ) | ||
|
|
||
| type WorkflowEvent string | ||
|
|
||
| const ( | ||
| WorkflowEventItemOpened WorkflowEvent = "item_opened" | ||
| WorkflowEventItemAddedToProject WorkflowEvent = "item_added_to_project" | ||
| WorkflowEventItemRemovedFromProject WorkflowEvent = "item_removed_from_project" | ||
| WorkflowEventItemReopened WorkflowEvent = "item_reopened" | ||
| WorkflowEventItemClosed WorkflowEvent = "item_closed" | ||
| WorkflowEventItemColumnChanged WorkflowEvent = "item_column_changed" | ||
| WorkflowEventCodeChangesRequested WorkflowEvent = "code_changes_requested" | ||
| WorkflowEventCodeReviewApproved WorkflowEvent = "code_review_approved" | ||
| WorkflowEventPullRequestMerged WorkflowEvent = "pull_request_merged" | ||
| ) | ||
|
|
||
| var workflowEvents = []WorkflowEvent{ | ||
| WorkflowEventItemOpened, | ||
| WorkflowEventItemAddedToProject, | ||
| WorkflowEventItemRemovedFromProject, | ||
| WorkflowEventItemReopened, | ||
| WorkflowEventItemClosed, | ||
| WorkflowEventItemColumnChanged, | ||
| WorkflowEventCodeChangesRequested, | ||
| WorkflowEventCodeReviewApproved, | ||
| WorkflowEventPullRequestMerged, | ||
| } | ||
|
|
||
| func GetWorkflowEvents() []WorkflowEvent { | ||
| return workflowEvents | ||
| } | ||
|
|
||
| func IsValidWorkflowEvent(event string) bool { | ||
| for _, we := range workflowEvents { | ||
| if we.EventID() == event { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (we WorkflowEvent) LangKey() string { | ||
| switch we { | ||
| case WorkflowEventItemOpened: | ||
| return "projects.workflows.event.item_opened" | ||
| case WorkflowEventItemAddedToProject: | ||
| return "projects.workflows.event.item_added_to_project" | ||
| case WorkflowEventItemRemovedFromProject: | ||
| return "projects.workflows.event.item_removed_from_project" | ||
| case WorkflowEventItemReopened: | ||
| return "projects.workflows.event.item_reopened" | ||
| case WorkflowEventItemClosed: | ||
| return "projects.workflows.event.item_closed" | ||
| case WorkflowEventItemColumnChanged: | ||
| return "projects.workflows.event.item_column_changed" | ||
| case WorkflowEventCodeChangesRequested: | ||
| return "projects.workflows.event.code_changes_requested" | ||
| case WorkflowEventCodeReviewApproved: | ||
| return "projects.workflows.event.code_review_approved" | ||
| case WorkflowEventPullRequestMerged: | ||
| return "projects.workflows.event.pull_request_merged" | ||
| default: | ||
| return string(we) | ||
| } | ||
| } | ||
|
|
||
| func (we WorkflowEvent) EventID() string { | ||
| return string(we) | ||
| } | ||
|
|
||
| type WorkflowFilterType string | ||
|
|
||
| const ( | ||
| WorkflowFilterTypeIssueType WorkflowFilterType = "issue_type" // issue, pull_request, etc. | ||
| WorkflowFilterTypeSourceColumn WorkflowFilterType = "source_column" // source column for item_column_changed event | ||
| WorkflowFilterTypeTargetColumn WorkflowFilterType = "target_column" // target column for item_column_changed event | ||
| WorkflowFilterTypeLabels WorkflowFilterType = "labels" // filter by issue/PR labels | ||
| ) | ||
|
|
||
| type WorkflowFilter struct { | ||
| Type WorkflowFilterType `json:"type"` | ||
| Value string `json:"value"` | ||
| } | ||
|
|
||
| type WorkflowActionType string | ||
|
|
||
| const ( | ||
| WorkflowActionTypeColumn WorkflowActionType = "column" // add the item to the project's column | ||
| WorkflowActionTypeAddLabels WorkflowActionType = "add_labels" // choose one or more labels | ||
| WorkflowActionTypeRemoveLabels WorkflowActionType = "remove_labels" // choose one or more labels | ||
| WorkflowActionTypeIssueState WorkflowActionType = "issue_state" // change the issue state (reopen/close) | ||
| ) | ||
|
|
||
| type WorkflowAction struct { | ||
| Type WorkflowActionType `json:"type"` | ||
| Value string `json:"value"` | ||
| } | ||
|
|
||
| // WorkflowEventCapabilities defines what filters and actions are available for each event | ||
| type WorkflowEventCapabilities struct { | ||
| AvailableFilters []WorkflowFilterType `json:"available_filters"` | ||
| AvailableActions []WorkflowActionType `json:"available_actions"` | ||
| } | ||
|
|
||
| // GetWorkflowEventCapabilities returns the capabilities for each workflow event | ||
| func GetWorkflowEventCapabilities() map[WorkflowEvent]WorkflowEventCapabilities { | ||
| return map[WorkflowEvent]WorkflowEventCapabilities{ | ||
| WorkflowEventItemOpened: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeLabels}, | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels}, | ||
| }, | ||
| WorkflowEventItemAddedToProject: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeLabels}, | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels, WorkflowActionTypeIssueState}, | ||
| }, | ||
| WorkflowEventItemRemovedFromProject: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeLabels}, | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels, WorkflowActionTypeIssueState}, | ||
| }, | ||
| WorkflowEventItemReopened: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeLabels}, | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels}, | ||
| }, | ||
| WorkflowEventItemClosed: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeLabels}, | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels}, | ||
| }, | ||
| WorkflowEventItemColumnChanged: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeSourceColumn, WorkflowFilterTypeTargetColumn, WorkflowFilterTypeLabels}, | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels, WorkflowActionTypeIssueState}, | ||
| }, | ||
| WorkflowEventCodeChangesRequested: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeLabels}, // only applies to pull requests | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels}, | ||
| }, | ||
| WorkflowEventCodeReviewApproved: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeLabels}, // only applies to pull requests | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels}, | ||
| }, | ||
| WorkflowEventPullRequestMerged: { | ||
| AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeLabels}, // only applies to pull requests | ||
| AvailableActions: []WorkflowActionType{WorkflowActionTypeColumn, WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| type Workflow struct { | ||
| ID int64 | ||
| ProjectID int64 `xorm:"INDEX"` | ||
| Project *Project `xorm:"-"` | ||
| WorkflowEvent WorkflowEvent `xorm:"INDEX"` | ||
| WorkflowFilters []WorkflowFilter `xorm:"TEXT JSON"` | ||
| WorkflowActions []WorkflowAction `xorm:"TEXT JSON"` | ||
| Enabled bool `xorm:"DEFAULT true"` | ||
| CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||
| UpdatedUnix timeutil.TimeStamp `xorm:"updated"` | ||
| } | ||
|
|
||
| // TableName overrides the table name used by ProjectWorkflow to `project_workflow` | ||
| func (Workflow) TableName() string { | ||
| return "project_workflow" | ||
| } | ||
|
|
||
| func (p *Workflow) LoadProject(ctx context.Context) error { | ||
| if p.Project != nil || p.ProjectID <= 0 { | ||
| return nil | ||
| } | ||
| project, err := GetProjectByID(ctx, p.ProjectID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| p.Project = project | ||
| return nil | ||
| } | ||
|
|
||
| func (p *Workflow) Link(ctx context.Context) string { | ||
| if err := p.LoadProject(ctx); err != nil { | ||
| log.Error("ProjectWorkflow Link: %v", err) | ||
| return "" | ||
| } | ||
| return p.Project.Link(ctx) + fmt.Sprintf("/workflows/%d", p.ID) | ||
| } | ||
|
|
||
| func init() { | ||
| db.RegisterModel(new(Workflow)) | ||
| } | ||
|
|
||
| func FindWorkflowsByProjectID(ctx context.Context, projectID int64) ([]*Workflow, error) { | ||
| workflows := make([]*Workflow, 0) | ||
| if err := db.GetEngine(ctx).Where("project_id=?", projectID).Find(&workflows); err != nil { | ||
| return nil, err | ||
| } | ||
| return workflows, nil | ||
| } | ||
|
|
||
| func GetWorkflowByID(ctx context.Context, id int64) (*Workflow, error) { | ||
| p, exist, err := db.GetByID[Workflow](ctx, id) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !exist { | ||
| return nil, db.ErrNotExist{Resource: "ProjectWorkflow", ID: id} | ||
| } | ||
| return p, nil | ||
| } | ||
|
|
||
| func CreateWorkflow(ctx context.Context, wf *Workflow) error { | ||
| return db.Insert(ctx, wf) | ||
| } | ||
|
|
||
| func UpdateWorkflow(ctx context.Context, wf *Workflow) error { | ||
| _, err := db.GetEngine(ctx).ID(wf.ID).Cols("workflow_filters", "workflow_actions").Update(wf) | ||
| return err | ||
| } | ||
|
|
||
| func DeleteWorkflow(ctx context.Context, id int64) error { | ||
| _, err := db.GetEngine(ctx).ID(id).Delete(&Workflow{}) | ||
| return err | ||
| } | ||
|
|
||
| func EnableWorkflow(ctx context.Context, id int64) error { | ||
| _, err := db.GetEngine(ctx).ID(id).Cols("enabled").Update(&Workflow{Enabled: true}) | ||
| return err | ||
| } | ||
|
|
||
| func DisableWorkflow(ctx context.Context, id int64) error { | ||
| _, err := db.GetEngine(ctx).ID(id).Cols("enabled").Update(&Workflow{Enabled: false}) | ||
| return err | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WorkflowEvent string `xorm:"INDEX"`I don't think such index can work.