Adds Formatting to the CI (#69)
This MR adds linting and formatting to the CI pipeline for the repository for both the Golang and Lua code.
This commit is contained in:
committed by
GitHub
parent
3a67424fec
commit
a055c4c988
@@ -30,5 +30,8 @@ func ApproveHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Status: http.StatusOK,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ func AssigneesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Assignees: mr.Assignees,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func AttachmentHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
fileResponse := AttachmentResponse{
|
||||
response := AttachmentResponse{
|
||||
SuccessResponse: SuccessResponse{
|
||||
Status: http.StatusOK,
|
||||
Message: "File uploaded successfully",
|
||||
@@ -67,5 +67,8 @@ func AttachmentHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Url: projectFile.URL,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(fileResponse)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,11 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
command string
|
||||
projectId string
|
||||
mergeId int
|
||||
gitlabInstance string
|
||||
authToken string
|
||||
logPath string
|
||||
debug bool
|
||||
git *gitlab.Client
|
||||
}
|
||||
|
||||
@@ -41,11 +39,14 @@ var requestLogger retryablehttp.RequestLogHook = func(l retryablehttp.Logger, r
|
||||
token := r.Header.Get("Private-Token")
|
||||
r.Header.Set("Private-Token", "REDACTED")
|
||||
res, err := httputil.DumpRequest(r, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
r.Header.Set("Private-Token", token)
|
||||
|
||||
_, err = file.Write([]byte("\n-- REQUEST --\n"))
|
||||
_, err = file.Write(res)
|
||||
_, err = file.Write([]byte("\n"))
|
||||
_, 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) {
|
||||
@@ -58,10 +59,13 @@ var responseLogger retryablehttp.ResponseLogHook = func(l retryablehttp.Logger,
|
||||
defer file.Close()
|
||||
|
||||
res, err := httputil.DumpResponse(response, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = file.Write([]byte("\n-- RESPONSE --\n"))
|
||||
_, err = file.Write(res)
|
||||
_, err = file.Write([]byte("\n"))
|
||||
_, err = file.Write([]byte("\n-- RESPONSE --\n")) //nolint:all
|
||||
_, err = file.Write(res) //nolint:all
|
||||
_, err = file.Write([]byte("\n")) //nolint:all
|
||||
}
|
||||
|
||||
/* This will initialize the client with the token and check for the basic project ID and command arguments */
|
||||
@@ -155,5 +159,9 @@ func (c *Client) handleError(w http.ResponseWriter, err error, message string, s
|
||||
Details: err.Error(),
|
||||
Status: status,
|
||||
}
|
||||
json.NewEncoder(w).Encode(response)
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
const mrVersionsUrl = "%s/api/v4/projects/%s/merge_requests/%d/versions"
|
||||
|
||||
type PostCommentRequest struct {
|
||||
Comment string `json:"comment"`
|
||||
FileName string `json:"file_name"`
|
||||
@@ -103,7 +101,10 @@ func DeleteComment(w http.ResponseWriter, r *http.Request) {
|
||||
Status: http.StatusOK,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func PostComment(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -186,7 +187,10 @@ func PostComment(w http.ResponseWriter, r *http.Request) {
|
||||
Discussion: discussion,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func EditComment(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -241,5 +245,8 @@ func EditComment(w http.ResponseWriter, r *http.Request) {
|
||||
Comment: note,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ func SummaryHandler(w http.ResponseWriter, r *http.Request) {
|
||||
MergeRequest: mr,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (c *Client) Info() ([]byte, error) {
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||
return nil, errors.New(fmt.Sprintf("Recieved non-200 response: %d", res.StatusCode))
|
||||
return nil, fmt.Errorf("Recieved non-200 response: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
@@ -83,5 +83,8 @@ func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Info: mergeRequest,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ func JobHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
reader, _, err := c.git.Jobs.GetTraceFile(c.projectId, jobTraceRequest.JobId)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not get trace file for job", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
file, err := io.ReadAll(reader)
|
||||
|
||||
@@ -55,5 +58,8 @@ func JobHandler(w http.ResponseWriter, r *http.Request) {
|
||||
File: string(file),
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (c *Client) ListDiscussions(blacklist []string) ([]*gitlab.Discussion, []*g
|
||||
if note.Type == gitlab.NoteTypeValue("DiffNote") {
|
||||
linkedDiscussions = append(linkedDiscussions, discussion)
|
||||
break
|
||||
} else if note.System == false && note.Position == nil {
|
||||
} else if !note.System && note.Position == nil {
|
||||
unlinkedDiscussions = append(unlinkedDiscussions, discussion)
|
||||
break
|
||||
}
|
||||
@@ -118,5 +118,8 @@ func ListDiscussionsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
UnlinkedDiscussions: unlinkedDiscussions,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,9 +88,12 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
type ClientString string
|
||||
|
||||
func withGitlabContext(next http.HandlerFunc, c Client) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(context.Background(), "client", c)
|
||||
var cl ClientString = "client"
|
||||
ctx := context.WithValue(context.Background(), cl, c)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ func ProjectMembersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ProjectMembers: projectMembers,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
|
||||
return
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,10 @@ func GetJobs(w http.ResponseWriter, r *http.Request) {
|
||||
Jobs: jobs,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -104,6 +107,8 @@ func RetriggerPipeline(w http.ResponseWriter, r *http.Request) {
|
||||
Pipeline: pipeline,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,5 +79,8 @@ func ReplyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Note: note,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ func ReviewersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Reviewers: mr.Reviewers,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ func RevisionsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Revisions: versionInfo,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,5 +31,8 @@ func RevokeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Status: http.StatusOK,
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(response)
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user