diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fb5eff --- /dev/null +++ b/.gitignore @@ -0,0 +1,272 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# secrets +keys +token + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + diff --git a/ReleaseNotes.sln b/ReleaseNotes.sln new file mode 100644 index 0000000..5941c28 --- /dev/null +++ b/ReleaseNotes.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReleaseNotes", "ReleaseNotes\ReleaseNotes.csproj", "{2C29B087-0FDB-49C0-84BF-47BB642C1769}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2C29B087-0FDB-49C0-84BF-47BB642C1769}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C29B087-0FDB-49C0-84BF-47BB642C1769}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C29B087-0FDB-49C0-84BF-47BB642C1769}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C29B087-0FDB-49C0-84BF-47BB642C1769}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E9C5BCF7-2487-41ED-A69E-DE41DCFD17FE} + EndGlobalSection +EndGlobal diff --git a/ReleaseNotes/Program.cs b/ReleaseNotes/Program.cs new file mode 100644 index 0000000..73b4054 --- /dev/null +++ b/ReleaseNotes/Program.cs @@ -0,0 +1,144 @@ +using Octokit; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ReleaseNotes +{ + class Program + { + static GitHubClient _client = new GitHubClient(new ProductHeaderValue("uct-release-notes")); + static Dictionary _cachedUsers = new Dictionary(); + static string[] _labels = { "animations", "controls", "extensions", "services", "helpers", "connectivity", "notifications", "documentation", "sample app" }; + + const string _clientId = "[CLIENT-ID]"; + const string _clientSecret = "[CLIENT-SECRET]"; + + static string _filename = "token"; + + static int Main(string[] args) + { + if (args.Length == 1 && args[0] == "-auth") + { + Authorize().GetAwaiter().GetResult(); + return 0; + } + if (args.Length < 2) + { + System.Console.WriteLine("\r\nUsage: releasenotes \r\n"); + return 1; + } + + if (File.Exists(_filename)) + { + var token = File.ReadAllText(_filename); + _client.Credentials = new Credentials(token); + } + + var task = PrintReleaseNotes(args[0], args[1]); + Console.Write(task.GetAwaiter().GetResult()); + + return 0; + } + + public static async Task Authorize() + { + var uri = _client.Oauth.GetGitHubLoginUrl(new OauthLoginRequest(_clientId)); + Process.Start(new ProcessStartInfo("cmd", $"/c start {uri.ToString()}")); + Console.Write($"\r\nLaunching browser at {uri}.\r\nPlease log in and authorize application.\r\nAfter authorization, you will be redirected to an url that ends with code=[some_code]\r\nPlease copy the code, paste it here, and press enter.\r\n\r\ncode="); + var code = Console.ReadLine(); + Console.Write("\r\n"); + + if (String.IsNullOrEmpty(code)) + return; + + var request = new OauthTokenRequest(_clientId, _clientSecret, code); + var token = await _client.Oauth.CreateAccessToken(request); + + File.WriteAllText(_filename, token.AccessToken); + } + + private static async Task PrintReleaseNotes(string repoOwner, string repoName) + { + var result = new StringBuilder(); + var notes = new Dictionary>(); + + foreach (var labelName in _labels) + { + notes.Add(labelName, new List()); + } + notes.Add("other", new List()); + notes.Add("breaking changes", new List()); + + try + { + var release = await _client.Repository.Release.GetLatest(repoOwner, repoName); + var request = new PullRequestRequest() + { + State = ItemStateFilter.Closed, + SortProperty = PullRequestSort.Updated + }; + var options = new ApiOptions() + { + PageCount = 1, + StartPage = 1 + }; + + var prs = await _client.PullRequest.GetAllForRepository(repoOwner, repoName, request, options); + var actionablePRs = prs.Where(pr => pr.Merged && pr.MergedAt > release.PublishedAt); + do + { + foreach (var pr in actionablePRs) + { + if (!_cachedUsers.TryGetValue(pr.User.Login, out var user)) + { + user = await _client.User.Get(pr.User.Login); + _cachedUsers.Add(pr.User.Login, user); + } + + var line = $"\t- {pr.Title} - [{user.Name ?? user.Login}]({user.HtmlUrl}) ([PR]({pr.HtmlUrl}))"; + + var issue = await _client.Issue.Get(repoOwner, repoName, pr.Number); + var matchedLabel = issue.Labels.Where(i => _labels.Contains(i.Name)).FirstOrDefault(); + + notes[matchedLabel != null ? matchedLabel.Name : "other"].Add(line); + + if (issue.Labels.Where(i => i.Name == "introduce breaking changes").Count() > 0) + notes["breaking changes"].Add(line); + } + + options.StartPage++; + prs = await _client.PullRequest.GetAllForRepository("Microsoft", "UWPCommunityToolkit", request, options); + actionablePRs = prs.Where(pr => pr.Merged && pr.MergedAt > release.PublishedAt); + } while (actionablePRs.Count() > 0); + } + catch (Octokit.NotFoundException) + { + return "Repository not found, or repository does not have milestones or pull requests\r\n"; + } + catch (Octokit.RateLimitExceededException ex) + { + return $"\r\n{ex.Message}\r\n\r\nTo authenticate, run: ReleaseNotes -auth\r\n\r\n"; + } + + foreach (var label in notes) + { + if (label.Value.Count > 0) + { + result.AppendLine($"- {label.Key}"); + foreach (var line in label.Value) + { + result.AppendLine(line); + } + result.AppendLine(); + } + } + + return result.ToString(); + } + } +} diff --git a/ReleaseNotes/Properties/PublishProfiles/FolderProfile.pubxml b/ReleaseNotes/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..9a3fdb2 --- /dev/null +++ b/ReleaseNotes/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,14 @@ + + + + + FileSystem + Release + netcoreapp1.1 + bin\Release\PublishOutput + win10-x64 + + \ No newline at end of file diff --git a/ReleaseNotes/ReleaseNotes.csproj b/ReleaseNotes/ReleaseNotes.csproj new file mode 100644 index 0000000..e721887 --- /dev/null +++ b/ReleaseNotes/ReleaseNotes.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp1.1 + win10-x64 + + + + + + +