Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression test for https://github.com/fsprojects/Paket/pull/393 #397

Merged
merged 2 commits into from
Nov 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,68 @@ type NugetPackageCache =
Unlisted : bool
DownloadUrl : string}

let rec private followODataLink auth url =
let rec private followODataLink getUrlContents url =
async {
let! raw = getFromUrl (auth, url)
let! raw = getUrlContents url
let doc = XmlDocument()
doc.LoadXml raw
let feed =
match doc |> getNode "feed" with
| Some node -> node
| None -> failwithf "unable to parse data from %s" url

let readEntryVersion = optGetNode "properties" >> optGetNode "Version"
let readEntryVersion = Some
>> optGetNode "properties"
>> optGetNode "Version"
>> Option.map (fun node -> node.InnerText)

let entriesVersions =
feed
|> getNodes "entry"
|> List.choose (fun entry -> Some entry |> readEntryVersion |> Option.map (fun node -> node.InnerText))
let entriesVersions = feed |> getNodes "entry" |> List.choose readEntryVersion

let linksVersions =
let! linksVersions =
feed
|> getNodes "link"
|> List.filter (fun node -> node |> getAttribute "rel" = Some "next")
|> List.choose (getAttribute "href")
|> List.map (followODataLink auth)
|> List.map (followODataLink getUrlContents)
|> Async.Parallel
|> Async.RunSynchronously
|> Seq.concat

return
entriesVersions
|> Seq.append linksVersions
linksVersions
|> Seq.collect id
|> Seq.append entriesVersions
}

/// Gets versions of the given package via OData via /Packages?$filter=Id eq 'packageId'
let getAllVersionsFromNugetODataWithFilter (auth, nugetURL, package) =
let getAllVersionsFromNugetODataWithFilter (getUrlContents, nugetURL, package) =
// we cannot cache this
followODataLink auth (sprintf "%s/Packages?$filter=Id eq '%s'" nugetURL package)
let url = sprintf "%s/Packages?$filter=Id eq '%s'" nugetURL package
followODataLink getUrlContents url

/// Gets versions of the given package via OData via /FindPackagesById()?id='packageId'.
let getAllVersionsFromNugetOData (auth, nugetURL, package) =
let getAllVersionsFromNugetOData (getUrlContents, nugetURL, package) =
async {
// we cannot cache this
try
let url = sprintf "%s/FindPackagesById()?id='%s'" nugetURL package
return! followODataLink auth url
with _ -> return! getAllVersionsFromNugetODataWithFilter (auth, nugetURL, package)
return! followODataLink getUrlContents url
with _ -> return! getAllVersionsFromNugetODataWithFilter (getUrlContents, nugetURL, package)
}

/// Gets all versions no. of the given package.
let getAllVersionsFromNuGet2(auth,nugetURL,package) =
// we cannot cache this
async {
let! raw = safeGetFromUrl(auth,sprintf "%s/package-versions/%s?includePrerelease=true" nugetURL package)
let getUrlContents url = getFromUrl(auth, url)
match raw with
| None -> let! result = getAllVersionsFromNugetOData(auth,nugetURL, package)
| None -> let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, package)
return result
| Some data ->
try
try
let result = JsonConvert.DeserializeObject<string []>(data) |> Array.toSeq
return result
with _ -> let! result = getAllVersionsFromNugetOData(auth,nugetURL, package)
with _ -> let! result = getAllVersionsFromNugetOData(getUrlContents, nugetURL, package)
return result
with exn ->
return! failwithf "Could not get data from %s for package %s.%s Message: %s" nugetURL package
Expand Down
Loading