Skip to content

Commit c2419f8

Browse files
committed
improvements
1 parent 623388c commit c2419f8

File tree

7 files changed

+61
-39
lines changed

7 files changed

+61
-39
lines changed

models/project/project.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func (err ErrProjectNotExist) Unwrap() error {
7070
type ErrProjectColumnNotExist struct {
7171
ColumnID int64
7272
ProjectID int64
73-
Name string
7473
}
7574

7675
// IsErrProjectColumnNotExist checks if an error is a ErrProjectColumnNotExist
@@ -80,8 +79,8 @@ func IsErrProjectColumnNotExist(err error) bool {
8079
}
8180

8281
func (err ErrProjectColumnNotExist) Error() string {
83-
if err.ProjectID > 0 && len(err.Name) > 0 {
84-
return fmt.Sprintf("project column does not exist [project_id: %d, name: %s]", err.ProjectID, err.Name)
82+
if err.ProjectID > 0 {
83+
return fmt.Sprintf("project column does not exist [project_id: %d, column_id: %d]", err.ProjectID, err.ColumnID)
8584
}
8685
return fmt.Sprintf("project column does not exist [id: %d]", err.ColumnID)
8786
}

models/project/workflows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const (
106106
WorkflowActionTypeColumn WorkflowActionType = "column" // add the item to the project's column
107107
WorkflowActionTypeAddLabels WorkflowActionType = "add_labels" // choose one or more labels
108108
WorkflowActionTypeRemoveLabels WorkflowActionType = "remove_labels" // choose one or more labels
109-
WorkflowActionTypeClose WorkflowActionType = "close" // close the issue
109+
WorkflowActionTypeIssueState WorkflowActionType = "issue_state" // change the issue state (reopen/close)
110110
)
111111

112112
type WorkflowAction struct {
@@ -141,7 +141,7 @@ func GetWorkflowEventCapabilities() map[WorkflowEvent]WorkflowEventCapabilities
141141
},
142142
WorkflowEventItemColumnChanged: {
143143
AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeIssueType, WorkflowFilterTypeColumn, WorkflowFilterTypeLabels},
144-
AvailableActions: []WorkflowActionType{WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels, WorkflowActionTypeClose},
144+
AvailableActions: []WorkflowActionType{WorkflowActionTypeAddLabels, WorkflowActionTypeRemoveLabels, WorkflowActionTypeIssueState},
145145
},
146146
WorkflowEventCodeChangesRequested: {
147147
AvailableFilters: []WorkflowFilterType{WorkflowFilterTypeLabels}, // only applies to pull requests

routers/web/projects/workflows.go

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package projects
55

66
import (
7+
stdCtx "context"
78
"errors"
89
"io"
910
"net/http"
@@ -25,22 +26,56 @@ var (
2526
)
2627

2728
// getFilterSummary returns a human-readable summary of the filters
28-
func getFilterSummary(filters []project_model.WorkflowFilter) string {
29+
func getFilterSummary(ctx stdCtx.Context, filters []project_model.WorkflowFilter) string {
2930
if len(filters) == 0 {
3031
return ""
3132
}
3233

34+
var summary strings.Builder
35+
labelIDs := make([]int64, 0)
3336
for _, filter := range filters {
34-
if filter.Type == "scope" {
37+
switch filter.Type {
38+
case project_model.WorkflowFilterTypeIssueType:
3539
switch filter.Value {
3640
case "issue":
37-
return " (Issues only)"
41+
summary.WriteString(" (Issues only)")
3842
case "pull_request":
39-
return " (Pull requests only)"
43+
summary.WriteString(" (Pull requests only)")
44+
}
45+
case project_model.WorkflowFilterTypeColumn:
46+
columnID, _ := strconv.ParseInt(filter.Value, 10, 64)
47+
if columnID <= 0 {
48+
continue
49+
}
50+
col, err := project_model.GetColumn(ctx, columnID)
51+
if err != nil {
52+
log.Error("GetColumn: %v", err)
53+
continue
54+
}
55+
summary.WriteString(" (Column: " + col.Title + ")")
56+
case project_model.WorkflowFilterTypeLabels:
57+
labelID, _ := strconv.ParseInt(filter.Value, 10, 64)
58+
if labelID > 0 {
59+
labelIDs = append(labelIDs, labelID)
4060
}
4161
}
4262
}
43-
return ""
63+
if len(labelIDs) > 0 {
64+
labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs)
65+
if err != nil {
66+
log.Error("GetLabelsByIDs: %v", err)
67+
} else {
68+
summary.WriteString(" (Labels: ")
69+
for i, label := range labels {
70+
summary.WriteString(label.Name)
71+
if i < len(labels)-1 {
72+
summary.WriteString(", ")
73+
}
74+
}
75+
summary.WriteString(")")
76+
}
77+
}
78+
return summary.String()
4479
}
4580

4681
// convertFormToFilters converts form filters to WorkflowFilter objects
@@ -133,28 +168,16 @@ func convertFormToActions(formActions map[string]any) []project_model.WorkflowAc
133168
}
134169
}
135170
}
136-
case "issueState":
171+
case "issue_state":
137172
if strValue, ok := value.(string); ok {
138-
switch strings.ToLower(strValue) {
139-
case "close", "closed", "true":
140-
actions = append(actions, project_model.WorkflowAction{
141-
Type: project_model.WorkflowActionTypeClose,
142-
Value: "close",
143-
})
144-
case "reopen", "open", "false":
173+
v := strings.ToLower(strValue)
174+
if v == "close" || v == "reopen" {
145175
actions = append(actions, project_model.WorkflowAction{
146-
Type: project_model.WorkflowActionTypeClose,
147-
Value: "reopen",
176+
Type: project_model.WorkflowActionTypeIssueState,
177+
Value: v,
148178
})
149179
}
150180
}
151-
case "closeIssue":
152-
if boolValue, ok := value.(bool); ok && boolValue {
153-
actions = append(actions, project_model.WorkflowAction{
154-
Type: project_model.WorkflowActionTypeClose,
155-
Value: "close",
156-
})
157-
}
158181
}
159182
}
160183

@@ -216,7 +239,7 @@ func WorkflowsEvents(ctx *context.Context) {
216239
if len(existingWorkflows) > 0 {
217240
// Add all existing workflows for this event
218241
for _, wf := range existingWorkflows {
219-
filterSummary := getFilterSummary(wf.WorkflowFilters)
242+
filterSummary := getFilterSummary(ctx, wf.WorkflowFilters)
220243
outputWorkflows = append(outputWorkflows, &WorkflowConfig{
221244
ID: wf.ID,
222245
EventID: strconv.FormatInt(wf.ID, 10),
@@ -485,7 +508,7 @@ func WorkflowsPost(ctx *context.Context) {
485508
}
486509

487510
// Return the newly created workflow with filter summary
488-
filterSummary := getFilterSummary(wf.WorkflowFilters)
511+
filterSummary := getFilterSummary(ctx, wf.WorkflowFilters)
489512
ctx.JSON(http.StatusOK, map[string]any{
490513
"success": true,
491514
"workflow": map[string]any{
@@ -518,7 +541,7 @@ func WorkflowsPost(ctx *context.Context) {
518541
}
519542

520543
// Return the updated workflow with filter summary
521-
filterSummary := getFilterSummary(wf.WorkflowFilters)
544+
filterSummary := getFilterSummary(ctx, wf.WorkflowFilters)
522545
ctx.JSON(http.StatusOK, map[string]any{
523546
"success": true,
524547
"workflow": map[string]any{

routers/web/repo/projects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func UpdateIssueProject(ctx *context.Context) {
447447
if issue.Project != nil && issue.Project.ID == projectID {
448448
continue
449449
}
450-
if err := issues_servie.IssueAssignOrRemoveProject(ctx, issue, ctx.Doer, projectID, 0); err != nil {
450+
if err := issues_servie.AssignOrRemoveProject(ctx, issue, ctx.Doer, projectID, 0); err != nil {
451451
if errors.Is(err, util.ErrPermissionDenied) {
452452
continue
453453
}

services/issue/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"code.gitea.io/gitea/services/notify"
1313
)
1414

15-
func IssueAssignOrRemoveProject(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, projectID int64, position int) error {
15+
func AssignOrRemoveProject(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, projectID int64, position int) error {
1616
if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, doer, projectID, 0); err != nil {
1717
return err
1818
}

services/projects/workflow_notifier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,16 @@ func executeWorkflowActions(ctx context.Context, workflow *project_model.Workflo
424424
}
425425
continue
426426
}
427-
case project_model.WorkflowActionTypeClose:
428-
if strings.EqualFold(action.Value, "reopen") || strings.EqualFold(action.Value, "false") {
427+
case project_model.WorkflowActionTypeIssueState:
428+
if strings.EqualFold(action.Value, "reopen") {
429429
if issue.IsClosed {
430430
if err := issue_service.ReopenIssue(ctx, issue, user_model.NewProjectWorkflowsUser(), ""); err != nil {
431431
log.Error("ReopenIssue: %v", err)
432432
continue
433433
}
434434
issue.IsClosed = false
435435
}
436-
} else {
436+
} else if strings.EqualFold(action.Value, "close") {
437437
if !issue.IsClosed {
438438
if err := issue_service.CloseIssue(ctx, issue, user_model.NewProjectWorkflowsUser(), ""); err != nil {
439439
log.Error("CloseIssue: %v", err)

web_src/js/components/projects/ProjectWorkflow.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -977,21 +977,21 @@ onUnmounted(() => {
977977
</div>
978978
</div>
979979

980-
<div class="field" v-if="hasAction('close')">
980+
<div class="field" v-if="hasAction('issue_state')">
981981
<label for="issue-state-action">Issue state</label>
982982
<select
983983
v-if="isInEditMode"
984984
id="issue-state-action"
985985
class="column-select"
986-
v-model="store.workflowActions.issueState"
986+
v-model="store.workflowActions.issue_state"
987987
>
988988
<option value="">No change</option>
989989
<option value="close">Close issue</option>
990990
<option value="reopen">Reopen issue</option>
991991
</select>
992992
<div v-else class="readonly-value">
993-
{{ store.workflowActions.issueState === 'close' ? 'Close issue' :
994-
store.workflowActions.issueState === 'reopen' ? 'Reopen issue' : 'No change' }}
993+
{{ store.workflowActions.issue_state === 'close' ? 'Close issue' :
994+
store.workflowActions.issue_state === 'reopen' ? 'Reopen issue' : 'No change' }}
995995
</div>
996996
</div>
997997
</div>

0 commit comments

Comments
 (0)