Skip to content

Commit

Permalink
fix(winget/version): confusing subpackage and version name
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Nov 3, 2024
1 parent 439a7e0 commit aabbc38
Show file tree
Hide file tree
Showing 2 changed files with 300 additions and 3 deletions.
33 changes: 30 additions & 3 deletions services/winget/winget-version.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const schema = Joi.object({
Joi.object({
type: Joi.string().required(),
name: Joi.string().required(),
object: Joi.object({
entries: Joi.array().items(
Joi.object({
type: Joi.string().required(),
name: Joi.string().required(),
}),
),
}).required(),
}),
),
})
Expand Down Expand Up @@ -64,6 +72,14 @@ export default class WingetVersion extends GithubAuthV4Service {
entries {
type
name
object {
... on Tree {
entries {
type
name
}
}
}
}
}
}
Expand All @@ -78,16 +94,27 @@ export default class WingetVersion extends GithubAuthV4Service {

async handle({ name }) {
const json = await this.fetch({ name })
if (json.data.repository.object === null) {
if (json.data.repository.object?.entries == null) {
throw new InvalidParameter({
prettyMessage: 'package not found',
})
}
const entries = json.data.repository.object.entries
const directories = entries.filter(file => file.type === 'tree')
const versions = directories.map(file => file.name)
const directories = entries.filter(entry => entry.type === 'tree')
const versionDirs = directories.filter(dir =>
dir.object.entries.some(
file => file.type === 'blob' && file.name === `${name}.yaml`,
),
)
const versions = versionDirs.map(dir => dir.name)
const version = latest(versions)

if (version == null) {
throw new InvalidParameter({
prettyMessage: 'no versions found',
})
}

return renderVersionBadge({ version })
}
}
270 changes: 270 additions & 0 deletions services/winget/winget-version.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,202 @@ t.create('gets the latest version')
{
type: 'tree',
name: '0.1001.389.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.1101.416.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.1201.442.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.137.141.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.200.170.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.503.261.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.601.285.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.601.297.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.701.323.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
{
type: 'tree',
name: '0.801.344.0',
object: {
entries: [
{
type: 'blob',
name: 'Microsoft.DevHome.installer.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Microsoft.DevHome.yaml',
},
],
},
},
],
},
Expand All @@ -71,3 +231,113 @@ t.create('gets the latest version')
)
.get('/Microsoft.DevHome.json')
.expectBadge({ label: 'winget', message: 'v0.1201.442.0' })

// Both 'Some.Package' and 'Some.Package.Sub' are present in the response.
// We should ignore 'Some.Package.Sub' in response to 'Some.Package' request.
// In this test case, Canonical.Ubuntu.2404 is present, but it should not be treated as Canonical.Ubuntu version 2404.
t.create('do not pick sub-package as version')
.intercept(nock =>
nock('https://api.github.com/')
.post('/graphql')
.reply(200, {
data: {
repository: {
object: {
entries: [
{
type: 'blob',
name: '.validation',
object: {},
},
{
type: 'tree',
name: '1804',
object: {
entries: [
{
type: 'tree',
name: '1804.6.4.0',
},
],
},
},
{
type: 'tree',
name: '2004',
object: {
entries: [
{
type: 'tree',
name: '2004.6.16.0',
},
],
},
},
{
type: 'tree',
name: '2204.1.8.0',
object: {
entries: [
{
type: 'blob',
name: 'Canonical.Ubuntu.installer.yaml',
},
{
type: 'blob',
name: 'Canonical.Ubuntu.locale.en-US.yaml',
},
{
type: 'blob',
name: 'Canonical.Ubuntu.locale.zh-CN.yaml',
},
{
type: 'blob',
name: 'Canonical.Ubuntu.yaml',
},
],
},
},
{
type: 'tree',
name: '2204',
object: {
entries: [
{
type: 'blob',
name: '.validation',
},
{
type: 'tree',
name: '2204.0.10.0',
},
{
type: 'tree',
name: '2204.2.47.0',
},
],
},
},
{
type: 'tree',
name: '2404',
object: {
entries: [
{
type: 'blob',
name: '.validation',
},
{
type: 'tree',
name: '2404.0.5.0',
},
],
},
},
],
},
},
},
}),
)
.get('/Canonical.Ubuntu.json')
.expectBadge({ label: 'winget', message: 'v2204.1.8.0' })

0 comments on commit aabbc38

Please sign in to comment.