-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Migrate [Jira] services to new service model #2541
Conversation
|
Also is there a pattern when writing service tests to cover lines that are using auth info from |
No… though it would be possible! You could use an IcedFrisby
The cleanup would go in an IcedFrisby You could generalize the code here into a shields/services/github/auth/admin.spec.js Lines 24 to 35 in b4b29ab
|
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.
This looks awesome! Thanks for the tests! I left you a few minor comments.
services/jira/jira-issue.service.js
Outdated
} | ||
|
||
static get route() { | ||
return { | ||
base: 'jira/issue', | ||
pattern: ':protocol(https?)/:host/:path?/:issueKey', |
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.
- The regex in this pattern confused me for a moment.
:protocol(http|https)
seems clearer. - I think you need
:path*
to allow multiple path segments.
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.
👍 on protocol
path
is where I kept hitting a a mental wall with the pattern. I was trying to use nested non-capture groups but pattern was having none of it 😆 Let me see if I can clean that up a bit
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 ended up using a specific regex ((.+)
) for the host param, which works and is more consistent with the legacy service info (which did not explicitly differentiate host and path)
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'm fine with the change you made, though I think hostAndPath
would better describe the field for the user (this is with #2496 in mind).
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.
yeah I like that better too (and that's what was there before so +1 for consistency!)
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.
changed to hostAndPath
in both the example pattern, route pattern, and param to handle for consistency. I elected not to include the +
suffix but let me know if it is needed
(original comment) i'm probably being overly pedantic here, but just noticed the example pattern before was actually hostAndPath+
does the +
suffix have any significance in the example patterns/is it worth including?
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.
In a pattern, the + tells pathToRegexp to allow one or more segments instead of just one, zero or one, or zero or more. We aren’t doing anything using the pattern in the examples beyond parsing it to get the individual segments. (That’s forthcoming actually, in #2496)
services/jira/jira-sprint.service.js
Outdated
url += '/rest/api/2/search' | ||
const options = { | ||
qs: { | ||
jql: `sprint=${sprintId} AND type IN (Bug,Improvement,Story,"Technical task")`, |
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 added the above comment on url
to indicate the usage of search
over sprint
API, and I totally get why it is implemented that way. However, I could envision some potential issues due the issue type clause that we have to put into the jql query. Jira is used by some teams at my day job, and we've created many custom issue types (like 12387123897612387123 of them 😄) that wouldn't be accurately reflected by this query.
IMO we shouldn't try to solve that in this PR, but it may be worth revisiting at some point
Thanks for the feedback! I think I've addressed everything, and also added a test helpers file to help facilitate the setup/restore to validate auth scenarios |
} | ||
|
||
function restore() { | ||
sinon.restore() |
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.
It looks like this function is not intended to be used publicly: sinonjs/sinon#1390
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.
Since [email protected] the default object is itself a sandbox, and most of the documentation says to use that directly for the majority of use cases, https://sinonjs.org/releases/v7.2.2/sandbox/.
They show this pattern, including the restore
function on the docs for migrating to [email protected] https://sinonjs.org/guides/migrating-to-5.0.html.
In that issue I see references to [email protected]/4.x so maybe the usage of restore
has changed?
.intercept(nock => | ||
nock('https://myprivatejira.com/rest/api/2/issue') | ||
.get(`/${encodeURIComponent('secure-234')}`) | ||
.basicAuth({ |
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.
Since this pattern is a bit unfamiliar, you could comment here that by including this here, it ensures the credentials are actually being sent out with the HTTP request. Otherwise the request wouldn't match and the test would fail.
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.
Nice work on this test, by the way!
btw @calebcartwright I wanted to reach out and see about setting up a time to say hi. Could you shoot a quick message? The address on my profile works. |
will do! |
Augmenting the tests for Jira that were added in #2541 to also validate color scheme
Migrates the Jira badge services to the new service model, and also adds tests for those badges.
I did make one minor changes to the badge labels/messages when the issue or sprint cannot be found. For example:
With the LegacyService implementation, when an issue was not found the badge would display as 'issue key | inaccessible' such as
KAFKA-2869 | inaccessible
but this changes that behavior tojira | issue not found
. I personally find this to be a bit more informative of a message, but want to call it out as I know how important backwards compatibility is. However, at first glance I'm also not sure how we'd replicate the old behavior of using the issue key (provided by user as a param) as the badge label when an issue is not found because the API response has a status code of 404 and a different schema than what Joi is expecting/validating.Similarly for the sprints, the old format for a sprint not found was
completion | inaccessible
it's nowjira | sprint not found