hostResolutionHintForNotFound returns a user-facing hint and whether it is applicable. hasHint is true only for 404-style resolution failures on non-github.com hosts.
(owner, repo, ref, workflowPath, explicitHost string, err error)
| 212 | // hostResolutionHintForNotFound returns a user-facing hint and whether it is applicable. |
| 213 | // hasHint is true only for 404-style resolution failures on non-github.com hosts. |
| 214 | func hostResolutionHintForNotFound(owner, repo, ref, workflowPath, explicitHost string, err error) (hint string, hasHint bool) { |
| 215 | if err == nil { |
| 216 | return "", false |
| 217 | } |
| 218 | |
| 219 | errorText := strings.ToLower(err.Error()) |
| 220 | if !strings.Contains(errorText, "http 404") && !strings.Contains(errorText, "status 404") { |
| 221 | return "", false |
| 222 | } |
| 223 | |
| 224 | normalizedExplicitHost := normalizeHostForHint(explicitHost) |
| 225 | if normalizedExplicitHost != "" { |
| 226 | return "", false |
| 227 | } |
| 228 | |
| 229 | resolvedHost := normalizeHostForHint(getGitHubHost()) |
| 230 | if resolvedHost == "" || resolvedHost == "github.com" { |
| 231 | return "", false |
| 232 | } |
| 233 | |
| 234 | trimmedPath := strings.TrimPrefix(workflowPath, "/") |
| 235 | fullURL := fmt.Sprintf("https://github.com/%s/%s/blob/%s/%s", owner, repo, ref, trimmedPath) |
| 236 | return fmt.Sprintf( |
| 237 | "Shorthand specs resolved on %s. Try using a full github.com source URL instead (for example: gh aw add %s)", |
| 238 | resolvedHost, fullURL, |
| 239 | ), true |
| 240 | } |
| 241 | |
| 242 | func normalizeHostForHint(host string) string { |
| 243 | host = strings.TrimSpace(strings.ToLower(host)) |