Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Stakwork Run ID to Front End on Sucessful Send #2119

Closed
4 tasks
Tracked by #2052
humansinstitute opened this issue Dec 6, 2024 · 6 comments · Fixed by #2123
Closed
4 tasks
Tracked by #2052

Post Stakwork Run ID to Front End on Sucessful Send #2119

humansinstitute opened this issue Dec 6, 2024 · 6 comments · Fixed by #2123
Assignees

Comments

@humansinstitute
Copy link
Contributor

humansinstitute commented Dec 6, 2024

Ticket Name: Implement WebSocket Update for Stakwork Run ID Submission

Task

  1. Modify the existing handler function in ticket.go to process the response from the Stakwork API.
  2. Unmarshal the response body to extract the project_id.
  3. Compose a WebSocket message using the extracted project_id.
  4. Utilize the sendMessage function from websocket/pool.go to broadcast this message.
  5. Ensure the WebSocket message uses the correct source session ID from the Stakwork object.

Outcome

This will allow display of a link to the current run to be displayed in the ticket editor component.

Design

https://github.com/stakwork/sphinx-tribes/blob/master/handlers/ticket.go#L376C2-L432C3

Code Snippet

resp, err := th.httpClient.Do(req)
if err != nil {
    w.WriteHeader(http.StatusInternalServerError)
    json.NewEncoder(w).Encode(TicketResponse{
        Success: false,
        Message: "Error sending request to Stakwork",
        Errors:  []string{err.Error()},
    })
    return
}
defer resp.Body.Close()

respBody, err := io.ReadAll(resp.Body)
if err != nil {
    w.WriteHeader(http.StatusInternalServerError)
    json.NewEncoder(w).Encode(TicketResponse{
        Success: false,
        Message: "Error reading response from Stakwork",
        Errors:  []string{err.Error()},
    })
    return
}

// Unmarshal the response
var stakworkResponse struct {
    Success bool `json:"success"`
    Data struct {
        ProjectID int `json:"project_id"`
    } `json:"data"`
}
err = json.Unmarshal(respBody, &stakworkResponse)
if err != nil {
    w.WriteHeader(http.StatusInternalServerError)
    json.NewEncoder(w).Encode(TicketResponse{
        Success: false,
        Message: "Error parsing response from Stakwork",
        Errors:  []string{err.Error()},
    })
    return
}

// Send WebSocket message
message := fmt.Sprintf("https://jobs.stakwork.com/admin/projects/%d", stakworkResponse.Data.ProjectID)
wsMessage := WebSocketMessage{
    BroadcastType: "direct",
    SourceSessionID: reviewReq.sourceWebsocket, // Ensure this is the correct path
    Message: message,
    Action: "swrun",
    TicketDetails: map[string]interface{}{},
}
sendMessage(wsMessage)

WebSocket Message

We already send a response that we have sent the message here: https://github.com/stakwork/sphinx-tribes/blob/master/handlers/ticket.go#L410C3-L420C6

Please update the message sent to:

{
    "broadcastType": "direct",
    "sourceSessionID": "<Question> Is this the correct path for source session ID?",
    "message": "${project_id}",
    "action": "swrun",
    "ticketDetails": {}
}

Acceptance Criteria

  • Modify ticket.go to process and unmarshal the Stakwork response.
  • Extract project_id from the Stakwork response.
  • Construct the new WebSocket message with the correct URL and project_id.
  • Use sendMessage from websocket/pool.go to send the WebSocket message.
@humansinstitute
Copy link
Contributor Author

Join and post in this Sphinx Tribe for assignments:

sphinx.chat://?action=tribeV2&pubkey=0306abbf1523b90303a0b65ca3d4e1359f5079348dc4ee33625d030613875b9f47&host=tribes.v2.sphinx.chat

No Github requests / tags will be monitored.

@saithsab877
Copy link
Contributor

@humansinstitute please assign me?

@AhsanFarooqDev
Copy link
Contributor

@humansinstitute can i help?

@AhsanFarooqDev
Copy link
Contributor

sphinx.chat://?action=tribeV2&pubkey=0306abbf1523b90303a0b65ca3d4e1359f5079348dc4ee33625d030613875b9f47&host=tribes.v2.sphinx.chat

@humansinstitute I can help please assign

@humansinstitute
Copy link
Contributor Author

@saithsab877 can we update this please.

"message": "${project_id}",

This will be easier to render on the front end.

@saithsab877
Copy link
Contributor

@humansinstitute Sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants