MCPcopy Create free account
hub / github.com/assetnote/newtowner / CheckURLs

Method CheckURLs

internal/providers/github/github.go:193–409  ·  view source on GitHub ↗

CheckURLs performs checks for the given URLs using GitHub Actions.

(urls []string)

Source from the content-addressed store, hash-verified

191
192// CheckURLs performs checks for the given URLs using GitHub Actions.
193func (p *Provider) CheckURLs(urls []string) ([]URLCheckResult, error) {
194 var allResults []URLCheckResult
195 ctx := context.Background()
196
197 if len(urls) == 0 {
198 return allResults, nil
199 }
200
201 allResults = make([]URLCheckResult, len(urls))
202 resultsMap := make(map[string]*URLCheckResult)
203
204 for i, rawURL := range urls {
205 allResults[i] = URLCheckResult{URL: rawURL}
206 result := &allResults[i]
207 resultsMap[rawURL] = result
208
209 parsedURL, err := url.Parse(rawURL)
210 if err != nil {
211 result.Error = fmt.Sprintf("Error parsing URL: %v", err)
212 log.Printf("[GitHub DEBUG] URL: %s - Initial population: Error parsing URL: %v", rawURL, err)
213 } else {
214 result.TargetHostname = parsedURL.Hostname()
215 }
216
217 log.Printf("[GitHub] Making direct request to %s", rawURL)
218 result.DirectRequest = util.MakeHTTPRequest(ctx, "GET", rawURL, false)
219 if result.DirectRequest.Error != "" {
220 log.Printf("[GitHub] Direct request error for %s: %s", rawURL, result.DirectRequest.Error)
221 }
222
223 if result.TargetHostname != "" {
224 geoLoc, resolvedIP, geoErr := util.ResolveHostAndGetGeoLocation(result.TargetHostname)
225 if geoErr == nil {
226 result.TargetResolvedIP = resolvedIP.String()
227 result.TargetGeoCountry = geoLoc.CountryCode
228 result.TargetGeoRegion = geoLoc.RegionName
229 } else {
230 log.Printf("[GitHub] Warning: Could not get GeoIP for %s: %v", result.TargetHostname, geoErr)
231 }
232 }
233 log.Printf("[GitHub DEBUG] URL: %s - After direct/GeoIP: Error='%s', DirectStatus=%d, TargetHost='%s', ResolvedIP='%s'", rawURL, result.Error, result.DirectRequest.StatusCode, result.TargetHostname, result.TargetResolvedIP)
234 }
235
236 var validURLsForWorkflow []string
237 for _, r := range allResults {
238 if r.Error == "" && r.TargetHostname != "" {
239 validURLsForWorkflow = append(validURLsForWorkflow, r.URL)
240 }
241 }
242
243 if len(validURLsForWorkflow) == 0 {
244 log.Printf("[GitHub] No valid URLs with successfully parsed hostnames to process via workflow.")
245 return allResults, nil
246 }
247
248 for i := 0; i < len(validURLsForWorkflow); i += githubWorkflowURLBatchSize {
249 end := i + githubWorkflowURLBatchSize
250 if end > len(validURLsForWorkflow) {

Callers

nothing calls this directly

Calls 8

pollForWorkflowRunMethod · 0.95
MakeHTTPRequestFunction · 0.92
SanitizeFilenameFunction · 0.92
GetMapKeysFunction · 0.92
CompareHTTPResponsesFunction · 0.92
StringMethod · 0.80

Tested by

no test coverage detected