MCPcopy
hub / github.com/cli/cli / ParseIssuesFromArgs

Function ParseIssuesFromArgs

pkg/cmd/issue/shared/lookup.go:21–54  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

19var issueURLRE = regexp.MustCompile(`^/([^/]+)/([^/]+)/(?:issues|pull)/(\d+)`)
20
21func 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
56func ParseIssueFromArg(arg string) (int, o.Option[ghrepo.Interface], error) {
57 issueLocator := tryParseIssueFromURL(arg)

Callers 1

TestParseIssuesFromArgsFunction · 0.85

Calls 7

IsSameFunction · 0.92
FullNameFunction · 0.92
ParseIssueFromArgFunction · 0.85
IsNoneMethod · 0.80
IsSomeMethod · 0.80
ErrorfMethod · 0.65
UnwrapMethod · 0.45

Tested by 1

TestParseIssuesFromArgsFunction · 0.68