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

d/pagerduty_vendor: Match whole string and fallback to partial matching #55

Merged
merged 1 commit into from
Feb 14, 2018

Conversation

heimweh
Copy link
Collaborator

@heimweh heimweh commented Jan 4, 2018

Fixes #54

This PR solves an issue where a vendor search for: "Sentry" would return "IPSentry" instead of "Sentry". To fix this we match the whole string instead.

@ghost
Copy link

ghost commented Jan 11, 2018

Hello @heimweh! We also experienced issue #54. Our first solution was to do an exact match too. But this might break backwards compatibility with users who expect to be able to provide partial matches. A more compatible approach might be to prefer the exact match but still support the partial match:

...
var found *pagerduty.Vendor = findVendor(resp.Vendors, searchName)
...

func findVendor(vendors []*pagerduty.Vendor, searchName string) (*pagerduty.Vendor) {
	r := regexp.MustCompile("(?i)" + searchName)
	var closeMatch *pagerduty.Vendor
  for _, vendor := range vendors {
		if searchName == vendor.Name {
			return vendor
		}
		if closeMatch == nil && r.MatchString(vendor.Name) {
			closeMatch = vendor
		}
	}

	return closeMatch
}

@heimweh
Copy link
Collaborator Author

heimweh commented Jan 11, 2018

Hi @yeungda-rea, thanks for your input.
I was actually about to tag this as a breaking change, but I totally agree with you.
It's better to fallback to partial matching if the exact match fails, to avoid a breaking change.

Updated the tests, so we should now be able to cover exact (default) and partial matching (fallback).

Note: the exact match is not super-exact, it still allows case-insensitive queries, to allow searching for example: "Sentry" or "sentry".

@heimweh heimweh changed the title d/pagerduty_vendor: Match whole string d/pagerduty_vendor: Match whole string and fallback to partial matching Jan 11, 2018
@ghost
Copy link

ghost commented Feb 1, 2018

This implementation looks like it would suit our needs. Looking forward to it being merged so we can stop carrying a patch for bug #54.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@heimweh heimweh merged commit 3263400 into PagerDuty:master Feb 14, 2018
@heimweh heimweh deleted the b-regexp-vendor branch February 14, 2018 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vendor Data Source can't find Sentry
2 participants