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

Method PrepareTaskData

backend/plugins/gitextractor/impl/impl.go:69–130  ·  view source on GitHub ↗

PrepareTaskData based on task context and user input options, return data that shared among all subtasks

(taskCtx plugin.TaskContext, options map[string]interface{})

Source from the content-addressed store, hash-verified

67
68// PrepareTaskData based on task context and user input options, return data that shared among all subtasks
69func (p GitExtractor) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) {
70 log := taskCtx.GetLogger().Nested("gitextractor.PrepareTaskData")
71 var op parser.GitExtractorOptions
72 if err := helper.DecodeMapStruct(options, &op, true); err != nil {
73 return nil, err
74 }
75
76 if op.PluginName != "" {
77 pluginInstance, err := plugin.GetPlugin(op.PluginName)
78 if err != nil {
79 return nil, errors.Default.Wrap(err, fmt.Sprintf("failed to get plugin instance for plugin: %s", op.PluginName))
80 }
81
82 if pluginGit, ok := pluginInstance.(DynamicGitUrl); ok {
83 gitUrl, err := pluginGit.GetDynamicGitUrl(taskCtx, op.ConnectionId, op.Url)
84 if err != nil {
85 return nil, errors.Default.Wrap(err, "failed to get Git URL")
86 }
87
88 op.Url = gitUrl
89 } else {
90 log.Printf("Plugin does not implement DynamicGitUrl interface for plugin: %s", op.PluginName)
91 }
92 }
93
94 parsedURL, err := giturls.Parse(op.Url)
95 if err != nil {
96 return nil, errors.BadInput.Wrap(err, "failed to parse git url")
97 }
98
99 // append username to the git url
100 if op.User != "" {
101 parsedURL.User = url.UserPassword(op.User, op.Password)
102 op.Url = parsedURL.String()
103 }
104
105 // commit stat, especially commit files(part of stat) are expensive to collect, so we skip them by default
106 cfg := taskCtx.GetConfigReader()
107 loadBool := func(optValue **bool, cfgKey string, defValue bool) {
108 // if user specified the option, use it
109 if *optValue != nil {
110 return
111 }
112 // or fallback to .env configuration
113 if cfg.IsSet(cfgKey) {
114 defValue = cfg.GetBool(cfgKey)
115 }
116 *optValue = &defValue
117 }
118 loadBool(&op.UseGoGit, "UseGoGit", false)
119 loadBool(&op.SkipCommitStat, "SKIP_COMMIT_STAT", false)
120 loadBool(&op.SkipCommitFiles, "SKIP_COMMIT_FILES", true)
121 log.Info("UseGoGit: %v", *op.UseGoGit)
122 log.Info("SkipCommitStat: %v", *op.SkipCommitStat)
123 log.Info("SkipCommitFiles: %v", *op.SkipCommitFiles)
124
125 taskData := &parser.GitExtractorTaskData{
126 Options: &op,

Callers

nothing calls this directly

Calls 11

GetPluginMethod · 0.80
WrapMethod · 0.80
IsSetMethod · 0.80
GetBoolMethod · 0.80
NestedMethod · 0.65
GetLoggerMethod · 0.65
GetDynamicGitUrlMethod · 0.65
PrintfMethod · 0.65
GetConfigReaderMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected