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

Function findByProjectName

backend/plugins/webhook/api/deployments.go:357–389  ·  view source on GitHub ↗

findByProjectName finds the connection by project name and plugin name

(connection interface{}, params map[string]string, pluginName string, webhookName string)

Source from the content-addressed store, hash-verified

355
356// findByProjectName finds the connection by project name and plugin name
357func findByProjectName(connection interface{}, params map[string]string, pluginName string, webhookName string) errors.Error {
358 projectName := params["projectName"]
359 if projectName == "" {
360 return errors.BadInput.New("missing projectName")
361 }
362 if len(projectName) > 100 {
363 return errors.BadInput.New("invalid projectName")
364 }
365 if pluginName == "" {
366 return errors.BadInput.New("missing pluginName")
367 }
368 // We need to join three tables: _tool_webhook_connections, _devlake_blueprint_connections, and _devlake_blueprints
369 // to find the connection associated with the given project name and plugin name.
370 // The SQL query would look something like this:
371 // SELECT wc.*
372 // FROM _tool_webhook_connections AS wc
373 // JOIN _devlake_blueprint_connections AS bc ON wc.id = bc.connection_id AND bc.plugin_name = ?
374 // JOIN _devlake_blueprints AS bp ON bc.blueprint_id = bp.id
375 // WHERE bp.project_name = ? and _tool_webhook_connections.name = ?
376 // LIMIT 1;
377
378 basicRes.GetLogger().Debug("finding project webhook connection for project %s and plugin %s", projectName, pluginName)
379 // Using DAL to construct the query
380 clauses := []dal.Clause{dal.From(connection)}
381 clauses = append(clauses,
382 dal.Join("left join _devlake_blueprint_connections bc ON _tool_webhook_connections.id = bc.connection_id and bc.plugin_name = ?", pluginName),
383 dal.Join("left join _devlake_blueprints bp ON bc.blueprint_id = bp.id"),
384 dal.Where("bp.project_name = ? and _tool_webhook_connections.name = ?", projectName, webhookName),
385 )
386
387 dal := basicRes.GetDal()
388 return dal.First(connection, clauses...)
389}

Callers 1

getOrCreateConnectionFunction · 0.85

Calls 6

NewMethod · 0.65
DebugMethod · 0.65
GetLoggerMethod · 0.65
FromMethod · 0.65
GetDalMethod · 0.65
FirstMethod · 0.65

Tested by

no test coverage detected