| 126 | } |
| 127 | |
| 128 | func validateHookRequest(controllerID, baseURL string, allHooks []*github.Hook, req *github.Hook) error { |
| 129 | parsed, err := url.Parse(baseURL) |
| 130 | if err != nil { |
| 131 | return fmt.Errorf("error parsing webhook url: %w", err) |
| 132 | } |
| 133 | |
| 134 | partialMatches := []string{} |
| 135 | for _, hook := range allHooks { |
| 136 | hookURL := strings.ToLower(hook.Config.GetURL()) |
| 137 | if hookURL == "" { |
| 138 | continue |
| 139 | } |
| 140 | |
| 141 | if hook.Config.GetURL() == req.Config.GetURL() { |
| 142 | return runnerErrors.NewConflictError("hook already installed") |
| 143 | } else if strings.Contains(hookURL, controllerID) || strings.Contains(hookURL, parsed.Hostname()) { |
| 144 | partialMatches = append(partialMatches, hook.Config.GetURL()) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if len(partialMatches) > 0 { |
| 149 | return runnerErrors.NewConflictError("a webhook containing the controller ID or hostname of this contreoller is already installed on this repository") |
| 150 | } |
| 151 | |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | func hookToParamsHookInfo(hook *github.Hook) params.HookInfo { |
| 156 | hookURL := hook.Config.GetURL() |