-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Maven] Support for maven central snapshots #10997
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
base: master
Are you sure you want to change the base?
Conversation
maven central remove old snapshots then this test can cause issues if try to check a removed version
9f708f1
to
4b400ac
Compare
looking forward to this! |
{ name: 'groupId', example: 'com.google.guava' }, | ||
{ name: 'artifactId', example: 'guava' }, |
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.
Can we replace this with an example that works
OK, so we've got 2 things going on here. First lets take the last updated badge. This one should be fairly simple to land. import Joi from 'joi'
import { pathParams, BaseXmlService } from '../index.js'
import { parseDate, renderDateBadge } from '../date.js'
import { nonNegativeInteger } from '../validators.js'
const updateResponseSchema = Joi.object({
metadata: Joi.object({
versioning: Joi.object({
lastUpdated: nonNegativeInteger,
}).required(),
}).required(),
}).required()
class MavenCentralLastUpdateBase extends BaseXmlService {
static category = 'activity'
static defaultBadgeData = { label: 'last updated' }
async handle({ groupId, artifactId }) {
const { metadata } = await this.fetch({
groupId,
artifactId,
schema: updateResponseSchema,
})
const date = parseDate(
String(metadata.versioning.lastUpdated),
'YYYYMMDDHHmmss',
)
return renderDateBadge(date)
}
static encodeParams({ groupId, artifactId }) {
return {
group: encodeURIComponent(groupId).replace(/\./g, '/'),
artifact: encodeURIComponent(artifactId),
}
}
}
class MavenCentralLastUpdate extends MavenCentralLastUpdateBase {
static route = {
base: 'maven-central/last-update',
pattern: ':groupId/:artifactId',
}
static openApi = {
'/maven-central/last-update/{groupId}/{artifactId}': {
get: {
summary: 'Maven Central Last Update',
parameters: pathParams(
{ name: 'groupId', example: 'com.google.guava' },
{ name: 'artifactId', example: 'guava' },
),
},
},
}
async fetch({ groupId, artifactId, schema }) {
const { group, artifact } = this.constructor.encodeParams({
groupId,
artifactId,
})
return this._requestXml({
schema,
url: `https://repo1.maven.org/maven2/${group}/${artifact}/maven-metadata.xml`,
httpErrors: { 404: 'artifact not found' },
})
}
}
class MavenCentralSnapshotsLastUpdate extends MavenCentralLastUpdateBase {
static route = {
base: 'maven-central-snapshots/last-update',
pattern: ':groupId/:artifactId',
}
static openApi = {
'/maven-central-snapshots/last-update/{groupId}/{artifactId}': {
get: {
summary: 'Maven Central Snapshots Last Update',
parameters: pathParams(
{ name: 'groupId', example: 'me.mrdoc.minecraft' },
{ name: 'artifactId', example: 'dlibcustomextensions' },
),
},
},
}
async fetch({ groupId, artifactId, schema }) {
const { group, artifact } = this.constructor.encodeParams({
groupId,
artifactId,
})
return this._requestXml({
schema,
url: `https://central.sonatype.com/repository/maven-snapshots/${group}/${artifact}/maven-metadata.xml`,
httpErrors: { 404: 'artifact not found' },
})
}
}
export default [MavenCentralLastUpdate, MavenCentralSnapshotsLastUpdate] (that can all go in one file) |
queryParam({ | ||
name: 'versionPrefix', | ||
example: '29', | ||
description: 'Filter only versions with this prefix.', | ||
}), | ||
queryParam({ | ||
name: 'versionSuffix', | ||
example: '-android', | ||
description: 'Filter only versions with this suffix.', | ||
}), |
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.
Secondly, lets look at the version badge.
This isn't really your fault, but the maven central version badge has a long-standing issue. #6188
I think it is likely we will remove the versionPrefix
and versionSuffix
params (see #6188 (comment) )
If we are going to add a specific route for this (although you can already make badges for this service anyway e.g: https://img.shields.io/maven-metadata/v.svg?label=maven-central-snapshots&metadataUrl=https%3A//central.sonatype.com/repository/maven-snapshots/me/mrdoc/minecraft/dlibcustomextensions/maven-metadata.xml as the routes are just redirectors for the more general maven-metadata route), then I think we should not expose the versionPrefix
and versionSuffix
params on the documentation page. Lets not encourage users to start using a feature that is likely to disappear.
pathParam({ name: 'groupId', example: 'com.google.guava' }), | ||
pathParam({ name: 'artifactId', example: 'guava' }), |
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.
Can we also replace this with an example that works
This PR close #10894 making a replicate of the current services for maven-central but for the snapshots feature added recently.