Skip to content

Commit

Permalink
Merge pull request #2552 from MahtabBukhari/Update_Ticket_Builder_Sen…
Browse files Browse the repository at this point in the history
…d_to_Stakwork_Payload_to_include_code_graph_details

Update Ticket Builder "Send to Stakwork" Payload to include code graph details
  • Loading branch information
humansinstitute authored Feb 13, 2025
2 parents 6e1bf8b + 99606b2 commit 894d16c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 43 deletions.
10 changes: 5 additions & 5 deletions db/code_graphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ func (db database) GetCodeGraphByUUID(uuid string) (WorkspaceCodeGraph, error) {
return codeGraph, nil
}

func (db database) GetCodeGraphsByWorkspaceUuid(workspace_uuid string) ([]WorkspaceCodeGraph, error) {
var codeGraphs []WorkspaceCodeGraph
result := db.db.Where("workspace_uuid = ?", workspace_uuid).Find(&codeGraphs)
func (db database) GetCodeGraphByWorkspaceUuid(workspace_uuid string) (WorkspaceCodeGraph, error) {
var codeGraph WorkspaceCodeGraph
result := db.db.Where("workspace_uuid = ?", workspace_uuid).Order("created DESC").First(&codeGraph)

if result.Error != nil {
return nil, result.Error
return WorkspaceCodeGraph{}, result.Error
}

return codeGraphs, nil
return codeGraph, nil
}

func (db database) CreateOrEditCodeGraph(m WorkspaceCodeGraph) (WorkspaceCodeGraph, error) {
Expand Down
2 changes: 1 addition & 1 deletion db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type Database interface {
GetChatMessagesForChatID(chatID string) ([]ChatMessage, error)
GetChatsForWorkspace(workspaceID string, chatStatus string) ([]Chat, error)
GetCodeGraphByUUID(uuid string) (WorkspaceCodeGraph, error)
GetCodeGraphsByWorkspaceUuid(workspace_uuid string) ([]WorkspaceCodeGraph, error)
GetCodeGraphByWorkspaceUuid(workspace_uuid string) (WorkspaceCodeGraph, error)
CreateOrEditCodeGraph(m WorkspaceCodeGraph) (WorkspaceCodeGraph, error)
DeleteCodeGraph(workspace_uuid string, uuid string) error
GetTicketsWithoutGroup() ([]Tickets, error)
Expand Down
16 changes: 8 additions & 8 deletions handlers/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ type FileResponse struct {
}

type SendMessageRequest struct {
ChatID string `json:"chat_id"`
Message string `json:"message"`
PDFURL string `json:"pdf_url,omitempty"`
ModelSelection string `json:"modelSelection,omitempty"`
ContextTags []struct {
ChatID string `json:"chat_id"`
Message string `json:"message"`
PDFURL string `json:"pdf_url,omitempty"`
ModelSelection string `json:"modelSelection,omitempty"`
ContextTags []struct {
Type string `json:"type"`
ID string `json:"id"`
} `json:"contextTags"`
Expand Down Expand Up @@ -355,9 +355,9 @@ func (ch *ChatHandler) SendMessage(w http.ResponseWriter, r *http.Request) {

var codeGraph *db.WorkspaceCodeGraph
if workspaceID := request.WorkspaceUUID; workspaceID != "" {
codeGraphs, err := ch.db.GetCodeGraphsByWorkspaceUuid(workspaceID)
if err == nil && len(codeGraphs) > 0 {
codeGraph = &codeGraphs[0]
codeGraphResult, err := ch.db.GetCodeGraphByWorkspaceUuid(workspaceID)
if err == nil {
codeGraph = &codeGraphResult
}
}

Expand Down
4 changes: 2 additions & 2 deletions handlers/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (th *ticketHandler) PostTicketDataToStakwork(w http.ResponseWriter, r *http

var (
productBrief, featureBrief, featureArchitecture, codeGraphURL, codeGraphAlias string
feature db.WorkspaceFeatures
feature db.WorkspaceFeatures
)

if ticket.FeatureUUID != "" {
Expand Down Expand Up @@ -461,7 +461,7 @@ func (th *ticketHandler) PostTicketDataToStakwork(w http.ResponseWriter, r *http

schematicURL = workspace.SchematicUrl

codeGraph, err := th.db.GetCodeGraphByUUID(feature.WorkspaceUuid)
codeGraph, err := th.db.GetCodeGraphByWorkspaceUuid(feature.WorkspaceUuid)
if err == nil {
codeGraphURL = codeGraph.Url
codeGraphAlias = codeGraph.SecretAlias
Expand Down
6 changes: 3 additions & 3 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ func (oh *workspaceHandler) GetWorkspaceCodeGraphByUUID(w http.ResponseWriter, r
json.NewEncoder(w).Encode(codeGraph)
}

func (oh *workspaceHandler) GetCodeGraphsByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
func (oh *workspaceHandler) GetCodeGraphByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
Expand All @@ -1240,15 +1240,15 @@ func (oh *workspaceHandler) GetCodeGraphsByWorkspaceUuid(w http.ResponseWriter,
}

workspace_uuid := chi.URLParam(r, "workspace_uuid")
codeGraphs, err := oh.db.GetCodeGraphsByWorkspaceUuid(workspace_uuid)
codeGraph, err := oh.db.GetCodeGraphByWorkspaceUuid(workspace_uuid)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to get code graphs"})
return
}

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(codeGraphs)
json.NewEncoder(w).Encode(codeGraph)
}

func (oh *workspaceHandler) DeleteWorkspaceCodeGraph(w http.ResponseWriter, r *http.Request) {
Expand Down
11 changes: 5 additions & 6 deletions handlers/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ func TestGetCodeGraphsByWorkspaceUuid(t *testing.T) {

t.Run("should return error if user is not authorized", func(t *testing.T) {
rr := httptest.NewRecorder()
handler := http.HandlerFunc(oHandler.GetCodeGraphsByWorkspaceUuid)
handler := http.HandlerFunc(oHandler.GetCodeGraphByWorkspaceUuid)

rctx := chi.NewRouteContext()
rctx.URLParams.Add("workspace_uuid", workspace.Uuid)
Expand All @@ -2201,7 +2201,7 @@ func TestGetCodeGraphsByWorkspaceUuid(t *testing.T) {

t.Run("should return workspace code graphs if user is authorized", func(t *testing.T) {
rr := httptest.NewRecorder()
handler := http.HandlerFunc(oHandler.GetCodeGraphsByWorkspaceUuid)
handler := http.HandlerFunc(oHandler.GetCodeGraphByWorkspaceUuid)

rctx := chi.NewRouteContext()
rctx.URLParams.Add("workspace_uuid", workspace.Uuid)
Expand All @@ -2215,12 +2215,11 @@ func TestGetCodeGraphsByWorkspaceUuid(t *testing.T) {
handler.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)

var returnedCodeGraphs []db.WorkspaceCodeGraph
var returnedCodeGraphs db.WorkspaceCodeGraph
err = json.Unmarshal(rr.Body.Bytes(), &returnedCodeGraphs)
assert.NoError(t, err)
assert.Equal(t, 1, len(returnedCodeGraphs))
assert.Equal(t, codeGraph.Name, returnedCodeGraphs[0].Name)
assert.Equal(t, codeGraph.Url, returnedCodeGraphs[0].Url)
assert.Equal(t, codeGraph.Name, returnedCodeGraphs.Name)
assert.Equal(t, codeGraph.Url, returnedCodeGraphs.Url)
})
}

Expand Down
32 changes: 15 additions & 17 deletions mocks/Database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion routes/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func WorkspaceRoutes() chi.Router {

r.Post("/codegraph", workspaceHandlers.CreateOrEditWorkspaceCodeGraph)
r.Get("/codegraph/{uuid}", workspaceHandlers.GetWorkspaceCodeGraphByUUID)
r.Get("/{workspace_uuid}/codegraph", workspaceHandlers.GetCodeGraphsByWorkspaceUuid)
r.Get("/{workspace_uuid}/codegraph", workspaceHandlers.GetCodeGraphByWorkspaceUuid)
r.Delete("/{workspace_uuid}/codegraph/{uuid}", workspaceHandlers.DeleteWorkspaceCodeGraph)
})
return r
Expand Down

0 comments on commit 894d16c

Please sign in to comment.