<commit_before>﻿namespace Paket

open Paket

type CompleteCoreInfo = 
    { Id : string
      Version : SemVerInfo
      Authors : string list
      Description : string }
    member this.PackageFileName = sprintf "%s.%O.nupkg" this.Id this.Version
    member this.NuspecFileName = sprintf "/%s.%O.nuspec" this.Id this.Version

type ProjectCoreInfo = 
    { Id : string option
      Version : SemVerInfo option
      Authors : string list option
      Description : string option }
    static member Empty = 
        { Id = None
          Authors = None
          Version = None
          Description = None }

type OptionalPackagingInfo = 
    { Title : string option
      Owners : string list
      ReleaseNotes : string option
      Summary : string option
      Language : string option
      ProjectUrl : string option
      IconUrl : string option
      LicenseUrl : string option
      Copyright : string option
      RequireLicenseAcceptance : bool
      Tags : string list
      DevelopmentDependency : bool
      Dependencies : (string * VersionRequirement) list
      Files : (string * string) list }
    static member Epmty : OptionalPackagingInfo = 
        { Title = None
          Owners = []
          ReleaseNotes = None
          Summary = None
          Language = None
          ProjectUrl = None
          LicenseUrl = None
          IconUrl = None
          Copyright = None
          RequireLicenseAcceptance = false
          Tags = []
          DevelopmentDependency = false
          Dependencies = []
          Files = [] }

type CompleteInfo = CompleteCoreInfo * OptionalPackagingInfo

type TemplateFileContents = 
    | CompleteInfo of CompleteInfo
    | ProjectInfo of ProjectCoreInfo * OptionalPackagingInfo

type TemplateFile = 
    { FileName : string
      Contents : TemplateFileContents }

[<CompilationRepresentationAttribute(CompilationRepresentationFlags.ModuleSuffix)>]
module TemplateFile = 
    open System
    open System.IO
    open System.Text.RegularExpressions
    open Paket.Rop
    open Paket.Domain
    
    let setVersion version templateFile = 
        let contents = 
            match templateFile.Contents with
            | CompleteInfo(core, optional) -> CompleteInfo({ core with Version = version }, optional)
            | ProjectInfo(core, optional) -> ProjectInfo({ core with Version = Some version }, optional)
        { templateFile with Contents = contents }
    
    let setReleaseNotes releaseNotes templateFile = 
        let contents = 
            match templateFile.Contents with
            | CompleteInfo(core, optional) -> CompleteInfo(core, { optional with ReleaseNotes = releaseNotes })
            | ProjectInfo(core, optional) -> ProjectInfo(core, { optional with ReleaseNotes = releaseNotes })
        { templateFile with Contents = contents }
    
    let private basicOperators = [ "~>"; "=="; "<="; ">="; "="; ">"; "<" ]
    let private operators = basicOperators @ (basicOperators |> List.map (fun o -> "!" + o))
    
    let private (!<) prefix lines = 
        let singleLine str = 
            let regex = sprintf "^%s (?<%s>.*)" prefix prefix
            let reg = Regex(regex, RegexOptions.Compiled ||| RegexOptions.CultureInvariant ||| RegexOptions.IgnoreCase)
            if reg.IsMatch str then Some <| (reg.Match str).Groups.[prefix].Value
            else None
        
        let multiLine lines = 
            let rec findBody acc (lines : string list) = <commit_msg>Removing dead code<commit_after>﻿namespace Paket

open Paket

type CompleteCoreInfo = 
    { Id : string
      Version : SemVerInfo
      Authors : string list
      Description : string }
    member this.PackageFileName = sprintf "%s.%O.nupkg" this.Id this.Version
    member this.NuspecFileName = sprintf "/%s.%O.nuspec" this.Id this.Version

type ProjectCoreInfo = 
    { Id : string option
      Version : SemVerInfo option
      Authors : string list option
      Description : string option }
    static member Empty = 
        { Id = None
          Authors = None
          Version = None
          Description = None }

type OptionalPackagingInfo = 
    { Title : string option
      Owners : string list
      ReleaseNotes : string option
      Summary : string option
      Language : string option
      ProjectUrl : string option
      IconUrl : string option
      LicenseUrl : string option
      Copyright : string option
      RequireLicenseAcceptance : bool
      Tags : string list
      DevelopmentDependency : bool
      Dependencies : (string * VersionRequirement) list
      Files : (string * string) list }
    static member Epmty : OptionalPackagingInfo = 
        { Title = None
          Owners = []
          ReleaseNotes = None
          Summary = None
          Language = None
          ProjectUrl = None
          LicenseUrl = None
          IconUrl = None
          Copyright = None
          RequireLicenseAcceptance = false
          Tags = []
          DevelopmentDependency = false
          Dependencies = []
          Files = [] }

type CompleteInfo = CompleteCoreInfo * OptionalPackagingInfo

type TemplateFileContents = 
    | CompleteInfo of CompleteInfo
    | ProjectInfo of ProjectCoreInfo * OptionalPackagingInfo

type TemplateFile = 
    { FileName : string
      Contents : TemplateFileContents }

[<CompilationRepresentationAttribute(CompilationRepresentationFlags.ModuleSuffix)>]
module TemplateFile = 
    open System
    open System.IO
    open System.Text.RegularExpressions
    open Paket.Rop
    open Paket.Domain
    
    let setVersion version templateFile = 
        let contents = 
            match templateFile.Contents with
            | CompleteInfo(core, optional) -> CompleteInfo({ core with Version = version }, optional)
            | ProjectInfo(core, optional) -> ProjectInfo({ core with Version = Some version }, optional)
        { templateFile with Contents = contents }
    
    let setReleaseNotes releaseNotes templateFile = 
        let contents = 
            match templateFile.Contents with
            | CompleteInfo(core, optional) -> CompleteInfo(core, { optional with ReleaseNotes = releaseNotes })
            | ProjectInfo(core, optional) -> ProjectInfo(core, { optional with ReleaseNotes = releaseNotes })
        { templateFile with Contents = contents }
    
    let private (!<) prefix lines = 
        let singleLine str = 
            let regex = sprintf "^%s (?<%s>.*)" prefix prefix
            let reg = Regex(regex, RegexOptions.Compiled ||| RegexOptions.CultureInvariant ||| RegexOptions.IgnoreCase)
            if reg.IsMatch str then Some <| (reg.Match str).Groups.[prefix].Value
            else None
        
        let multiLine lines = 
            let rec findBody acc (lines : string list) = 
{'fraction_non_alphanumeric': 0.0744303048239124, 'fraction_numerical': 0.0, 'mean_word_length': 2.319744597249509, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4015691', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1627, 'n_words': 520}