Skip to content

Commit

Permalink
Use recommended stream instead of alpha in code.quarkus links
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Mar 15, 2023
1 parent f9c3053 commit 0cf9da5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/components/util/code-quarkus-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ const codeQuarkusUrl = ({ artifact, unlisted, platforms, streams }) => {
// Don't return a URL if the streams aren't available on code.quarkus
const currentStreams =
streams && streams.filter(stream => stream.isLatestThree)
// Choose a stream arbitrarily if there are multiple, since we have no good basis for choosing; almost always there will only be one, and it will be the latest
if (currentStreams?.length > 0 && currentStreams[0]) {
const stream = currentStreams[0]
// We could perhaps do proper url encoding, but home-roll an encoded url
const streamQuery = `&S=${stream.platformKey}%3A${stream.id}`
return `https://code.quarkus.io/?e=${trimmedArtifactId}${streamQuery}`
const isCurrent = currentStreams?.length > 0
if (isCurrent) {
// Choose a stream arbitrarily if there are multiple, since we have no good basis for choosing; almost always there will only be one, and it will be the latest
// Do not put in a stream if it's an alpha
const stream = currentStreams.find(s => !s.isAlpha)
if (stream) {
// We could perhaps do proper url encoding, but home-roll an encoded url
const streamQuery = `&S=${stream.platformKey}%3A${stream.id}`
return `https://code.quarkus.io/?e=${trimmedArtifactId}${streamQuery}`
} else {
return `https://code.quarkus.io/?e=${trimmedArtifactId}`
}
}
} else {
return `https://code.quarkus.io/?e=${coordinates.groupId}%3A${coordinates.artifactId}`
Expand Down
20 changes: 19 additions & 1 deletion src/components/util/code-quarkus-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("code quarkus url generator", () => {
it("returns a minimal query string for platform extensions", () => {
expect(
codeQuarkusUrl({
artifact: "io.quarkus:quarkus-vertx:3.0.0.Alpha3",
artifact: "io.quarkus:quarkus-vertx:3.0.0.Final",
platforms: ["quarkus-bom-quarkus-platform-descriptor"],
streams: [
{
Expand Down Expand Up @@ -43,6 +43,24 @@ describe("code quarkus url generator", () => {
)
})

// Make a (risky, but better than the alternative) assumption that the things in alphas were also in previous releases
it("returns a url, but with no stream, for alphas", () => {
expect(
codeQuarkusUrl({
artifact: "io.quarkus:quarkus-vertx:3.0.0.Alpha3",
platforms: ["quarkus-bom-quarkus-platform-descriptor"],
streams: [
{
platformKey: "io.quarkus.platform",
id: "3.0.0.Alpha4",
isLatestThree: true,
isAlpha: true,
},
],
})
).toBe("https://code.quarkus.io/?e=vertx")
})

it("does not attempt to build a url for unlisted extensions", () => {
expect(
codeQuarkusUrl({
Expand Down
2 changes: 2 additions & 0 deletions src/components/util/pretty-platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ const getStream = (origin, currentPlatforms) => {
)
const isLatestThree =
platform?.streams.find(stream => stream.id === id) != null
const isAlpha = /Alpha/.test(versionParts[3])
return {
platformKey: coordinates.groupId,
id: id,
isLatestThree,
isAlpha,
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/components/util/pretty-platform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ describe("stream extractor", () => {
).toBe(true)
})

it("correctly identifies not-alphas are not alphas", () => {
expect(
getStream(
"io.quarkus.platform:quarkus-bom-quarkus-platform-descriptor:2.15.0:json:2.15.0",
currentPlatforms
).isAlpha
).toBe(false)
})

it("correctly identifies alphas are alphas", () => {
expect(
getStream(
"io.quarkus.platform:quarkus-bom-quarkus-platform-descriptor:1.0.0.Alpha2:json:1.0.0.Alpha2",
currentPlatforms
).isAlpha
).toBe(true)
})

it("extracts the stream for an origin with an alpha qualifier", () => {
expect(
getStream(
Expand All @@ -156,6 +174,7 @@ describe("stream extractor", () => {
platformKey: "io.quarkus.platform",
id: "3.0",
isLatestThree: true,
isAlpha: true,
})
})

Expand All @@ -169,6 +188,7 @@ describe("stream extractor", () => {
platformKey: "io.quarkus.platform",
id: "1.2",
isLatestThree: false,
isAlpha: false,
})
})
})
1 change: 1 addition & 0 deletions src/templates/extension-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export const pageQuery = graphql`
streams {
id
isLatestThree
isAlpha
platformKey
}
duplicates {
Expand Down

0 comments on commit 0cf9da5

Please sign in to comment.