This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add SourceLink.MilestoneReleaseNotes (#370)
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
20 changes: 20 additions & 0 deletions
20
SourceLink.MilestoneReleaseNotes/SourceLink.MilestoneReleaseNotes.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters