@@ -606,28 +606,38 @@ func (tp *tagpr) generatenNextLabels(prIssues []*github.Issue) []string {
606
606
return nextLabels
607
607
}
608
608
609
- func buildChunkSearchIssuesQuery (queryBase string , shasStr string ) (chunkQueries []string ) {
610
- query := queryBase
609
+ func buildChunkSearchIssuesQuery (qualifiers string , shasStr string ) (chunkQueries []string ) {
610
+ // Longer than 256 characters are not supported in the query.
611
+ // ref. https://docs.github.com/en/rest/reference/search#limitations-on-query-length
612
+ //
613
+ // However, although not explicitly stated in the documentation, the space separating
614
+ // keywords is counted as one or more characters, so it is possible to exceed 256
615
+ // characters if the text is filled to the very limit of 256 characters.
616
+ // For this reason, the maximum number of chars in the KEYWORD section is limited to
617
+ // the following number.
618
+ const maxKeywordsLength = 200
619
+
620
+ // array of SHAs
621
+ keywords := make ([]string , 0 , 25 )
611
622
// Make bulk requests with multiple SHAs of the maximum possible length.
612
623
// If multiple SHAs are specified, the issue search API will treat it like an OR search,
613
- // and all the pull requests will be searched.u
624
+ // and all the pull requests will be searched.
614
625
// This is difficult to read from the current documentation, but that is the current
615
626
// behavior and GitHub support has responded that this is the spec.
616
627
for _ , sha := range strings .Split (shasStr , "\n " ) {
617
628
if strings .TrimSpace (sha ) == "" {
618
629
continue
619
630
}
620
- // Longer than 256 characters are not supported in the query.
621
- // ref. https://docs.github.com/en/rest/reference/search#limitations-on-query-length
622
- if len (query )+ 1 + len (sha ) >= 256 {
623
- chunkQueries = append (chunkQueries , query )
624
- query = queryBase
631
+ tempKeywords := append (keywords , sha )
632
+ if len (strings .Join (tempKeywords , " " )) >= maxKeywordsLength {
633
+ chunkQueries = append (chunkQueries , qualifiers + " " + strings .Join (keywords , " " ))
634
+ keywords = make ([]string , 0 , 25 )
625
635
}
626
- query += " " + sha
636
+ keywords = append ( keywords , sha )
627
637
}
628
638
629
- if query != queryBase {
630
- chunkQueries = append (chunkQueries , query )
639
+ if len ( keywords ) > 0 {
640
+ chunkQueries = append (chunkQueries , qualifiers + " " + strings . Join ( keywords , " " ) )
631
641
}
632
642
633
643
return chunkQueries
0 commit comments