@@ -11,52 +11,55 @@ import (
1111 "github.com/cli/cli/internal/ghrepo"
1212)
1313
14- func IssueFromArg (apiClient * api.Client , baseRepoFn func () (ghrepo.Interface , error ), arg string ) (* api.Issue , ghrepo.Interface , error ) {
15- issue , baseRepo , err := issueFromURL (apiClient , arg )
16- if err != nil {
17- return nil , nil , err
18- }
19- if issue != nil {
20- return issue , baseRepo , nil
21- }
14+ func IssueWithCommentsFromArg (apiClient * api.Client , baseRepoFn func () (ghrepo.Interface , error ), arg string , comments int ) (* api.Issue , ghrepo.Interface , error ) {
15+ issueNumber , baseRepo := issueMetadataFromURL (arg )
2216
23- baseRepo , err = baseRepoFn ()
24- if err != nil {
25- return nil , nil , fmt .Errorf ("could not determine base repo: %w" , err )
17+ if baseRepo == nil {
18+ var err error
19+ baseRepo , err = baseRepoFn ()
20+ if err != nil {
21+ return nil , nil , fmt .Errorf ("could not determine base repo: %w" , err )
22+ }
2623 }
2724
28- issueNumber , err := strconv .Atoi (strings .TrimPrefix (arg , "#" ))
29- if err != nil {
30- return nil , nil , fmt .Errorf ("invalid issue format: %q" , arg )
25+ if issueNumber == 0 {
26+ var err error
27+ issueNumber , err = strconv .Atoi (strings .TrimPrefix (arg , "#" ))
28+ if err != nil {
29+ return nil , nil , fmt .Errorf ("invalid issue format: %q" , arg )
30+ }
3131 }
3232
33- issue , err = issueFromNumber (apiClient , baseRepo , issueNumber )
33+ issue , err : = issueFromNumber (apiClient , baseRepo , issueNumber , comments )
3434 return issue , baseRepo , err
3535}
3636
37+ func IssueFromArg (apiClient * api.Client , baseRepoFn func () (ghrepo.Interface , error ), arg string ) (* api.Issue , ghrepo.Interface , error ) {
38+ return IssueWithCommentsFromArg (apiClient , baseRepoFn , arg , 0 )
39+ }
40+
3741var issueURLRE = regexp .MustCompile (`^/([^/]+)/([^/]+)/issues/(\d+)` )
3842
39- func issueFromURL ( apiClient * api. Client , s string ) (* api. Issue , ghrepo.Interface , error ) {
43+ func issueMetadataFromURL ( s string ) (int , ghrepo.Interface ) {
4044 u , err := url .Parse (s )
4145 if err != nil {
42- return nil , nil , nil
46+ return 0 , nil
4347 }
4448
4549 if u .Scheme != "https" && u .Scheme != "http" {
46- return nil , nil , nil
50+ return 0 , nil
4751 }
4852
4953 m := issueURLRE .FindStringSubmatch (u .Path )
5054 if m == nil {
51- return nil , nil , nil
55+ return 0 , nil
5256 }
5357
5458 repo := ghrepo .NewWithHost (m [1 ], m [2 ], u .Hostname ())
5559 issueNumber , _ := strconv .Atoi (m [3 ])
56- issue , err := issueFromNumber (apiClient , repo , issueNumber )
57- return issue , repo , err
60+ return issueNumber , repo
5861}
5962
60- func issueFromNumber (apiClient * api.Client , repo ghrepo.Interface , issueNumber int ) (* api.Issue , error ) {
61- return api .IssueByNumber (apiClient , repo , issueNumber )
63+ func issueFromNumber (apiClient * api.Client , repo ghrepo.Interface , issueNumber , comments int ) (* api.Issue , error ) {
64+ return api .IssueByNumber (apiClient , repo , issueNumber , comments )
6265}
0 commit comments