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:
committed by
GitHub
parent
f1faf603b0
commit
22bfd0c83e
@@ -5,10 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"os"
|
||||
|
||||
"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
@@ -48,12 +45,19 @@ func NewClient() (error, *Client) {
|
||||
gitlab.WithBaseURL(apiCustUrl),
|
||||
}
|
||||
|
||||
if pluginOptions.Debug.Request {
|
||||
gitlabOptions = append(gitlabOptions, gitlab.WithRequestLogHook(requestLogger))
|
||||
if pluginOptions.Debug.GitlabRequest {
|
||||
gitlabOptions = append(gitlabOptions, gitlab.WithRequestLogHook(
|
||||
func(l retryablehttp.Logger, r *http.Request, i int) {
|
||||
logRequest("REQUEST TO GITLAB", r)
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
if pluginOptions.Debug.Response {
|
||||
gitlabOptions = append(gitlabOptions, gitlab.WithResponseLogHook(responseLogger))
|
||||
if pluginOptions.Debug.GitlabResponse {
|
||||
gitlabOptions = append(gitlabOptions, gitlab.WithResponseLogHook(func(l retryablehttp.Logger, response *http.Response) {
|
||||
logResponse("RESPONSE FROM GITLAB", response)
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
tr := &http.Transport{
|
||||
@@ -106,7 +110,6 @@ func InitProjectSettings(c *Client, gitInfo git.GitData) (error, *ProjectInfo) {
|
||||
return nil, &ProjectInfo{
|
||||
ProjectId: projectId,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* handleError is a utililty handler that returns errors to the client along with their statuses and messages */
|
||||
@@ -115,7 +118,6 @@ func handleError(w http.ResponseWriter, err error, message string, status int) {
|
||||
response := ErrorResponse{
|
||||
Message: message,
|
||||
Details: err.Error(),
|
||||
Status: status,
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
@@ -123,53 +125,3 @@ func handleError(w http.ResponseWriter, err error, message string, status int) {
|
||||
handleError(w, err, "Could not encode error response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
var requestLogger retryablehttp.RequestLogHook = func(l retryablehttp.Logger, r *http.Request, i int) {
|
||||
file := openLogFile()
|
||||
defer file.Close()
|
||||
|
||||
token := r.Header.Get("Private-Token")
|
||||
r.Header.Set("Private-Token", "REDACTED")
|
||||
res, err := httputil.DumpRequest(r, true)
|
||||
if err != nil {
|
||||
log.Fatalf("Error dumping request: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
r.Header.Set("Private-Token", token)
|
||||
|
||||
_, err = file.Write([]byte("\n-- REQUEST --\n")) //nolint:all
|
||||
_, err = file.Write(res) //nolint:all
|
||||
_, err = file.Write([]byte("\n")) //nolint:all
|
||||
}
|
||||
|
||||
var responseLogger retryablehttp.ResponseLogHook = func(l retryablehttp.Logger, response *http.Response) {
|
||||
file := openLogFile()
|
||||
defer file.Close()
|
||||
|
||||
res, err := httputil.DumpResponse(response, true)
|
||||
if err != nil {
|
||||
log.Fatalf("Error dumping response: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = file.Write([]byte("\n-- RESPONSE --\n")) //nolint:all
|
||||
_, err = file.Write(res) //nolint:all
|
||||
_, err = file.Write([]byte("\n")) //nolint:all
|
||||
}
|
||||
|
||||
func openLogFile() *os.File {
|
||||
file, err := os.OpenFile(pluginOptions.LogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Printf("Log file %s does not exist", pluginOptions.LogPath)
|
||||
} else if os.IsPermission(err) {
|
||||
log.Printf("Permission denied for log file %s", pluginOptions.LogPath)
|
||||
} else {
|
||||
log.Printf("Error opening log file %s: %v", pluginOptions.LogPath, err)
|
||||
}
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user