Skip to content

Commit

Permalink
Merge pull request #397 from jvrdev/master
Browse files Browse the repository at this point in the history
Regression test for #393
  • Loading branch information
forki committed Nov 27, 2014
2 parents 40ea775 + d9afa85 commit 1b2cd65
Show file tree
Hide file tree
Showing 4 changed files with 631 additions and 81 deletions.
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

0 comments on commit 1b2cd65

Please sign in to comment.