Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Checking outdated NuGet dependencies with the F# OData type provider
#r "System.Xml.Linq"
#r @"g:\prg\SolrNet\lib\NuGet.exe"
open NuGet
let split (c: char) (x: string) = x.Split c
let parseDependencies : string -> seq<string * IVersionSpec> =
split '|' >> Seq.map (split ':' >> fun x -> x.[0], VersionUtility.ParseVersionSpec x.[1])
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
let inList (memberr: Expr<'a -> 'b>) (values: 'b list) : Expr<'a -> bool> =
match memberr with
| Lambda (_, PropertyGet _) ->
match values with
| [] -> <@ fun _ -> true @>
| _ -> values |> Seq.map (fun v -> <@ fun a -> (%memberr) a = v @>) |> Seq.reduce (fun a b -> <@ fun x -> (%a) x || (%b) x @>)
| _ -> failwith "Expression has to be a member"
#r "System.Data.Services.Client"
#r "FSharp.Data.TypeProviders"
open System.Linq
open System.Data.Services.Client
let execQueryAsync (q: _ DataServiceQuery) =
Async.FromBeginEnd(q.BeginExecute, q.EndExecute)
type nuget = Microsoft.FSharp.Data.TypeProviders.ODataService<"https://nuget.org/api/v2">
type Package = nuget.ServiceTypes.V2FeedPackage
let ctx = nuget.GetDataContext()
let checkDependencies packageId =
async {
let packagesQuery =
query {
for p in ctx.Packages do
where (p.Id = packageId && p.IsAbsoluteLatestVersion && p.IsLatestVersion)
select p
} :?> DataServiceQuery<Package>
let! packages = execQueryAsync packagesQuery
let package = Seq.exactlyOne packages
let deps = parseDependencies package.Dependencies |> Seq.toList
let depIds = List.map fst deps
let depsQuery =
query {
for p in ctx.Packages do
where (((%(inList <@ fun (x: Package) -> x.Id @> depIds)) p) && p.IsAbsoluteLatestVersion && p.IsLatestVersion)
select p
} :?> DataServiceQuery<Package>
let! depPackages = execQueryAsync depsQuery
let depPackagesList = Seq.toList depPackages
let satisfies =
deps |> List.map (fun (depId, version) ->
let depPackage = depPackagesList |> Seq.find (fun p -> p.Id = depId)
let semVersion = SemanticVersion.Parse depPackage.Version
depId, version, version.Satisfies semVersion)
return satisfies
}
checkDependencies "GDataDB" |> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment