LoadProjectRules 加载项目规则
(ctx context.Context, projectID string)
| 103 | |
| 104 | // LoadProjectRules 加载项目规则 |
| 105 | func (m *Manager) LoadProjectRules(ctx context.Context, projectID string) error { |
| 106 | m.mu.Lock() |
| 107 | defer m.mu.Unlock() |
| 108 | |
| 109 | // 从项目文件加载 |
| 110 | if m.config.ProjectBasePath != "" && m.config.ProjectRuleFile != "" { |
| 111 | filePath := filepath.Join(m.config.ProjectBasePath, projectID, m.config.ProjectRuleFile) |
| 112 | rules, err := m.loadRulesFromFile(filePath, ScopeProject) |
| 113 | if err != nil { |
| 114 | if !os.IsNotExist(err) { |
| 115 | return fmt.Errorf("load project rules failed: %w", err) |
| 116 | } |
| 117 | } else { |
| 118 | for _, r := range rules { |
| 119 | m.ruleSet.AddProjectRule(projectID, r) |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // 使用自定义加载器 |
| 125 | for _, loader := range m.loaders { |
| 126 | rules, err := loader.LoadProjectRules(ctx, projectID) |
| 127 | if err != nil { |
| 128 | return fmt.Errorf("loader %T failed: %w", loader, err) |
| 129 | } |
| 130 | for _, r := range rules { |
| 131 | m.ruleSet.AddProjectRule(projectID, r) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return nil |
| 136 | } |
| 137 | |
| 138 | // GetRulesForProject 获取项目的所有规则 |
| 139 | func (m *Manager) GetRulesForProject(projectID string) []*Rule { |
nothing calls this directly
no test coverage detected