Skip to content

Commit 903d605

Browse files
committed
improvements
1 parent c2419f8 commit 903d605

File tree

6 files changed

+56
-122
lines changed

6 files changed

+56
-122
lines changed

models/project/workflows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (we WorkflowEvent) LangKey() string {
6464
}
6565
}
6666

67-
func (we WorkflowEvent) UUID() string {
67+
func (we WorkflowEvent) EventID() string {
6868
switch we {
6969
case WorkflowEventItemOpened:
7070
return "item_opened"
@@ -90,9 +90,9 @@ func (we WorkflowEvent) UUID() string {
9090
type WorkflowFilterType string
9191

9292
const (
93-
WorkflowFilterTypeIssueType WorkflowFilterType = "issue_type" // issue, pull_request, etc.
94-
WorkflowFilterTypeColumn WorkflowFilterType = "column" // target column for item_column_changed event
95-
WorkflowFilterTypeLabels WorkflowFilterType = "labels" // filter by issue/PR labels
93+
WorkflowFilterTypeIssueType WorkflowFilterType = "issue_type" // issue, pull_request, etc.
94+
WorkflowFilterTypeColumn WorkflowFilterType = "target_column" // target column for item_column_changed event
95+
WorkflowFilterTypeLabels WorkflowFilterType = "labels" // filter by issue/PR labels
9696
)
9797

9898
type WorkflowFilter struct {

routers/web/projects/workflows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func getFilterSummary(ctx stdCtx.Context, filters []project_model.WorkflowFilter
5252
log.Error("GetColumn: %v", err)
5353
continue
5454
}
55-
summary.WriteString(" (Column: " + col.Title + ")")
55+
summary.WriteString(" (Target Column: " + col.Title + ")")
5656
case project_model.WorkflowFilterTypeLabels:
5757
labelID, _ := strconv.ParseInt(filter.Value, 10, 64)
5858
if labelID > 0 {
@@ -243,7 +243,7 @@ func WorkflowsEvents(ctx *context.Context) {
243243
outputWorkflows = append(outputWorkflows, &WorkflowConfig{
244244
ID: wf.ID,
245245
EventID: strconv.FormatInt(wf.ID, 10),
246-
DisplayName: string(ctx.Tr(wf.WorkflowEvent.LangKey())) + filterSummary,
246+
DisplayName: string(ctx.Tr(wf.WorkflowEvent.LangKey())),
247247
BaseEventType: string(wf.WorkflowEvent),
248248
WorkflowEvent: string(wf.WorkflowEvent),
249249
Capabilities: capabilities[event],
@@ -258,7 +258,7 @@ func WorkflowsEvents(ctx *context.Context) {
258258
// Add placeholder for creating new workflow
259259
outputWorkflows = append(outputWorkflows, &WorkflowConfig{
260260
ID: 0,
261-
EventID: event.UUID(),
261+
EventID: event.EventID(),
262262
DisplayName: string(ctx.Tr(event.LangKey())),
263263
BaseEventType: string(event),
264264
WorkflowEvent: string(event),
@@ -514,7 +514,7 @@ func WorkflowsPost(ctx *context.Context) {
514514
"workflow": map[string]any{
515515
"id": wf.ID,
516516
"event_id": strconv.FormatInt(wf.ID, 10),
517-
"display_name": string(ctx.Tr(wf.WorkflowEvent.LangKey())) + filterSummary,
517+
"display_name": string(ctx.Tr(wf.WorkflowEvent.LangKey())),
518518
"filters": wf.WorkflowFilters,
519519
"actions": wf.WorkflowActions,
520520
"filter_summary": filterSummary,

services/projects/workflow_notifier.go

Lines changed: 23 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (m *workflowNotifier) NewIssue(ctx context.Context, issue *issues_model.Iss
5555
// Find workflows for the ItemOpened event
5656
for _, workflow := range workflows {
5757
if workflow.WorkflowEvent == project_model.WorkflowEventItemOpened {
58-
fireIssueWorkflow(ctx, workflow, issue)
58+
fireIssueWorkflow(ctx, workflow, issue, 0)
5959
}
6060
}
6161
}
@@ -92,7 +92,7 @@ func (m *workflowNotifier) IssueChangeStatus(ctx context.Context, doer *user_mod
9292
// Find workflows for the specific event
9393
for _, workflow := range workflows {
9494
if workflow.WorkflowEvent == workflowEvent {
95-
fireIssueWorkflow(ctx, workflow, issue)
95+
fireIssueWorkflow(ctx, workflow, issue, 0)
9696
}
9797
}
9898
}
@@ -124,7 +124,7 @@ func (*workflowNotifier) IssueChangeProjects(ctx context.Context, doer *user_mod
124124
// Find workflows for the ItemOpened event
125125
for _, workflow := range workflows {
126126
if workflow.WorkflowEvent == project_model.WorkflowEventItemAddedToProject {
127-
fireIssueWorkflow(ctx, workflow, issue)
127+
fireIssueWorkflow(ctx, workflow, issue, 0)
128128
}
129129
}
130130
}
@@ -158,7 +158,7 @@ func (*workflowNotifier) IssueChangeProjectColumn(ctx context.Context, doer *use
158158
// Find workflows for the ItemColumnChanged event
159159
for _, workflow := range workflows {
160160
if workflow.WorkflowEvent == project_model.WorkflowEventItemColumnChanged {
161-
fireIssueWorkflowWithColumn(ctx, workflow, issue, newColumnID)
161+
fireIssueWorkflow(ctx, workflow, issue, newColumnID)
162162
}
163163
}
164164
}
@@ -192,7 +192,7 @@ func (*workflowNotifier) MergePullRequest(ctx context.Context, doer *user_model.
192192
// Find workflows for the PullRequestMerged event
193193
for _, workflow := range workflows {
194194
if workflow.WorkflowEvent == project_model.WorkflowEventPullRequestMerged {
195-
fireIssueWorkflow(ctx, workflow, issue)
195+
fireIssueWorkflow(ctx, workflow, issue, 0)
196196
}
197197
}
198198
}
@@ -231,14 +231,12 @@ func (*workflowNotifier) PullRequestReview(ctx context.Context, pr *issues_model
231231
for _, workflow := range workflows {
232232
if (workflow.WorkflowEvent == project_model.WorkflowEventCodeChangesRequested && review.Type == issues_model.ReviewTypeReject) ||
233233
(workflow.WorkflowEvent == project_model.WorkflowEventCodeReviewApproved && review.Type == issues_model.ReviewTypeApprove) {
234-
fireIssueWorkflow(ctx, workflow, issue)
234+
fireIssueWorkflow(ctx, workflow, issue, 0)
235235
}
236236
}
237237
}
238238

239-
// fireIssueWorkflowWithColumn fires a workflow for an issue with a specific column ID
240-
// This is used for ItemColumnChanged events where we need to check the target column
241-
func fireIssueWorkflowWithColumn(ctx context.Context, workflow *project_model.Workflow, issue *issues_model.Issue, columnID int64) {
239+
func fireIssueWorkflow(ctx context.Context, workflow *project_model.Workflow, issue *issues_model.Issue, columnID int64) {
242240
if !workflow.Enabled {
243241
return
244242
}
@@ -249,72 +247,15 @@ func fireIssueWorkflowWithColumn(ctx context.Context, workflow *project_model.Wo
249247
return
250248
}
251249

252-
for _, filter := range workflow.WorkflowFilters {
253-
switch filter.Type {
254-
case project_model.WorkflowFilterTypeIssueType:
255-
// If filter value is empty, match all types
256-
if filter.Value == "" {
257-
continue
258-
}
259-
// Filter value can be "issue" or "pull_request"
260-
if filter.Value == "issue" && issue.IsPull {
261-
return
262-
}
263-
if filter.Value == "pull_request" && !issue.IsPull {
264-
return
265-
}
266-
case project_model.WorkflowFilterTypeColumn:
267-
// If filter value is empty, match all columns
268-
if filter.Value == "" {
269-
continue
270-
}
271-
filterColumnID, _ := strconv.ParseInt(filter.Value, 10, 64)
272-
if filterColumnID == 0 {
273-
log.Error("Invalid column ID: %s", filter.Value)
274-
return
275-
}
276-
// For column changed event, check against the new column ID
277-
if columnID != filterColumnID {
278-
return
279-
}
280-
case project_model.WorkflowFilterTypeLabels:
281-
// Check if issue has the specified label
282-
labelID, _ := strconv.ParseInt(filter.Value, 10, 64)
283-
if labelID == 0 {
284-
log.Error("Invalid label ID: %s", filter.Value)
285-
return
286-
}
287-
// Check if issue has this label
288-
hasLabel := false
289-
for _, label := range issue.Labels {
290-
if label.ID == labelID {
291-
hasLabel = true
292-
break
293-
}
294-
}
295-
if !hasLabel {
296-
return
297-
}
298-
default:
299-
log.Error("Unsupported filter type: %s", filter.Type)
300-
return
301-
}
250+
if !matchWorkflowsFilters(workflow, issue, columnID) {
251+
return
302252
}
303253

304254
executeWorkflowActions(ctx, workflow, issue)
305255
}
306256

307-
func fireIssueWorkflow(ctx context.Context, workflow *project_model.Workflow, issue *issues_model.Issue) {
308-
if !workflow.Enabled {
309-
return
310-
}
311-
312-
// Load issue labels for labels filter
313-
if err := issue.LoadLabels(ctx); err != nil {
314-
log.Error("LoadLabels: %v", err)
315-
return
316-
}
317-
257+
// matchWorkflowsFilters checks if the issue matches all filters of the workflow
258+
func matchWorkflowsFilters(workflow *project_model.Workflow, issue *issues_model.Issue, columnID int64) bool {
318259
for _, filter := range workflow.WorkflowFilters {
319260
switch filter.Type {
320261
case project_model.WorkflowFilterTypeIssueType:
@@ -324,35 +265,31 @@ func fireIssueWorkflow(ctx context.Context, workflow *project_model.Workflow, is
324265
}
325266
// Filter value can be "issue" or "pull_request"
326267
if filter.Value == "issue" && issue.IsPull {
327-
return
268+
return false
328269
}
329270
if filter.Value == "pull_request" && !issue.IsPull {
330-
return
271+
return false
331272
}
332273
case project_model.WorkflowFilterTypeColumn:
333274
// If filter value is empty, match all columns
334275
if filter.Value == "" {
335276
continue
336277
}
337-
columnID, _ := strconv.ParseInt(filter.Value, 10, 64)
338-
if columnID == 0 {
278+
filterColumnID, _ := strconv.ParseInt(filter.Value, 10, 64)
279+
if filterColumnID == 0 {
339280
log.Error("Invalid column ID: %s", filter.Value)
340-
return
341-
}
342-
issueProjectColumnID, err := issue.ProjectColumnID(ctx)
343-
if err != nil {
344-
log.Error("Issue.ProjectColumnID: %v", err)
345-
return
281+
return false
346282
}
347-
if issueProjectColumnID != columnID {
348-
return
283+
// For column changed event, check against the new column ID
284+
if columnID > 0 && columnID != filterColumnID {
285+
return false
349286
}
350287
case project_model.WorkflowFilterTypeLabels:
351288
// Check if issue has the specified label
352289
labelID, _ := strconv.ParseInt(filter.Value, 10, 64)
353290
if labelID == 0 {
354291
log.Error("Invalid label ID: %s", filter.Value)
355-
return
292+
return false
356293
}
357294
// Check if issue has this label
358295
hasLabel := false
@@ -363,15 +300,14 @@ func fireIssueWorkflow(ctx context.Context, workflow *project_model.Workflow, is
363300
}
364301
}
365302
if !hasLabel {
366-
return
303+
return false
367304
}
368305
default:
369306
log.Error("Unsupported filter type: %s", filter.Type)
370-
return
307+
return false
371308
}
372309
}
373-
374-
executeWorkflowActions(ctx, workflow, issue)
310+
return true
375311
}
376312

377313
func executeWorkflowActions(ctx context.Context, workflow *project_model.Workflow, issue *issues_model.Issue) {

templates/repo/projects/workflows.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{{template "repo/header" .}}
44
<div class="ui container padded">
55
<div class="tw-flex tw-justify-between tw-items-center tw-mb-4">
6-
<a class="ui" href="{{.ProjectLink}}">{{svg "octicon-arrow-left"}} {{ctx.Locale.Tr "projects.workflows"}} {{.Project.Title}}</a>
7-
</div>
6+
<a class="ui" href="{{.ProjectLink}}">{{svg "octicon-arrow-left"}} {{ctx.Locale.Tr "projects.workflows"}} {{.Project.Title}}</a>
7+
</div>
88
</div>
99
{{template "projects/workflows" .}}
1010
</div>

web_src/js/components/projects/ProjectWorkflow.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,11 @@ onUnmounted(() => {
829829
</div>
830830
</div>
831831

832-
<div class="field" v-if="hasFilter('column')">
832+
<div class="field" v-if="hasFilter('target_column')">
833833
<label>When moved to column</label>
834834
<select
835835
v-if="isInEditMode"
836-
v-model="store.workflowFilters.column"
836+
v-model="store.workflowFilters.target_column"
837837
class="column-select"
838838
>
839839
<option value="">Any column</option>
@@ -842,7 +842,7 @@ onUnmounted(() => {
842842
</option>
843843
</select>
844844
<div v-else class="readonly-value">
845-
{{ store.projectColumns.find(c => String(c.id) === store.workflowFilters.column)?.title || 'Any column' }}
845+
{{ store.projectColumns.find(c => String(c.id) === store.workflowFilters.target_column)?.title || 'Any column' }}
846846
</div>
847847
</div>
848848

0 commit comments

Comments
 (0)