LoadGlobalRules 加载全局规则
(ctx context.Context)
| 69 | |
| 70 | // LoadGlobalRules 加载全局规则 |
| 71 | func (m *Manager) LoadGlobalRules(ctx context.Context) error { |
| 72 | m.mu.Lock() |
| 73 | defer m.mu.Unlock() |
| 74 | |
| 75 | // 从文件加载 |
| 76 | if m.config.GlobalRulesPath != "" { |
| 77 | rules, err := m.loadRulesFromFile(m.config.GlobalRulesPath, ScopeGlobal) |
| 78 | if err != nil { |
| 79 | // 文件不存在不是错误 |
| 80 | if !os.IsNotExist(err) { |
| 81 | return fmt.Errorf("load global rules failed: %w", err) |
| 82 | } |
| 83 | } else { |
| 84 | for _, r := range rules { |
| 85 | m.ruleSet.AddGlobalRule(r) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // 使用自定义加载器 |
| 91 | for _, loader := range m.loaders { |
| 92 | rules, err := loader.LoadGlobalRules(ctx) |
| 93 | if err != nil { |
| 94 | return fmt.Errorf("loader %T failed: %w", loader, err) |
| 95 | } |
| 96 | for _, r := range rules { |
| 97 | m.ruleSet.AddGlobalRule(r) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | // LoadProjectRules 加载项目规则 |
| 105 | func (m *Manager) LoadProjectRules(ctx context.Context, projectID string) error { |
nothing calls this directly
no test coverage detected