MCPcopy
hub / github.com/apache/devlake / handlePluginCall

Function handlePluginCall

backend/server/api/router.go:112–174  ·  view source on GitHub ↗
(basicRes context.BasicRes, pluginName string, handler plugin.ApiResourceHandler)

Source from the content-addressed store, hash-verified

110}
111
112func handlePluginCall(basicRes context.BasicRes, pluginName string, handler plugin.ApiResourceHandler) func(c *gin.Context) {
113 return func(c *gin.Context) {
114 var err errors.Error
115 input := &plugin.ApiResourceInput{}
116 input.Params = make(map[string]string)
117 if len(c.Params) > 0 {
118 for _, param := range c.Params {
119 input.Params[param.Key] = param.Value
120 }
121 }
122 input.Params["plugin"] = pluginName
123 input.Query = c.Request.URL.Query()
124 user, exist := shared.GetUser(c)
125 if !exist {
126 basicRes.GetLogger().Debug("user doesn't exist")
127 } else {
128 input.User = user
129 }
130 if c.Request.Body != nil {
131 if strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data;") {
132 input.Request = c.Request
133 } else {
134 shouldBindJSONErr := c.ShouldBindJSON(&input.Body)
135 if shouldBindJSONErr != nil && shouldBindJSONErr.Error() != "EOF" {
136 shared.ApiOutputError(c, shouldBindJSONErr)
137 return
138 }
139 }
140 }
141 output, err := handler(input)
142 if err != nil {
143 if output != nil && output.Body != nil {
144 logruslog.Global.Error(err, "")
145 shared.ApiOutputSuccess(c, output.Body, err.GetType().GetHttpCode())
146 } else {
147 shared.ApiOutputError(c, err)
148 }
149 } else if output != nil {
150 status := output.Status
151 if status < http.StatusContinue {
152 status = http.StatusOK
153 }
154 if output.Header != nil {
155 for k, vs := range output.Header {
156 for _, v := range vs {
157 c.Header(k, v)
158 }
159 }
160 }
161 if output.File != nil {
162 c.Data(status, output.File.ContentType, output.File.Data)
163 return
164 }
165 if blob, ok := output.Body.([]byte); ok && output.ContentType != "" {
166 c.Data(status, output.ContentType, blob)
167 } else {
168 shared.ApiOutputSuccess(c, output.Body, status)
169 }

Callers 1

registerPluginEndpointsFunction · 0.85

Calls 9

GetTypeMethod · 0.95
QueryMethod · 0.80
GetUserMethod · 0.80
GetHttpCodeMethod · 0.80
DebugMethod · 0.65
GetLoggerMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.65
DataMethod · 0.65

Tested by

no test coverage detected