| 1 | package github |
| 2 | |
| 3 | import "strings" |
| 4 | |
| 5 | // OwnerRepoFromPRURL extracts the "owner/repo" slug from a full GitHub PR URL |
| 6 | // such as "https://github.com/owner/repo/pull/123". It tolerates a trailing |
| 7 | // slash and returns "" when the URL does not contain a non-empty owner and |
| 8 | // repo segment (e.g. a bare short name like "klaus" or a malformed URL). |
| 9 | // |
| 10 | // This is the single source of truth for PR-URL slug parsing; callers in |
| 11 | // internal/cmd and internal/pipeline both delegate here rather than reimplementing |
| 12 | // the split. |
| 13 | func OwnerRepoFromPRURL(prURL string) string { |
| 14 | s := strings.TrimPrefix(prURL, "https://github.com/") |
| 15 | s = strings.TrimPrefix(s, "http://github.com/") |
| 16 | parts := strings.Split(s, "/") |
| 17 | if len(parts) < 2 || parts[0] == "" || parts[1] == "" { |
| 18 | return "" |
| 19 | } |
| 20 | return parts[0] + "/" + parts[1] |
| 21 | } |