Feat: See Pipeline Job Logs (#54)
This MR adds the ability to see log traces associated with Gitlab CI jobs, via the new `perform_linewise_action` keybinding in the pipeline popup.
This commit is contained in:
committed by
GitHub
parent
26a133be44
commit
94fdf5f38a
59
cmd/job.go
Normal file
59
cmd/job.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type JobTraceRequest struct {
|
||||
JobId int `json:"job_id"`
|
||||
}
|
||||
|
||||
type JobTraceResponse struct {
|
||||
SuccessResponse
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
||||
func JobHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
c := r.Context().Value("client").(Client)
|
||||
|
||||
if r.Method != http.MethodGet {
|
||||
w.Header().Set("Allow", http.MethodGet)
|
||||
c.handleError(w, errors.New("Invalid request type"), "That request type is not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not read request body", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
|
||||
var jobTraceRequest JobTraceRequest
|
||||
err = json.Unmarshal(body, &jobTraceRequest)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not unmarshal data from request body", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
reader, _, err := c.git.Jobs.GetTraceFile(c.projectId, jobTraceRequest.JobId)
|
||||
|
||||
file, err := io.ReadAll(reader)
|
||||
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not read job trace file", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
response := JobTraceResponse{
|
||||
SuccessResponse: SuccessResponse{
|
||||
Status: http.StatusOK,
|
||||
Message: "Log file read",
|
||||
},
|
||||
File: string(file),
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
@@ -41,6 +41,7 @@ func main() {
|
||||
m.Handle("/reply", withGitlabContext(http.HandlerFunc(ReplyHandler), c))
|
||||
m.Handle("/members", withGitlabContext(http.HandlerFunc(ProjectMembersHandler), c))
|
||||
m.Handle("/pipeline", withGitlabContext(http.HandlerFunc(PipelineHandler), c))
|
||||
m.Handle("/job", withGitlabContext(http.HandlerFunc(JobHandler), c))
|
||||
|
||||
port := fmt.Sprintf(":%s", os.Args[3])
|
||||
server := &http.Server{
|
||||
|
||||
Reference in New Issue
Block a user