fix: date fixes; go middleware refactors; regex fixes; etc (#368)

fix: format of date when MR was closed or merged (#367)
refactor: Add Payload Validators + Middleware In Go Code (#366)
fix: Add better checks for leaving comments (#369)
fix: regex support for http credentials embedded in remote url (#372)
fix: Comment on single line selects two lines (#371)

This is a #PATCH release.
This commit is contained in:
Harrison (Harry) Cramer
2024-09-14 16:53:00 -04:00
committed by GitHub
parent f1faf603b0
commit 22bfd0c83e
61 changed files with 1527 additions and 1284 deletions

View File

@@ -10,7 +10,7 @@ import (
)
type JobTraceRequest struct {
JobId int `json:"job_id"`
JobId int `json:"job_id" validate:"required"`
}
type JobTraceResponse struct {
@@ -28,30 +28,11 @@ type traceFileService struct {
}
/* jobHandler returns a string that shows the output of a specific job run in a Gitlab pipeline */
func (a traceFileService) handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
w.Header().Set("Access-Control-Allow-Methods", http.MethodGet)
handleError(w, InvalidRequestError{}, "Expected GET", http.StatusMethodNotAllowed)
return
}
func (a traceFileService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
handleError(w, err, "Could not read request body", http.StatusBadRequest)
return
}
payload := r.Context().Value(payload("payload")).(*JobTraceRequest)
defer r.Body.Close()
var jobTraceRequest JobTraceRequest
err = json.Unmarshal(body, &jobTraceRequest)
if err != nil {
handleError(w, err, "Could not unmarshal data from request body", http.StatusBadRequest)
return
}
reader, res, err := a.client.GetTraceFile(a.projectInfo.ProjectId, jobTraceRequest.JobId)
reader, res, err := a.client.GetTraceFile(a.projectInfo.ProjectId, payload.JobId)
if err != nil {
handleError(w, err, "Could not get trace file for job", http.StatusInternalServerError)
@@ -59,7 +40,7 @@ func (a traceFileService) handler(w http.ResponseWriter, r *http.Request) {
}
if res.StatusCode >= 300 {
handleError(w, GenericError{endpoint: "/job"}, "Could not get trace file for job", res.StatusCode)
handleError(w, GenericError{r.URL.Path}, "Could not get trace file for job", res.StatusCode)
return
}
@@ -71,11 +52,8 @@ func (a traceFileService) handler(w http.ResponseWriter, r *http.Request) {
}
response := JobTraceResponse{
SuccessResponse: SuccessResponse{
Status: http.StatusOK,
Message: "Log file read",
},
File: string(file),
SuccessResponse: SuccessResponse{Message: "Log file read"},
File: string(file),
}
err = json.NewEncoder(w).Encode(response)