(input string)
| 1252 | } |
| 1253 | |
| 1254 | func extractPullRequestNumber(input string) (int, error) { |
| 1255 | candidate := strings.TrimSpace(input) |
| 1256 | candidate = strings.TrimSuffix(candidate, "/") |
| 1257 | if candidate == "" { |
| 1258 | return 0, fmt.Errorf("pull request reference cannot be empty") |
| 1259 | } |
| 1260 | |
| 1261 | if number, ok := parseNumericCandidate(candidate); ok { |
| 1262 | return number, nil |
| 1263 | } |
| 1264 | |
| 1265 | if strings.HasPrefix(candidate, "http://") || strings.HasPrefix(candidate, "https://") { |
| 1266 | u, err := url.Parse(candidate) |
| 1267 | if err == nil && u.Host != "" { |
| 1268 | segments := strings.Split(strings.Trim(u.Path, "/"), "/") |
| 1269 | for i := 0; i < len(segments); i++ { |
| 1270 | segment := segments[i] |
| 1271 | if segment == "pull" || segment == "pulls" { |
| 1272 | if i+1 < len(segments) { |
| 1273 | if number, ok := parseNumericCandidate(segments[i+1]); ok { |
| 1274 | return number, nil |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | if idx := strings.LastIndex(candidate, "#"); idx >= 0 && idx+1 < len(candidate) { |
| 1283 | if number, ok := parseNumericCandidate(candidate[idx+1:]); ok { |
| 1284 | return number, nil |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | if idx := strings.LastIndex(candidate, "/"); idx >= 0 && idx+1 < len(candidate) { |
| 1289 | if number, ok := parseNumericCandidate(candidate[idx+1:]); ok { |
| 1290 | return number, nil |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | return 0, fmt.Errorf("unable to determine pull request number from %q", input) |
| 1295 | } |
| 1296 | |
| 1297 | func parseNumericCandidate(raw string) (int, bool) { |
| 1298 | trimmed := strings.TrimSpace(raw) |
no test coverage detected