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.
48 lines
956 B
Go
48 lines
956 B
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/xanzy/go-gitlab"
|
|
)
|
|
|
|
type UserResponse struct {
|
|
SuccessResponse
|
|
User *gitlab.User `json:"user"`
|
|
}
|
|
|
|
type MeGetter interface {
|
|
CurrentUser(options ...gitlab.RequestOptionFunc) (*gitlab.User, *gitlab.Response, error)
|
|
}
|
|
|
|
type meService struct {
|
|
data
|
|
client MeGetter
|
|
}
|
|
|
|
func (a meService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
user, res, err := a.client.CurrentUser()
|
|
|
|
if err != nil {
|
|
handleError(w, err, "Failed to get current user", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
if res.StatusCode >= 300 {
|
|
handleError(w, err, "User API returned non-200 status", res.StatusCode)
|
|
return
|
|
}
|
|
|
|
response := UserResponse{
|
|
SuccessResponse: SuccessResponse{Message: "User fetched successfully"},
|
|
User: user,
|
|
}
|
|
|
|
err = json.NewEncoder(w).Encode(response)
|
|
if err != nil {
|
|
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
|
}
|
|
}
|