parseShorthandSource handles "owner/repo" and "owner/repo@branch" forms.
(s string)
| 267 | |
| 268 | // parseShorthandSource handles "owner/repo" and "owner/repo@branch" forms. |
| 269 | func parseShorthandSource(s string) (owner, repo, branch, path string, ok bool) { |
| 270 | if at := strings.Index(s, "@"); at >= 0 { |
| 271 | branch = s[at+1:] |
| 272 | s = s[:at] |
| 273 | } |
| 274 | parts := strings.Split(s, "/") |
| 275 | if len(parts) < 2 || parts[0] == "" || parts[1] == "" { |
| 276 | return "", "", "", "", false |
| 277 | } |
| 278 | // A GitHub owner/repo has no dots; if the first segment looks like a |
| 279 | // hostname (e.g. "example.com/a"), this isn't a GitHub source. |
| 280 | if strings.Contains(parts[0], ".") { |
| 281 | return "", "", "", "", false |
| 282 | } |
| 283 | owner, repo = parts[0], parts[1] |
| 284 | if len(parts) > 2 { |
| 285 | path = strings.Join(parts[2:], "/") |
| 286 | } |
| 287 | return owner, repo, branch, path, true |
| 288 | } |