<commit_before>﻿module Paket.PackageProcess

open Paket
open System
open System.IO
open System.Reflection
open Paket.Domain
open Paket.Logging
open System.Collections.Generic
open Paket.PackageMetaData
open Chessie.ErrorHandling
open InstallProcess

let private tryGenerateDescription packageId outputType =
    match packageId with
    | Some id when notNullOrEmpty id ->
        let outputType =
            match outputType with
            | ProjectOutputType.Library -> "library"
            | ProjectOutputType.Exe -> "program"
        Some (sprintf "%s %s." id outputType)
    | _ -> None

let private merge buildConfig buildPlatform versionFromAssembly specificVersions (projectFile:ProjectFile) templateFile = 
    let withVersion =
        match versionFromAssembly with
        | None -> templateFile
        | Some v -> templateFile |> TemplateFile.setVersion (Some v) specificVersions

    match withVersion with
    | { Contents = ProjectInfo(md, opt) } -> 
        let assemblyReader,id,versionFromAssembly,assemblyFileName = readAssemblyFromProjFile buildConfig buildPlatform projectFile
        let attribs = loadAssemblyAttributes assemblyReader

        let mergedOpt =
            match opt.Title with
            | Some _ -> opt
            | None -> { opt with Title = getTitle attribs }

        match md with
        | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, mergedOpt) }
        | _ ->
            let md = { md with Id = md.Id ++ Some id }

            match md with
            | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, mergedOpt) }
            | _ ->
                let versionFromAssembly =
                    match md.Id |> Option.bind (fun id -> Map.tryFind id specificVersions) with
                    | Some _ as specificVersion -> specificVersion
                    | None -> getVersion versionFromAssembly attribs

                let merged = 
                    { Id = md.Id
                      Version = md.Version ++ versionFromAssembly
                      Authors = md.Authors ++ getAuthors attribs
                      Description = md.Description ++ getDescription attribs ++ tryGenerateDescription md.Id projectFile.OutputType
                      Symbols = md.Symbols }

                match merged with
                | Invalid ->
                    let missing =
                        [ if merged.Id = None then yield "Id"
                          if merged.Version = None then yield "Version"
                          if merged.Authors = None || merged.Authors = Some [] then yield "Authors"
                          if merged.Description = None || merged.Description = Some "" then yield "Description" ]
                        |> fun xs -> String.Join(", ",xs)
<commit_msg>Warn the user about missing package description<commit_after>﻿module Paket.PackageProcess

open Paket
open System
open System.IO
open System.Reflection
open Paket.Domain
open Paket.Logging
open System.Collections.Generic
open Paket.PackageMetaData
open Chessie.ErrorHandling
open InstallProcess

let private tryGenerateDescription packageId outputType =
    match packageId with
    | Some id when notNullOrEmpty id ->
        let outputType =
            match outputType with
            | ProjectOutputType.Library -> "library"
            | ProjectOutputType.Exe -> "program"
        Some (sprintf "%s %s." id outputType)
    | _ -> None

let private merge buildConfig buildPlatform versionFromAssembly specificVersions (projectFile:ProjectFile) templateFile = 
    let withVersion =
        match versionFromAssembly with
        | None -> templateFile
        | Some v -> templateFile |> TemplateFile.setVersion (Some v) specificVersions

    match withVersion with
    | { Contents = ProjectInfo(md, opt) } -> 
        let assemblyReader,id,versionFromAssembly,assemblyFileName = readAssemblyFromProjFile buildConfig buildPlatform projectFile
        let attribs = loadAssemblyAttributes assemblyReader

        let mergedOpt =
            match opt.Title with
            | Some _ -> opt
            | None -> { opt with Title = getTitle attribs }

        match md with
        | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, mergedOpt) }
        | _ ->
            let md = { md with Id = md.Id ++ Some id }

            match md with
            | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, mergedOpt) }
            | _ ->
                let versionFromAssembly =
                    match md.Id |> Option.bind (fun id -> Map.tryFind id specificVersions) with
                    | Some _ as specificVersion -> specificVersion
                    | None -> getVersion versionFromAssembly attribs

                // See discussion at https://github.com/fsprojects/Paket/pull/1831
                let tryGenerateDescription packageId outputType =
                    match packageId with
                    | Some id -> traceWarnfn "No description was provided for package %A. Generating from ID and project output type." id
                    | _ -> ()
                    tryGenerateDescription packageId outputType

                let merged = 
                    { Id = md.Id
                      Version = md.Version ++ versionFromAssembly
                      Authors = md.Authors ++ getAuthors attribs
                      Description = md.Description ++ getDescription attribs ++ tryGenerateDescription md.Id projectFile.OutputType
                      Symbols = md.Symbols }

                match merged with
                | Invalid ->
                    let missing =
                        [ if merged.Id = None then yield "Id"
                          if merged.Version = None then yield "Version"
                          if merged.Authors = None || merged.Authors = Some [] then yield "Authors"
                          if merged.Description = None || merged.Description = Some "" then yield "Description" ]
                        |> fun xs -> String.Join(", ",xs)

{'fraction_non_alphanumeric': 0.06820790293490736, 'fraction_numerical': 0.0006558452205279554, 'mean_word_length': 1.8814359943316012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1189164', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1365, 'n_words': 454}