Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unstable search issue behavior #178

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions tagpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,28 +606,38 @@ func (tp *tagpr) generatenNextLabels(prIssues []*github.Issue) []string {
return nextLabels
}

func buildChunkSearchIssuesQuery(queryBase string, shasStr string) (chunkQueries []string) {
query := queryBase
func buildChunkSearchIssuesQuery(qualifiers string, shasStr string) (chunkQueries []string) {
// Longer than 256 characters are not supported in the query.
// ref. https://docs.github.com/en/rest/reference/search#limitations-on-query-length
//
// However, although not explicitly stated in the documentation, the space separating
// keywords is counted as one or more characters, so it is possible to exceed 256
// characters if the text is filled to the very limit of 256 characters.
// For this reason, the maximum number of chars in the KEYWORD section is limited to
// the following number.
const maxKeywordsLength = 200

// array of SHAs
keywords := make([]string, 0, 25)
Copy link
Contributor Author

@snaka snaka Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 To clarify that the character limit applies only to the part of the string that makes up the query, excluding the qualifier, the variable name has been changed.

// Make bulk requests with multiple SHAs of the maximum possible length.
// If multiple SHAs are specified, the issue search API will treat it like an OR search,
// and all the pull requests will be searched.u
// and all the pull requests will be searched.
// This is difficult to read from the current documentation, but that is the current
// behavior and GitHub support has responded that this is the spec.
for _, sha := range strings.Split(shasStr, "\n") {
if strings.TrimSpace(sha) == "" {
continue
}
// Longer than 256 characters are not supported in the query.
// ref. https://docs.github.com/en/rest/reference/search#limitations-on-query-length
if len(query)+1+len(sha) >= 256 {
chunkQueries = append(chunkQueries, query)
query = queryBase
tempKeywords := append(keywords, sha)
if len(strings.Join(tempKeywords, " ")) >= maxKeywordsLength {
chunkQueries = append(chunkQueries, qualifiers + " " + strings.Join(keywords, " "))
keywords = make([]string, 0, 25)
}
query += " " + sha
keywords = append(keywords, sha)
}

if query != queryBase {
chunkQueries = append(chunkQueries, query)
if len(keywords) > 0 {
chunkQueries = append(chunkQueries, qualifiers + " " + strings.Join(keywords, " "))
}

return chunkQueries
Expand Down
10 changes: 4 additions & 6 deletions tagpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def3db8
c0fc143
`,
[]string{
"repo:Songmu/tagpr is:pr is:closed 1a8bb97 1b7691b a9462b9 4d2b5e9 9ce4268 1eccbf8 1c3fbfc 968ade5 531c782 780bb71 6025fbf cc369ba a1f3e39 792bc85 3e3c4e1 37832de ac97702 d742186 217eb5d 0f900f7 5ef33d1 1d2ec15 2f37752 066ad7b 2e19b14 52b3706 f5134ae",
"repo:Songmu/tagpr is:pr is:closed ea39bbf 76b0630 ee3c6e6 2336be4 423a209 63caa74 3296052 3c98d78 86b8739 2264ec5 5c1d87b 4ffe09c 7c5d0de 3de9ed0 1b6b58c 2b643ec 53bf089 e8e96d5 3dac4b0 0605ba4 86cb76d 358c7c1 a139f86 33c16b6 c91f8ff a109671 b4029bd",
"repo:Songmu/tagpr is:pr is:closed f985b4f b74ef35 53d9ab3 6f57b07 0a84d90 43aa57d 75b6f79 def3db8 c0fc143",
"repo:Songmu/tagpr is:pr is:closed 1a8bb97 1b7691b a9462b9 4d2b5e9 9ce4268 1eccbf8 1c3fbfc 968ade5 531c782 780bb71 6025fbf cc369ba a1f3e39 792bc85 3e3c4e1 37832de ac97702 d742186 217eb5d 0f900f7 5ef33d1 1d2ec15 2f37752 066ad7b 2e19b14",
"repo:Songmu/tagpr is:pr is:closed 52b3706 f5134ae ea39bbf 76b0630 ee3c6e6 2336be4 423a209 63caa74 3296052 3c98d78 86b8739 2264ec5 5c1d87b 4ffe09c 7c5d0de 3de9ed0 1b6b58c 2b643ec 53bf089 e8e96d5 3dac4b0 0605ba4 86cb76d 358c7c1 a139f86",
"repo:Songmu/tagpr is:pr is:closed 33c16b6 c91f8ff a109671 b4029bd f985b4f b74ef35 53d9ab3 6f57b07 0a84d90 43aa57d 75b6f79 def3db8 c0fc143",
},
},
{
Expand Down Expand Up @@ -132,11 +132,9 @@ d742186
2f37752
066ad7b
2e19b14
52b3706
f5134ae
`,
[]string{
"repo:Songmu/tagpr is:pr is:closed 1a8bb97 1b7691b a9462b9 4d2b5e9 9ce4268 1eccbf8 1c3fbfc 968ade5 531c782 780bb71 6025fbf cc369ba a1f3e39 792bc85 3e3c4e1 37832de ac97702 d742186 217eb5d 0f900f7 5ef33d1 1d2ec15 2f37752 066ad7b 2e19b14 52b3706 f5134ae",
"repo:Songmu/tagpr is:pr is:closed 1a8bb97 1b7691b a9462b9 4d2b5e9 9ce4268 1eccbf8 1c3fbfc 968ade5 531c782 780bb71 6025fbf cc369ba a1f3e39 792bc85 3e3c4e1 37832de ac97702 d742186 217eb5d 0f900f7 5ef33d1 1d2ec15 2f37752 066ad7b 2e19b14",
},
},
}
Expand Down
Loading