Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
add SourceLink.MilestoneReleaseNotes (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaggart authored Sep 25, 2018
1 parent 7b8bf67 commit d24b810
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
56 changes: 56 additions & 0 deletions SourceLink.MilestoneReleaseNotes/Program.fs
Original file line number Diff line number Diff line change
@@ -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)

[<EntryPoint>]
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
41 changes: 41 additions & 0 deletions SourceLink.MilestoneReleaseNotes/Settings.fs
Original file line number Diff line number Diff line change
@@ -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

[<CLIMutable>]
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PackAsTool>True</PackAsTool>
<ToolCommandName>milestonereleasenotes</ToolCommandName>
<Description>app for creating release notes from a GitHub milestone</Description>
</PropertyGroup>
<ItemGroup>
<Compile Include="Settings.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Octokit" Version="0.32.0" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d24b810

Please sign in to comment.