Skip to content

Commit 2f550fb

Browse files
authored
Merge pull request #114 from intersystems-community/stage
includePrerelease and includeSnapshots
2 parents f7e4087 + 5617543 commit 2f550fb

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Name>zpm-registry</Name>
66
<ExternalName>ZPM Registry</ExternalName>
77
<Description>Registry server for ZPM</Description>
8-
<Version>1.2.9</Version>
8+
<Version>1.3.0</Version>
99
<Packaging>module</Packaging>
1010
<Dependencies>
1111
<ModuleReference>

src/cls/ZPM/Package.cls

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,18 @@ Method versionsGet() As %ListOfDataTypes
140140
Set tList = ##class(%ListOfDataTypes).%New()
141141

142142
Set name = ..name
143-
&sql(SELECT %DLIST(version) INTO :versions FROM Package WHERE name = :name)
143+
Set tPrerelease = $Select($Data(%request) # 2: %request.Get("includePrerelease", 0), 1: 1)
144+
Set tSnapshot = $Select($Data(%request) # 2: %request.Get("includeSnapshots", 0), 1: 1)
145+
&sql(
146+
SELECT %DLIST(version) INTO :versions
147+
FROM Package
148+
WHERE name = :name
149+
AND (
150+
versionPrerelease IS NULL
151+
OR (:tSnapshot = 1 AND LOWER(versionPrerelease) = 'snapshot')
152+
OR (:tPrerelease = 1 AND LOWER(versionPrerelease) <> 'snapshot')
153+
)
154+
)
144155
If (SQLCODE=0) {
145156
Set ptr = 0
146157
While $ListNext(versions, ptr, version) {
@@ -158,20 +169,33 @@ Method versionsGet() As %ListOfDataTypes
158169
Return tList
159170
}
160171

161-
ClassMethod VersionFind(pkg As %String = "", version As %String = "") As %String
172+
ClassMethod VersionFind(pkg As %String = "", version As %String = "", pPrerelease As %Boolean = 1, pSnapshot As %Boolean = 1) As %String
162173
{
163174
If (version = "") || (version = "latest") || (version = "*") {
164175
// package was published directly in this registry - return the last version
165-
&sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package WHERE Name = :pkg AND UpLink IS NULL
166-
ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC
176+
&sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package
177+
WHERE Name = :pkg
178+
AND UpLink IS NULL
179+
AND (
180+
versionPrerelease IS NULL
181+
OR (:pSnapshot = 1 AND LOWER(versionPrerelease) = 'snapshot')
182+
OR (:pPrerelease = 1 AND LOWER(versionPrerelease) <> 'snapshot')
183+
)
184+
ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC
167185
)
168186
If SQLCODE=0 {
169187
// found
170188
Return version
171189
} Else {
172190
// find the latest version in UpLinks
173191
Do ##class(ZPM.UpLink).LoadPackageFromAllUpLinks(pkg, "latest")
174-
&sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package WHERE Name = :pkg
192+
&sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package
193+
WHERE Name = :pkg
194+
AND (
195+
versionPrerelease IS NULL
196+
OR (:pSnapshot = 1 AND LOWER(versionPrerelease) = 'snapshot')
197+
OR (:pPrerelease = 1 AND LOWER(versionPrerelease) <> 'snapshot')
198+
)
175199
ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC
176200
)
177201
If SQLCODE=0 {

src/cls/ZPM/Registry.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ ClassMethod Package(pkg As %String = "", version As %String = "", platformVersio
117117
If (version="") {
118118
$$$ThrowOnError(##class(ZPM.UpLink).FindPackageInAllUpLinks(pkg))
119119
}
120+
Set tIncludePrerelease = %request.Get("includePrerelease", 0)
121+
Set tIncludeSnapshots = %request.Get("includeSnapshots", 0)
120122

121-
Set version = ##class(ZPM.Package).VersionFind(pkg, version)
123+
Set version = ##class(ZPM.Package).VersionFind(pkg, version, tIncludePrerelease, tIncludeSnapshots)
122124
If (version = "") {
123125
Return ..ReportHttpStatusCode(..#HTTP404NOTFOUND)
124126
}

0 commit comments

Comments
 (0)