MCPcopy Index your code
hub / github.com/apache/devlake / formatConnection

Function formatConnection

backend/plugins/webhook/api/connection.go:256–281  ·  view source on GitHub ↗
(connection *models.WebhookConnection, withApiKeyInfo bool)

Source from the content-addressed store, hash-verified

254}
255
256func formatConnection(connection *models.WebhookConnection, withApiKeyInfo bool) (*WebhookConnectionResponse, errors.Error) {
257 response := &WebhookConnectionResponse{WebhookConnection: *connection}
258 response.PostIssuesEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/issues`, connection.ID)
259 response.CloseIssuesEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/issue/:issueKey/close`, connection.ID)
260 response.PostPullRequestsEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/pull_requests`, connection.ID)
261 response.PostPipelineTaskEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/cicd_tasks`, connection.ID)
262 response.PostPipelineDeployTaskEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/deployments`, connection.ID)
263 response.ClosePipelineEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/cicd_pipeline/:pipelineName/finish`, connection.ID)
264 if withApiKeyInfo {
265 db := basicRes.GetDal()
266 apiKeyName := apiKeyHelper.GenApiKeyNameForPlugin(pluginName, connection.ID)
267 apiKey, err := apiKeyHelper.GetApiKey(db, dal.Where("name = ?", apiKeyName))
268 if err != nil {
269 if db.IsErrorNotFound(err) {
270 logger.Info("api key with name: %s not found in db", apiKeyName)
271 } else {
272 logger.Error(err, "query api key from db, name: %s", apiKeyName)
273 return nil, err
274 }
275 } else {
276 response.ApiKey = apiKey
277 response.ApiKey.RemoveHashedApiKey() // delete the hashed api key to reduce the attack surface.
278 }
279 }
280 return response, nil
281}

Callers 3

PostConnectionsFunction · 0.85
ListConnectionsFunction · 0.85
getConnectionFunction · 0.85

Calls 7

GetApiKeyMethod · 0.80
RemoveHashedApiKeyMethod · 0.80
GetDalMethod · 0.65
IsErrorNotFoundMethod · 0.65
InfoMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected