Skip to content

Commit

Permalink
fix: milestone matching
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jan 23, 2024
1 parent c7edb9b commit 57d4cc6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
69 changes: 69 additions & 0 deletions src/nextcloudUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, expect, test } from 'vitest'
import { Milestone } from '@octokit/webhooks-types'
import { getMilestoneFromBase } from './nextcloudUtils'

describe('Match branch branch to milestone', () => {
const branches = [
'stable28',
'stable26',
'stable21',
'stable1',
'stable-3.11',
'stable-4.0.0',
]

const milestones = [
'Nextcloud 21.1.0',
'Nextcloud 21.0.1',
'Nextcloud 26.0.10',
'Nextcloud 26.0.9',
'Nextcloud 21.1.0',
'Nextcloud 1.0.0',
'Nextcloud 1.1.1',
'💞 Next Major (29)',
'💙 Next Patch (28)',
'💔 Backlog',
'3.11.1',
'3.10.4',
].map(title => ({ title })) as Milestone[]

const expectedMilestones = [
'💙 Next Patch (28)',
'Nextcloud 26.0.9',
'Nextcloud 21.0.1',
'Nextcloud 1.0.0',
'3.11.1',
undefined,
]

branches.forEach((branch, index) => {
test(`Branch '${branch}' should return milestone '${expectedMilestones[index]}'`, () => {
expect(getMilestoneFromBase(branch, milestones)?.title).toEqual(expectedMilestones[index])
})
})
})

describe('Throws error for invalid branch', () => {
const branches = [
'stable',
'',
]
const milestones = [
'Nextcloud 21.1.0',
'Nextcloud 21.0.1',
'Nextcloud 1.0.0',
'Nextcloud 1.1.1',
'💞 Next Major (29)',
'💙 Next Patch (28)',
'💔 Backlog',
'3.11.1',
'3.10.4',
].map(title => ({ title })) as Milestone[]

branches.forEach(branch => {
test(`Branch '${branch}'`, () => {
expect(() => getMilestoneFromBase(branch, milestones))
.toThrow(`Could not extract version from branch \`${branch}\``)
})
})
})
6 changes: 3 additions & 3 deletions src/nextcloudUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const compareSemanticVersions = (a: string, b: string) => {

export const getMilestoneFromBase = (branch: string, milestones: Milestone[]): Milestone => {
// Extract the version from the branch name, e.g. stable21
const version = branch.match(/stable(\d{2})/i)?.[1]
const version = branch.match(/^\D+([\d.]+)/i)?.[1]
if (!version) {
throw new Error(`Could not extract version from branch ${branch}`)
throw new Error(`Could not extract version from branch \`${branch}\``)
}
const selection = milestones
.filter(milestone => milestone.title.startsWith('Nextcloud ' + version))
.filter(milestone => milestone.title.includes(version))
.sort((a, b) => compareSemanticVersions(a.title, b.title))
return selection[0]
}
Expand Down

0 comments on commit 57d4cc6

Please sign in to comment.