| 19 | var issueURLRE = regexp.MustCompile(`^/([^/]+)/([^/]+)/(?:issues|pull)/(\d+)`) |
| 20 | |
| 21 | func ParseIssuesFromArgs(args []string) ([]int, o.Option[ghrepo.Interface], error) { |
| 22 | var repo o.Option[ghrepo.Interface] |
| 23 | issueNumbers := make([]int, len(args)) |
| 24 | |
| 25 | for i, arg := range args { |
| 26 | // For each argument, parse the issue number and an optional repo |
| 27 | issueNumber, issueRepo, err := ParseIssueFromArg(arg) |
| 28 | if err != nil { |
| 29 | return nil, o.None[ghrepo.Interface](), err |
| 30 | } |
| 31 | |
| 32 | // if this is our first issue repo found, then we need to set it |
| 33 | if repo.IsNone() { |
| 34 | repo = issueRepo |
| 35 | } |
| 36 | |
| 37 | // if there is an issue repo returned, then we need to check if it is the same as the previous one |
| 38 | if issueRepo.IsSome() && repo.IsSome() { |
| 39 | // Unwraps are safe because we've checked for presence above |
| 40 | if !ghrepo.IsSame(repo.Unwrap(), issueRepo.Unwrap()) { |
| 41 | return nil, o.None[ghrepo.Interface](), fmt.Errorf( |
| 42 | "multiple issues must be in same repo: found %q, expected %q", |
| 43 | ghrepo.FullName(issueRepo.Unwrap()), |
| 44 | ghrepo.FullName(repo.Unwrap()), |
| 45 | ) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // add the issue number to the list |
| 50 | issueNumbers[i] = issueNumber |
| 51 | } |
| 52 | |
| 53 | return issueNumbers, repo, nil |
| 54 | } |
| 55 | |
| 56 | func ParseIssueFromArg(arg string) (int, o.Option[ghrepo.Interface], error) { |
| 57 | issueLocator := tryParseIssueFromURL(arg) |