tenseleyflow/shithub / c9e34c2

Browse files

api/actions_workflows: surface disabled state in list response

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
c9e34c268f706210a8cadf7d7c9e3a48a83a58cd
Parents
7633c43
Tree
30a421c

1 changed file

StatusFile+-
M internal/web/handlers/api/actions_workflows.go 16 1
internal/web/handlers/api/actions_workflows.gomodified
@@ -16,6 +16,7 @@ import (
1616
 
1717
 	"github.com/tenseleyFlow/shithub/internal/actions/dispatch"
1818
 	actionsevent "github.com/tenseleyFlow/shithub/internal/actions/event"
19
+	actionsdb "github.com/tenseleyFlow/shithub/internal/actions/sqlc"
1920
 	"github.com/tenseleyFlow/shithub/internal/actions/trigger"
2021
 	"github.com/tenseleyFlow/shithub/internal/actions/workflow"
2122
 	"github.com/tenseleyFlow/shithub/internal/auth/pat"
@@ -105,9 +106,23 @@ func (h *Handlers) actionsWorkflowsList(w http.ResponseWriter, r *http.Request)
105106
 		writeAPIError(w, http.StatusInternalServerError, "list failed")
106107
 		return
107108
 	}
109
+	disabled, err := actionsdb.New().ListDisabledWorkflowsForRepo(r.Context(), h.d.Pool, repo.ID)
110
+	if err != nil {
111
+		h.d.Logger.ErrorContext(r.Context(), "api: list disabled workflows", "error", err)
112
+		writeAPIError(w, http.StatusInternalServerError, "list failed")
113
+		return
114
+	}
115
+	disabledSet := make(map[string]struct{}, len(disabled))
116
+	for _, f := range disabled {
117
+		disabledSet[f] = struct{}{}
118
+	}
108119
 	out := make([]workflowResponse, 0, len(files))
109120
 	for _, f := range files {
110
-		out = append(out, presentWorkflow(f))
121
+		wr := presentWorkflow(f)
122
+		if _, off := disabledSet[f.Path]; off {
123
+			wr.State = "disabled"
124
+		}
125
+		out = append(out, wr)
111126
 	}
112127
 	sort.Slice(out, func(i, j int) bool { return out[i].Path < out[j].Path })
113128
 	writeJSON(w, http.StatusOK, out)