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.
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
Add Wikiapiary Extension Badge [WikiapiaryInstalls] #6678
Add Wikiapiary Extension Badge [WikiapiaryInstalls] #6678
Changes from 2 commits
3529906
af2ef56
d3de7ec
84f3888
30ba489
8df3ed1
eb40619
30dbe0c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've still got a case-sensitivity issue here. e.g:
wikiapiary/Extension/installs/parserFunctions
It seems fundamentally the difficulty stems from the fact the query is case-insensitive (kind of) but the response isn't.
Would it work if we lowercase the args and lowercase the keys in the results array
to do a case-insensitive comparison?
That would also conveniently allow us to make the options for the
:variant
param lowercase. In general, we tend to avoid having uppercase characters in the bit of the URL that is not the repo/package/whatever.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh strange. 🤔
I'll update this PR later.
I tested case-sensitivity and it worked when I tried it, but I used
Parserfunctions
, which returned no result. (So I assumed the extension name was itself case-sensitive.)Not sure why
parserFunctions
works, butParserfunctions
returns no result. 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there is also an issue that the upstream API behaves somewhat esoterically.
Note that
wikiapiary/Extension/installs/parserFunctions
causes an error (even though the API does return the stats) butwikiapiary/Extension/installs/pArserfunctions
is just a not found (which obviously we can't do anything about)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully, this should be resolved now.
I've addressed the issue with case-sensitivity, using an approach similar to what you suggested. (not identical)
I've also added documentation to the badge to clarify the odd behavior.
Unfortunately, I couldn't see documentation upstream to definitively state exactly what is accepted and what isn't.
I just tested a bunch in Insomnia, and attempted to infer a conclusion from there.
Let me know if that's not favorable!
Screenshot:
Alternatives
One alternative approach to selecting the correct value could be to just not use a key at all.
It appears (but I do not definitively know) that we could just get an array of values from the
results
(as in ignore the keys) and just select the first (and only from what I can tell) property.I just don't know if that's a good idea, as I'm not aware of the upstream behavior. 🤔
One thing you could drop an opinion, on line 97 I throw an error if the key we're after can't be found.
I don't know of a way to actually trigger than error because logically, it should never get there.
Is that fine do you think, or shall I use a different error type/message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - me either. I think the implementation as it stands is fine 👍
The check should probably be
if (resultKey === undefined)...
rather thanif (!resultKey)...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find#return_value
I'm not exactly sure what you mean here. I think throwing a
NotFound
is probably an OK choice of exception there. If you're not sure how to write a test for it, you could write a mocked test (see the docs: https://github.com/badges/shields/blob/master/doc/service-tests.md#5-mocking-responses ) and then you can make the request return an intentionally malformed object under to test to hit that case. If you mean something else maybve you can give an example?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant, it appears that the upstream API would never normally return a response that would trigger such an error.
In other words, I was clarifying that I was just writing defensive code, rather than covering an actual edge-case.
Since you mention it, I've tried adding a test case anyway, but it's not going well. 🤔
I've spent a fair bit of time on this, but I fail to see what's wrong. 🤔
I can make this work if I use regular expression, but not with a string literal.
Both of the following work:
/.+/
/^\/w\/api\.php\?action=ask&query=\[\[extension:ParserFunctions\]\]%7C\?Has_website_count&format=json$/
Trial and error hell, but I can use a strict regular expression if I replace
|
with the URL encoded equivalent.However, the string literal equivalent still doesn't pass.
Just wanted to share here. I'm not sure if I'm being stupid, or if it's an issue in nock, but something seems wrong here to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Seth! 👋🏼
I would programmatically URL-encode the weird bit of your query string:
Alternatively you can use
.query()
:If that doesn't work, you can debug the nock match with all sorts of verbose detail by setting
DEBUG=nock.*
when you run the test. (Add.only()
to the test if necessary.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh! Thanks for that!
I had already tried URL encoding the parameters before.
Unfortunately, the
.query
method didn't help either.However... those were my fault.
Thanks to your tip for debugging the nock requests, I found the issue was with the request being made in the service class. The request wasn't being URL encoded in the service, so the interceptor wrongly interpreted/compared it from there.
Actual
Expected
I've switched both to just use the dedicated
options.qs
/query
property now.I'll keep that in mind for future reference as well.