Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 9
perf: optimise regex patterns compilation#1114
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c9dddce
perf: compile regex patterns once instead of per call
mbevc1 54b4aa3
fix: address review of the regex compilation changes
mbevc1 5571957
perf: compile the annotation key pattern once
mbevc1 d583bc9
refactor(jira): quote project keys when building the issue key pattern
mbevc1 a032f6f
fix(jira): narrow rather than widen on unusable project keys
mbevc1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -303,15 +303,7 @@ func (o *attestJiraOptions) run(args []string) error { | ||
| // Search commit message, branch name, and secondary source for Jira issue keys, | ||
| // filtering out false positives from multi-segment identifiers like CVE-2026-41284. | ||
| searchTexts := []string{commitInfo.Message} | ||
| if !o.ignoreBranchMatch { | ||
| searchTexts = append(searchTexts, commitInfo.Branch) | ||
| } | ||
| if o.secondarySource != "" { | ||
| searchTexts = append(searchTexts, o.secondarySource) | ||
| } | ||
| combinedText := strings.Join(searchTexts, "\n") | ||
| issueIDs := jira.FindJiraIssueKeys(combinedText, o.projectKeys) | ||
| issueIDs := jira.FindJiraIssueKeys(jiraSearchText(commitInfo, o.secondarySource, o.ignoreBranchMatch), o.projectKeys) | ||
| logger.Debug("Checked for Jira issue references in Git commit %s on branch %s commit message:\n%s", commitInfo.Sha1, commitInfo.Branch, commitInfo.Message) | ||
| logger.Debug("the following Jira references are found in commit message or branch name: %v", issueIDs) | ||
| @@ -374,18 +366,32 @@ func (o *attestJiraOptions) run(args []string) error { | ||
| return wrapAttestationError(err) | ||
| } | ||
| func (o *attestJiraOptions) validateJiraProjectKeys() error { | ||
| // According to Jira documentation https://confluence.atlassian.com/adminjiraserver/changing-the-project-key-format-938847081.html | ||
| // the Jira project key has to start with a capital letter and can then have capital letters numbers and underscore. | ||
| // But Jira itself will accept lower case letters when searching a repository for matching branches and commits | ||
| matchesJiraProjectKeys, err := regexp.Compile("^[A-Za-z][A-Za-z0-9_]{1,9}$") | ||
| if err != nil { | ||
| return err | ||
| // jiraSearchText joins the texts that are searched for Jira issue keys: the commit | ||
| // message, the branch name unless ignoreBranchMatch is set, and the secondary source | ||
| // when one is given. | ||
| func jiraSearchText(commitInfo *gitview.CommitInfo, secondarySource string, ignoreBranchMatch bool) string { | ||
| searchTexts := []string{commitInfo.Message} | ||
| if !ignoreBranchMatch { | ||
| searchTexts = append(searchTexts, commitInfo.Branch) | ||
| } | ||
| if secondarySource != "" { | ||
| searchTexts = append(searchTexts, secondarySource) | ||
| } | ||
| return strings.Join(searchTexts, "\n") | ||
| } | ||
| // jiraProjectKeyRegexp is compiled once, so validateJiraProjectKeys does not re-compile a | ||
| // constant pattern on every invocation. | ||
| // | ||
| // According to Jira documentation https://confluence.atlassian.com/adminjiraserver/changing-the-project-key-format-938847081.html | ||
| // the Jira project key has to start with a capital letter and can then have capital letters numbers and underscore. | ||
| // But Jira itself will accept lower case letters when searching a repository for matching branches and commits. | ||
| var jiraProjectKeyRegexp = regexp.MustCompile("^[A-Za-z][A-Za-z0-9_]{1,9}$") | ||
| func (o *attestJiraOptions) validateJiraProjectKeys() error { | ||
| invalidKeys := []string{} | ||
| for _, projectKey := range o.projectKeys { | ||
| isValid := matchesJiraProjectKeys.MatchString(projectKey) | ||
| isValid := jiraProjectKeyRegexp.MatchString(projectKey) | ||
| if !isValid { | ||
mbevc1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| invalidKeys = append(invalidKeys, projectKey) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.