-
-
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?
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BaseXmlService } from '../index.js' | ||
|
||
export default class MavenCentralSnapshotsBase extends BaseXmlService { | ||
async fetch({ groupId, artifactId, schema }) { | ||
const group = encodeURIComponent(groupId).replace(/\./g, '/') | ||
const artifact = encodeURIComponent(artifactId) | ||
return this._requestXml({ | ||
schema, | ||
url: `https://central.sonatype.com/repository/maven-snapshots/${group}/${artifact}/maven-metadata.xml`, | ||
httpErrors: { 404: 'artifact not found' }, | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Joi from 'joi' | ||
import { pathParams } from '../index.js' | ||
import { parseDate, renderDateBadge } from '../date.js' | ||
import { nonNegativeInteger } from '../validators.js' | ||
import MavenCentralSnapshotsBase from './maven-central-snapshots-base.js' | ||
|
||
const updateResponseSchema = Joi.object({ | ||
metadata: Joi.object({ | ||
versioning: Joi.object({ | ||
lastUpdated: nonNegativeInteger, | ||
}).required(), | ||
}).required(), | ||
}).required() | ||
|
||
export default class MavenCentralSnapshotsLastUpdate extends MavenCentralSnapshotsBase { | ||
static category = 'activity' | ||
|
||
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: 'com.google.guava' }, | ||
{ name: 'artifactId', example: 'guava' }, | ||
), | ||
}, | ||
}, | ||
} | ||
|
||
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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { isFormattedDate } from '../test-validators.js' | ||
import { createServiceTester } from '../tester.js' | ||
export const t = await createServiceTester() | ||
|
||
t.create('last update date') | ||
.get('/me.mrdoc.minecraft/dlibcustomextensions.json') | ||
.expectBadge({ | ||
label: 'last updated', | ||
message: isFormattedDate, | ||
}) | ||
|
||
t.create('last update when artifact not found') | ||
.get('/com.fail.test/this-does-not-exist.json') | ||
.expectBadge({ | ||
label: 'last updated', | ||
message: 'artifact not found', | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { redirector, pathParam, queryParam } from '../index.js' | ||
import { description } from '../maven-metadata/maven-metadata.js' | ||
|
||
export default redirector({ | ||
category: 'version', | ||
isDeprecated: false, | ||
route: { | ||
base: 'maven-central-snapshots/v', | ||
pattern: ':groupId/:artifactId/:versionPrefix?', | ||
}, | ||
openApi: { | ||
'/maven-central-snapshots/v/{groupId}/{artifactId}': { | ||
get: { | ||
summary: 'Maven Central Snapshots Version', | ||
description, | ||
parameters: [ | ||
pathParam({ name: 'groupId', example: 'com.google.guava' }), | ||
pathParam({ name: 'artifactId', example: 'guava' }), | ||
Comment on lines
+17
to
+18
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. Can we also replace this with an example that works |
||
queryParam({ | ||
name: 'versionPrefix', | ||
example: '29', | ||
description: 'Filter only versions with this prefix.', | ||
}), | ||
queryParam({ | ||
name: 'versionSuffix', | ||
example: '-android', | ||
description: 'Filter only versions with this suffix.', | ||
}), | ||
Comment on lines
+19
to
+28
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. 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 |
||
], | ||
}, | ||
}, | ||
}, | ||
transformPath: () => '/maven-metadata/v', | ||
transformQueryParams: ({ groupId, artifactId, versionPrefix }) => { | ||
const group = encodeURIComponent(groupId).replace(/\./g, '/') | ||
const artifact = encodeURIComponent(artifactId) | ||
const metadataUrl = `https://central.sonatype.com/repository/maven-snapshots/${group}/${artifact}/maven-metadata.xml` | ||
return { | ||
metadataUrl, | ||
label: 'maven-central-snapshots', | ||
versionPrefix, | ||
} | ||
}, | ||
overrideTransformedQueryParams: true, | ||
dateAdded: new Date('2021-06-12'), | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createServiceTester } from '../tester.js' | ||
export const t = await createServiceTester() | ||
|
||
t.create('latest version redirection') | ||
.get('/me.mrdoc.minecraft/dlibcustomextensions.json') // https://central.sonatype.com/repository/maven-snapshots/me/mrdoc/minecraft/dlibcustomextensions/ | ||
.expectRedirect( | ||
`/maven-metadata/v.json?label=maven-central-snapshots&metadataUrl=${encodeURIComponent( | ||
'https://central.sonatype.com/repository/maven-snapshots/me/mrdoc/minecraft/dlibcustomextensions/maven-metadata.xml', | ||
)}`, | ||
) |
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