diff --git a/SourceLink.MilestoneReleaseNotes/Program.fs b/SourceLink.MilestoneReleaseNotes/Program.fs new file mode 100644 index 0000000..1cfd7fe --- /dev/null +++ b/SourceLink.MilestoneReleaseNotes/Program.fs @@ -0,0 +1,56 @@ +module SourceLink.MilestoneReleaseNotes.Program + +open System +open Octokit +open FSharp.Control.Tasks.V2 + +let appName = "SourceLink" + +type String with + static member equalsi a b = StringComparer.OrdinalIgnoreCase.Equals(a, b) + +[] +let main argv = + let t = + task { + try + let settings = Settings.Load argv + + // Oktokit is used to find the milestone + // https://github.com/octokit/octokit.net/blob/master/docs/getting-started.md + + let client = GitHubClient(ProductHeaderValue appName, Uri settings.GitHubUrl) + let tokenAuth = Credentials settings.GitHubToken + + client.Credentials <- tokenAuth + let milestoneRequest = MilestoneRequest() + milestoneRequest.State <- ItemStateFilter.All + let! milestones = client.Issue.Milestone.GetAllForRepository(settings.GitHubOwner, settings.GitHubRepository, milestoneRequest) + let milestone = milestones |> Seq.find (fun milestone -> String.equalsi settings.Milestone milestone.Title) + + let issueRequest = RepositoryIssueRequest () + issueRequest.State <- ItemStateFilter.All + issueRequest.Milestone <- sprintf "%d" milestone.Number + let! issues = client.Issue.GetAllForRepository(settings.GitHubOwner, settings.GitHubRepository, issueRequest) + + printfn "## Issues" + issues + |> Seq.filter (fun issue -> isNull issue.PullRequest) + |> Seq.iter (fun issue -> printfn "- [#%d](%s) %s" issue.Number issue.HtmlUrl issue.Title) + + printfn "\n## Pull Requests" + issues + |> Seq.filter (fun issue -> not <| isNull issue.PullRequest) + |> Seq.iter (fun issue -> printfn "- [#%d](%s) %s" issue.Number issue.HtmlUrl issue.Title) + + return 0 + with e -> + eprintfn "failure %A" e + return 1 + } + match t.Wait (TimeSpan.FromSeconds 60.) with + | false -> + eprintfn "timed out" + 2 + | true -> + t.Result \ No newline at end of file diff --git a/SourceLink.MilestoneReleaseNotes/Settings.fs b/SourceLink.MilestoneReleaseNotes/Settings.fs new file mode 100644 index 0000000..96db2c9 --- /dev/null +++ b/SourceLink.MilestoneReleaseNotes/Settings.fs @@ -0,0 +1,41 @@ +// Settings can be configured using envronment variables or command line arguments +// as described in the ASP.NET Core documentation +// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1 + +// The keys are not case sensitive. example: +// milestonereleasenotes githubtoken=$githubtoken githubowner=ctaggart githubrepository=sourcelink milestone=3.0.0 +// You can also use environment variables with a prefix of RELEASENOTES_, such as RELEASENOTES_GITHUBTOKEN + +namespace SourceLink.MilestoneReleaseNotes + +open System +open Microsoft.Extensions.Configuration + +[] +type Settings = + { + GitHubUrl: string + GitHubToken: string + GitHubOwner: string + GitHubRepository: string + Milestone: string + } +with + static member Default = + { + GitHubUrl = "https://api.github.com" + GitHubToken = String.Empty + GitHubOwner = String.Empty + GitHubRepository = String.Empty + Milestone = String.Empty + } + + static member Load (args: string[]) = + let config = + ConfigurationBuilder() + .AddEnvironmentVariables("RELEASENOTES_") + .AddCommandLine(args) + .Build() + let settings = Settings.Default + config.Bind settings + settings \ No newline at end of file diff --git a/SourceLink.MilestoneReleaseNotes/SourceLink.MilestoneReleaseNotes.fsproj b/SourceLink.MilestoneReleaseNotes/SourceLink.MilestoneReleaseNotes.fsproj new file mode 100644 index 0000000..66167b1 --- /dev/null +++ b/SourceLink.MilestoneReleaseNotes/SourceLink.MilestoneReleaseNotes.fsproj @@ -0,0 +1,20 @@ + + + Exe + netcoreapp2.1 + True + milestonereleasenotes + app for creating release notes from a GitHub milestone + + + + + + + + + + + + + diff --git a/build.ps1 b/build.ps1 index 9dad6fd..9739b15 100644 --- a/build.ps1 +++ b/build.ps1 @@ -29,6 +29,9 @@ dotnet $build Set-Location $psscriptroot\SourceLink.Test dotnet $build +Set-Location $psscriptroot\SourceLink.MilestoneReleaseNotes +dotnet $pack + # Set-Location $psscriptroot\build # dotnet restore # $nupkgs = ls ..\bin\*$version$versionSuffix.nupkg