99 "errors"
1010 "fmt"
1111 "log"
12+ "net/url"
1213 "os"
1314 "os/exec"
1415 "path"
@@ -109,6 +110,12 @@ func (b Builder) Build(owner, repo string) error {
109110 b .changelog .Entries [i ].LinkedPR = prIDs
110111 } else {
111112 // Applying heuristics to PR fields
113+ owner , repo , err := ExtractOwnerRepo (entry .LinkedPR [0 ])
114+ if err != nil {
115+ log .Printf ("%s: check if the PR field is correct in changelog: %s" , entry .File .Name , err .Error ())
116+ continue
117+ }
118+
112119 originalPR , err := FindOriginalPR (entry .LinkedPR [0 ], owner , repo , c )
113120 if err != nil {
114121 log .Printf ("%s: check if the PR field is correct in changelog: %s" , entry .File .Name , err .Error ())
@@ -122,6 +129,12 @@ func (b Builder) Build(owner, repo string) error {
122129 linkedIssues := []string {}
123130
124131 for _ , prURL := range b .changelog .Entries [i ].LinkedPR {
132+ owner , repo , err := ExtractOwnerRepo (prURL )
133+ if err != nil {
134+ log .Printf ("%s: check if the PR field is correct in changelog: %s" , entry .File .Name , err .Error ())
135+ continue
136+ }
137+
125138 tempIssues , err := FindIssues (graphqlClient , context .Background (), owner , repo , prURL , 50 )
126139 if err != nil {
127140 log .Printf ("%s: could not find linked issues for pr: %s: %s" , entry .File .Name , entry .LinkedPR , err .Error ())
@@ -136,7 +149,7 @@ func (b Builder) Build(owner, repo string) error {
136149
137150 b .changelog .Entries [i ].LinkedIssue = linkedIssues
138151 } else if len (entry .LinkedIssue ) == 1 {
139- _ , err : = ExtractEventNumber ("issue" , entry .LinkedIssue [0 ])
152+ _ , err = ExtractEventNumber ("issue" , entry .LinkedIssue [0 ])
140153 if err != nil {
141154 log .Printf ("%s: check if the issue field is correct in changelog: %s" , entry .File .Name , err .Error ())
142155 }
@@ -168,11 +181,25 @@ func collectFragment(fs afero.Fs, path string, info os.FileInfo, err error, file
168181 return nil
169182}
170183
184+ func ExtractOwnerRepo (eventURL string ) (string , string , error ) {
185+ urlParsed , err := url .Parse (eventURL )
186+ if err != nil {
187+ return "" , "" , fmt .Errorf ("invalid url: %w" , err )
188+ }
189+
190+ urlParts := strings .Split (urlParsed .Path , "/" )
191+ if len (urlParts ) < 1 {
192+ return "" , "" , fmt .Errorf ("can't get owner or repo" )
193+ }
194+
195+ return urlParts [1 ], urlParts [2 ], nil
196+ }
197+
171198func ExtractEventNumber (linkType , eventURL string ) (string , error ) {
172199 urlParts := strings .Split (eventURL , "/" )
173200
174201 if len (urlParts ) < 1 {
175- return "" , fmt .Errorf ("cant get event number" )
202+ return "" , fmt .Errorf ("can't get event number" )
176203 }
177204
178205 switch linkType {
0 commit comments