-
-
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
Use release/latest fields of [mavenmetadata] instead of last version in the versions, add according query parameter #6594
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,14 +7,14 @@ const { BaseXmlService } = require('..') | |||||
|
||||||
const queryParamSchema = Joi.object({ | ||||||
metadataUrl: optionalUrl.required(), | ||||||
latestOrRelease: Joi.string().valid('release', 'latest').optional(), | ||||||
}).required() | ||||||
|
||||||
const schema = Joi.object({ | ||||||
metadata: Joi.object({ | ||||||
versioning: Joi.object({ | ||||||
versions: Joi.object({ | ||||||
version: Joi.array().items(Joi.string().required()).single().required(), | ||||||
}).required(), | ||||||
latest: Joi.string().required(), | ||||||
release: Joi.string().required(), | ||||||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we positive both of these elements will always be there? What does the xml look like for a package that has no releases/only snapshots? Based on the example you shared it seems like it the |
||||||
}).required(), | ||||||
}).required(), | ||||||
}).required() | ||||||
|
@@ -35,6 +35,7 @@ module.exports = class MavenMetadata extends BaseXmlService { | |||||
queryParams: { | ||||||
metadataUrl: | ||||||
'https://repo1.maven.org/maven2/com/google/code/gson/gson/maven-metadata.xml', | ||||||
latestOrRelease: 'latest', | ||||||
}, | ||||||
staticPreview: renderVersionBadge({ version: '2.8.5' }), | ||||||
}, | ||||||
|
@@ -52,10 +53,19 @@ module.exports = class MavenMetadata extends BaseXmlService { | |||||
}) | ||||||
} | ||||||
|
||||||
async handle(_namedParams, { metadataUrl }) { | ||||||
async handle(_namedParams, { metadataUrl, latestOrRelease }) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would need to be changed accordingly (with rename in destructuring to satiate the linters):
Suggested change
|
||||||
const data = await this.fetch({ metadataUrl }) | ||||||
let v | ||||||
if ( | ||||||
latestOrRelease === 'latest' || | ||||||
typeof latestOrRelease === 'undefined' | ||||||
) { | ||||||
v = data.metadata.versioning.latest | ||||||
} else if (latestOrRelease === 'release') { | ||||||
v = data.metadata.versioning.release | ||||||
} | ||||||
return renderVersionBadge({ | ||||||
version: data.metadata.versioning.versions.version.slice(-1)[0], | ||||||
version: v, | ||||||
}) | ||||||
Comment on lines
+58
to
69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just FYI, a fairly common pattern in our service classes is to utilize another function We also default our version badges to showing the latest stable/release version ( If both the |
||||||
} | ||||||
} |
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.
One of the many areas we strive for consistency within Shields (beyond the svg's themselves) are things like the badge route patterns and query parameter names for common functions.
For the latest vs. release function we use a query param name of
include_prereleases
, and the presence of the param providing the implicit boolean value.