Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
7592b715
Unverified
Commit
7592b715
authored
6 months ago
by
Ryan Laurie
Committed by
GitHub
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Refine 'last' version logic (#47512)
* refine 'last' version logic * better comment placement
parent
a359852b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
release/src/milestones.ts
+1
-0
1 addition, 0 deletions
release/src/milestones.ts
release/src/version-helpers.ts
+7
-6
7 additions, 6 deletions
release/src/version-helpers.ts
release/src/version-helpers.unit.spec.ts
+22
-9
22 additions, 9 deletions
release/src/version-helpers.unit.spec.ts
with
30 additions
and
15 deletions
release/src/milestones.ts
+
1
−
0
View file @
7592b715
...
...
@@ -298,6 +298,7 @@ export async function checkMilestoneForRelease({
owner
,
repo
,
version
,
ignorePatches
:
true
,
// ignore patch versions since we don't release notes for them
});
const
compareResponse
=
await
github
.
rest
.
repos
.
compareCommitsWithBasehead
({
...
...
This diff is collapsed.
Click to expand it.
release/src/version-helpers.ts
+
7
−
6
View file @
7592b715
...
...
@@ -232,32 +232,33 @@ export function versionSort(a: string, b: string) {
return
0
;
}
export
function
getLastReleaseFromTags
(
tags
:
Tag
[]
)
{
export
function
getLastReleaseFromTags
(
{
tags
,
ignorePatches
=
false
}:
{
tags
:
Tag
[],
ignorePatches
?:
boolean
}
)
{
return
tags
.
map
(
tag
=>
tag
.
ref
.
replace
(
'
refs/tags/
'
,
''
))
.
filter
(
tag
=>
!
isRCVersion
(
tag
))
// we want to ignore RC tags because release notes should be cumulative
.
filter
(
v
=>
!
isPatchVersion
(
v
)
)
// ignore patch versions since we don't release notes for them
.
filter
(
ignorePatches
?
v
=>
!
isPatchVersion
(
v
)
:
()
=>
true
)
.
sort
(
versionSort
)
.
reverse
()[
0
];
}
/**
* queries the github api to get all release version tags,
* optionally filtered by a major version
* optionally filtered by a major version
, and can optionally exclude patch versions
*/
export
async
function
getLastReleaseTag
({
github
,
owner
,
repo
,
version
=
''
,
}:
GithubProps
&
{
version
?:
string
})
{
ignorePatches
=
false
,
}:
GithubProps
&
{
version
?:
string
,
ignorePatches
?:
boolean
})
{
const
tags
=
await
github
.
paginate
(
github
.
rest
.
git
.
listMatchingRefs
,
{
owner
,
repo
,
ref
:
`tags/v0.
${
version
?
getMajorVersion
(
version
)
:
''
}
`
,
});
const
lastRelease
=
getLastReleaseFromTags
(
tags
);
const
lastRelease
=
getLastReleaseFromTags
(
{
tags
,
ignorePatches
}
);
return
lastRelease
;
}
...
...
@@ -283,7 +284,7 @@ export const getNextPatchVersion = async ({
}:
GithubProps
&
{
majorVersion
:
number
})
=>
{
const
lastRelease
=
await
getLastReleaseTag
({
github
,
owner
,
repo
,
version
:
`v0.
${
majorVersion
.
toString
()}
.0`
version
:
`v0.
${
majorVersion
.
toString
()}
.0`
,
});
const
nextPatch
=
findNextPatchVersion
(
lastRelease
);
...
...
This diff is collapsed.
Click to expand it.
release/src/version-helpers.unit.spec.ts
+
22
−
9
View file @
7592b715
...
...
@@ -474,16 +474,16 @@ describe("version-helpers", () => {
describe
(
'
getLastReleaseFromTags
'
,
()
=>
{
it
(
'
should return the latest release tag for minor versions
'
,
()
=>
{
const
latest
=
getLastReleaseFromTags
([
const
latest
=
getLastReleaseFromTags
(
{
tags
:
[
{
ref
:
'
refs/tags/v0.12.0
'
},
{
ref
:
'
refs/tags/v0.12.2
'
},
{
ref
:
'
refs/tags/v0.12.1
'
},
]
as
Tag
[]);
]
as
Tag
[]
}
);
expect
(
latest
).
toBe
(
'
v0.12.2
'
);
});
it
(
'
should
not
return the latest release tag for patch versions
'
,
()
=>
{
const
latest
=
getLastReleaseFromTags
([
it
(
'
should return the latest release tag for patch versions
'
,
()
=>
{
const
latest
=
getLastReleaseFromTags
(
{
tags
:
[
{
ref
:
'
refs/tags/v0.12.0
'
},
{
ref
:
'
refs/tags/v0.11.2
'
},
{
ref
:
'
refs/tags/v0.12.2
'
},
...
...
@@ -491,25 +491,38 @@ describe("version-helpers", () => {
{
ref
:
'
refs/tags/v0.12.2.0
'
},
{
ref
:
'
refs/tags/v0.12.2.3
'
},
{
ref
:
'
refs/tags/v0.12.2.2
'
},
]
as
Tag
[]);
]
as
Tag
[]});
expect
(
latest
).
toBe
(
'
v0.12.2.3
'
);
});
it
(
'
should ignore patches when the ignorePatches flag is passed
'
,
()
=>
{
const
latest
=
getLastReleaseFromTags
({
tags
:
[
{
ref
:
'
refs/tags/v0.12.0
'
},
{
ref
:
'
refs/tags/v0.11.2
'
},
{
ref
:
'
refs/tags/v0.12.2
'
},
{
ref
:
'
refs/tags/v0.12.1
'
},
{
ref
:
'
refs/tags/v0.12.2.0
'
},
{
ref
:
'
refs/tags/v0.12.2.3
'
},
{
ref
:
'
refs/tags/v0.12.2.2
'
},
]
as
Tag
[],
ignorePatches
:
true
});
expect
(
latest
).
toBe
(
'
v0.12.2
'
);
});
it
(
'
should return the latest tag for major version
'
,
()
=>
{
const
latest
=
getLastReleaseFromTags
([
const
latest
=
getLastReleaseFromTags
(
{
tags
:
[
{
ref
:
'
refs/tags/v0.12.9
'
},
{
ref
:
'
refs/tags/v0.12.8
'
},
{
ref
:
'
refs/tags/v0.13.0
'
},
]
as
Tag
[]);
]
as
Tag
[]
}
);
expect
(
latest
).
toBe
(
'
v0.13.0
'
);
});
it
(
'
should ignore release candidates
'
,
()
=>
{
const
latest
=
getLastReleaseFromTags
([
const
latest
=
getLastReleaseFromTags
(
{
tags
:
[
{
ref
:
'
refs/tags/v0.12.0
'
},
{
ref
:
'
refs/tags/v0.12.2-RC99
'
},
{
ref
:
'
refs/tags/v0.12.1
'
},
]
as
Tag
[]);
]
as
Tag
[]
}
);
expect
(
latest
).
toBe
(
'
v0.12.1
'
);
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment