-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(datasource/nuget): move v2/v3 API logic to classes (#28117)
- Loading branch information
1 parent
fde2dff
commit 87bba9d
Showing
5 changed files
with
282 additions
and
256 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
lib/modules/datasource/nuget/v3.spec.ts → lib/modules/datasource/nuget/common.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,74 @@ | ||
import { XmlDocument, XmlElement } from 'xmldoc'; | ||
import { logger } from '../../../logger'; | ||
import type { Http } from '../../../util/http'; | ||
import type { HttpResponse } from '../../../util/http/types'; | ||
import { regEx } from '../../../util/regex'; | ||
import type { ReleaseResult } from '../types'; | ||
import { massageUrl, removeBuildMeta } from './common'; | ||
|
||
function getPkgProp(pkgInfo: XmlElement, propName: string): string | undefined { | ||
return pkgInfo.childNamed('m:properties')?.childNamed(`d:${propName}`)?.val; | ||
} | ||
export class NugetV2Api { | ||
getPkgProp(pkgInfo: XmlElement, propName: string): string | undefined { | ||
return pkgInfo.childNamed('m:properties')?.childNamed(`d:${propName}`)?.val; | ||
} | ||
|
||
export async function getReleases( | ||
http: Http, | ||
feedUrl: string, | ||
pkgName: string, | ||
): Promise<ReleaseResult | null> { | ||
const dep: ReleaseResult = { | ||
releases: [], | ||
}; | ||
let pkgUrlList: string | null = `${feedUrl.replace( | ||
regEx(/\/+$/), | ||
'', | ||
)}/FindPackagesById()?id=%27${pkgName}%27&$select=Version,IsLatestVersion,ProjectUrl,Published`; | ||
while (pkgUrlList !== null) { | ||
// typescript issue | ||
const pkgVersionsListRaw: HttpResponse<string> = await http.get(pkgUrlList); | ||
const pkgVersionsListDoc = new XmlDocument(pkgVersionsListRaw.body); | ||
async getReleases( | ||
http: Http, | ||
feedUrl: string, | ||
pkgName: string, | ||
): Promise<ReleaseResult | null> { | ||
const dep: ReleaseResult = { | ||
releases: [], | ||
}; | ||
let pkgUrlList: string | null = `${feedUrl.replace( | ||
regEx(/\/+$/), | ||
'', | ||
)}/FindPackagesById()?id=%27${pkgName}%27&$select=Version,IsLatestVersion,ProjectUrl,Published`; | ||
while (pkgUrlList !== null) { | ||
// typescript issue | ||
const pkgVersionsListRaw = await http.get(pkgUrlList); | ||
const pkgVersionsListDoc = new XmlDocument(pkgVersionsListRaw.body); | ||
|
||
const pkgInfoList = pkgVersionsListDoc.childrenNamed('entry'); | ||
const pkgInfoList = pkgVersionsListDoc.childrenNamed('entry'); | ||
|
||
for (const pkgInfo of pkgInfoList) { | ||
const version = getPkgProp(pkgInfo, 'Version'); | ||
const releaseTimestamp = getPkgProp(pkgInfo, 'Published'); | ||
dep.releases.push({ | ||
// TODO: types (#22198) | ||
version: removeBuildMeta(`${version}`), | ||
releaseTimestamp, | ||
}); | ||
try { | ||
const pkgIsLatestVersion = getPkgProp(pkgInfo, 'IsLatestVersion'); | ||
if (pkgIsLatestVersion === 'true') { | ||
dep['tags'] = { latest: removeBuildMeta(`${version}`) }; | ||
const projectUrl = getPkgProp(pkgInfo, 'ProjectUrl'); | ||
if (projectUrl) { | ||
dep.sourceUrl = massageUrl(projectUrl); | ||
for (const pkgInfo of pkgInfoList) { | ||
const version = this.getPkgProp(pkgInfo, 'Version'); | ||
const releaseTimestamp = this.getPkgProp(pkgInfo, 'Published'); | ||
dep.releases.push({ | ||
// TODO: types (#22198) | ||
version: removeBuildMeta(`${version}`), | ||
releaseTimestamp, | ||
}); | ||
try { | ||
const pkgIsLatestVersion = this.getPkgProp( | ||
pkgInfo, | ||
'IsLatestVersion', | ||
); | ||
if (pkgIsLatestVersion === 'true') { | ||
dep['tags'] = { latest: removeBuildMeta(`${version}`) }; | ||
const projectUrl = this.getPkgProp(pkgInfo, 'ProjectUrl'); | ||
if (projectUrl) { | ||
dep.sourceUrl = massageUrl(projectUrl); | ||
} | ||
} | ||
} catch (err) /* istanbul ignore next */ { | ||
logger.debug( | ||
{ err, pkgName, feedUrl }, | ||
`nuget registry failure: can't parse pkg info for project url`, | ||
); | ||
} | ||
} catch (err) /* istanbul ignore next */ { | ||
logger.debug( | ||
{ err, pkgName, feedUrl }, | ||
`nuget registry failure: can't parse pkg info for project url`, | ||
); | ||
} | ||
} | ||
|
||
const nextPkgUrlListLink = pkgVersionsListDoc | ||
.childrenNamed('link') | ||
.find((node) => node.attr.rel === 'next'); | ||
const nextPkgUrlListLink = pkgVersionsListDoc | ||
.childrenNamed('link') | ||
.find((node) => node.attr.rel === 'next'); | ||
|
||
pkgUrlList = nextPkgUrlListLink ? nextPkgUrlListLink.attr.href : null; | ||
} | ||
pkgUrlList = nextPkgUrlListLink ? nextPkgUrlListLink.attr.href : null; | ||
} | ||
|
||
// dep not found if no release, so we can try next registry | ||
if (dep.releases.length === 0) { | ||
return null; | ||
} | ||
// dep not found if no release, so we can try next registry | ||
if (dep.releases.length === 0) { | ||
return null; | ||
} | ||
|
||
return dep; | ||
return dep; | ||
} | ||
} |
Oops, something went wrong.