Skip to content

Commit

Permalink
Merge pull request #43 from get-glu/gm/fix-promote-endpoint
Browse files Browse the repository at this point in the history
fix(ui): call correct promote endpoint
  • Loading branch information
GeorgeMac authored Nov 20, 2024
2 parents ca9cc05 + ce3a8ed commit e6c8dd7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"io/fs"
"log/slog"
"net/http"

"github.com/get-glu/glu/pkg/core"
Expand Down Expand Up @@ -159,6 +160,7 @@ func (s *Server) listPipelines(w http.ResponseWriter, r *http.Request) {
for _, pipeline := range s.system.pipelines {
response, err := s.createPipelineResponse(ctx, pipeline)
if err != nil {
slog.Error("building pipeline response", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -169,6 +171,7 @@ func (s *Server) listPipelines(w http.ResponseWriter, r *http.Request) {
if err := json.NewEncoder(w).Encode(listPipelinesResponse{
Pipelines: pipelineResponses,
}); err != nil {
slog.Error("encoding pipeline", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -179,12 +182,14 @@ func (s *Server) getPipeline(w http.ResponseWriter, r *http.Request) {

pipeline, err := s.system.GetPipeline(chi.URLParam(r, "pipeline"))
if err != nil {
slog.Debug("resource not found", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusNotFound)
return
}

response, err := s.createPipelineResponse(ctx, pipeline)
if err != nil {
slog.Error("building pipeline response", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -204,6 +209,7 @@ func (s *Server) getPhase(w http.ResponseWriter, r *http.Request) {
if err != nil {
status := http.StatusInternalServerError
if errors.Is(err, core.ErrNotFound) {
slog.Debug("resource not found", "path", r.URL.Path, "error", err)
status = http.StatusNotFound
}

Expand All @@ -221,6 +227,7 @@ func (s *Server) getPhase(w http.ResponseWriter, r *http.Request) {
response.Value = v

if err := json.NewEncoder(w).Encode(response); err != nil {
slog.Error("encoding response", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand All @@ -229,6 +236,7 @@ func (s *Server) getPhase(w http.ResponseWriter, r *http.Request) {
func (s *Server) promotePhase(w http.ResponseWriter, r *http.Request) {
pipeline, err := s.system.GetPipeline(chi.URLParam(r, "pipeline"))
if err != nil {
slog.Debug("resource not found", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusNotFound)
return
}
Expand All @@ -238,6 +246,7 @@ func (s *Server) promotePhase(w http.ResponseWriter, r *http.Request) {
if err != nil {
status := http.StatusInternalServerError
if errors.Is(err, core.ErrNotFound) {
slog.Debug("resource not found", "path", r.URL.Path, "error", err)
status = http.StatusNotFound
}

Expand All @@ -246,6 +255,7 @@ func (s *Server) promotePhase(w http.ResponseWriter, r *http.Request) {
}

if err := phase.Promote(r.Context()); err != nil {
slog.Error("performing promotion", "path", r.URL.Path, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"source": "src/index.html",
"scripts": {
"start": "parcel --no-cache",
"build": "parcel build",
"build": "parcel build --no-cache",
"lint": "eslint --fix .",
"format": "prettier --write ."
},
Expand Down
2 changes: 1 addition & 1 deletion ui/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const listPipelines = async (): Promise<Pipeline[]> => {
};

export const promotePhase = async (pipeline: string, phase: string) => {
const response = await api.post(`/pipelines/${pipeline}/phase/${phase}/promote`);
const response = await api.post(`/pipelines/${pipeline}/phases/${phase}/promote`);
if (response.status !== 200) {
throw new Error(`unexpected status ${response.status}`);
}
Expand Down

0 comments on commit e6c8dd7

Please sign in to comment.