From 18146f3a2f63017bb8b696f9c036f3db3fcc58fe Mon Sep 17 00:00:00 2001 From: Leszek 'skolima' Ciesielski Date: Tue, 11 Sep 2018 16:50:35 +0200 Subject: [PATCH] Set the equivalent of `core.autocrlf=true` in .gitattributes (#423) * Set the equivalent of `core.autocrlf=true` in .gitattributes Follows https://github.com/dotnet/core/blob/master/.gitattributes * Don't force line endings in .editorconfigs This causes issues when working on Unix - use .gitattributes instead * Fixed line endings --- .editorconfig | 2 +- .gitattributes | 4 + NuKeeper/Commands/GitHubNuKeeperCommand.cs | 272 ++++++++++----------- 3 files changed, 141 insertions(+), 137 deletions(-) create mode 100644 .gitattributes diff --git a/.editorconfig b/.editorconfig index 7968c6333..116738756 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*] indent_style = space -end_of_line = crlf +# end_of_line = native # set via .gitattributes charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..e1b1161d8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto diff --git a/NuKeeper/Commands/GitHubNuKeeperCommand.cs b/NuKeeper/Commands/GitHubNuKeeperCommand.cs index d6dd1a8d3..cd5b02e68 100644 --- a/NuKeeper/Commands/GitHubNuKeeperCommand.cs +++ b/NuKeeper/Commands/GitHubNuKeeperCommand.cs @@ -1,136 +1,136 @@ -using System; -using System.Threading.Tasks; -using System.Linq; -using McMaster.Extensions.CommandLineUtils; -using NuKeeper.Configuration; -using NuKeeper.Engine; -using NuKeeper.Inspection.Logging; -using NuKeeper.Inspection.Report; - -namespace NuKeeper.Commands -{ - internal abstract class GitHubNuKeeperCommand : CommandBase - { - private readonly GitHubEngine _engine; - - [Argument(1, Name = "Token", - Description = - "GitHub personal access token to authorise access to GitHub server.")] - // ReSharper disable once UnassignedGetOnlyAutoProperty - // ReSharper disable once MemberCanBePrivate.Global - protected string GitHubToken { get; } - - [Option(CommandOptionType.SingleValue, ShortName = "x", LongName = "maxrepo", - Description = "The maximum number of repositories to change. Defaults to 10.")] - // ReSharper disable once MemberCanBePrivate.Global - protected int AllowedMaxRepositoriesChangedChange { get; } = 10; - - [Option(CommandOptionType.SingleValue, ShortName = "f", LongName = "fork", - Description = - "Prefer to make branches on a fork of the target repository, or on that repository itself. Allowed values are PreferFork, PreferSingleRepository, SingleRepositoryOnly. Defaults to PreferFork.")] - // ReSharper disable once MemberCanBePrivate.Global - protected ForkMode ForkMode { get; } = ForkMode.PreferFork; - - [Option(CommandOptionType.SingleValue, ShortName = "p", LongName = "maxpr", - Description = "The maximum number of pull requests to raise on any repository. Defaults to 3.")] - // ReSharper disable once MemberCanBePrivate.Global - protected int MaxPullRequestsPerRepository { get; } = 3; - - [Option(CommandOptionType.MultipleValue, ShortName = "l", LongName = "label", - Description = - "Label to apply to GitHub pull requests. Defaults to 'nukeeper'. Multiple labels can be provided by specifying this option multiple times.")] - // ReSharper disable once UnassignedGetOnlyAutoProperty - // ReSharper disable once MemberCanBePrivate.Global - protected string[] Label { get; } = { "nukeeper" }; - - [Option(CommandOptionType.SingleValue, ShortName = "g", LongName = "api", - Description = - "GitHub Api Base Url. If you are using an internal GitHub server and not the public one, you must set it to the api url for your GitHub server.")] - // ReSharper disable once UnassignedGetOnlyAutoProperty - // ReSharper disable once MemberCanBePrivate.Global - protected string GithubApiEndpoint { get; } - - [Option(CommandOptionType.SingleValue, ShortName = "r", LongName = "report", - Description = - "Controls if a CSV report file of possible updates is generated. Allowed values are Off, On, ReportOnly (which skips applying updates). Defaults to Off.")] - protected ReportMode ReportMode { get; } = ReportMode.Off; - - protected GitHubNuKeeperCommand(GitHubEngine engine, IConfigureLogLevel logger, IFileSettingsCache fileSettingsCache) : - base(logger, fileSettingsCache) - { - _engine = engine; - } - - protected override ValidationResult PopulateSettings(SettingsContainer settings) - { - var baseResult = base.PopulateSettings(settings); - if (!baseResult.IsSuccess) - { - return baseResult; - } - - var apiBase = GithubEndpointWithFallback(); - - if (string.IsNullOrWhiteSpace(apiBase)) - { - return ValidationResult.Failure("No GitHub Api base found"); - } - - if (!Uri.TryCreate(apiBase, UriKind.Absolute, out var githubUri)) - { - return ValidationResult.Failure($"Bad GitHub Api base '{GithubApiEndpoint}'"); - } - - var token = ReadToken(); - if (string.IsNullOrWhiteSpace(token)) - { - return ValidationResult.Failure("The required GitHub access token was not found"); - } - - var githubUrl = GitSettingsReader.EnsureTrailingSlash(githubUri); - - settings.GithubAuthSettings = new GithubAuthSettings(githubUrl, token); - - settings.UserSettings.MaxRepositoriesChanged = AllowedMaxRepositoriesChangedChange; - settings.PackageFilters.MaxPackageUpdates = MaxPullRequestsPerRepository; - settings.UserSettings.ForkMode = ForkMode; - settings.UserSettings.ReportMode = ReportMode; - - var fileSetting = FileSettingsCache.Get(); - - settings.SourceControlServerSettings.Labels = - Concat.AllPopulated(Label, fileSetting.Label).ToList(); - - return ValidationResult.Success; - } - - protected override async Task Run(SettingsContainer settings) - { - await _engine.Run(settings); - return 0; - } - - private string GithubEndpointWithFallback() - { - const string defaultGithubApi = "https://api.github.com/"; - var fileSetting = FileSettingsCache.Get(); - return Concat.FirstValue(GithubApiEndpoint, fileSetting.Api, defaultGithubApi); - } - - private string ReadToken() - { - if (!string.IsNullOrWhiteSpace(GitHubToken)) - { - return GitHubToken; - } - - var envToken = Environment.GetEnvironmentVariable("NuKeeper_github_token"); - if (!string.IsNullOrWhiteSpace(envToken)) - { - return envToken; - } - - return string.Empty; - } - } -} +using System; +using System.Threading.Tasks; +using System.Linq; +using McMaster.Extensions.CommandLineUtils; +using NuKeeper.Configuration; +using NuKeeper.Engine; +using NuKeeper.Inspection.Logging; +using NuKeeper.Inspection.Report; + +namespace NuKeeper.Commands +{ + internal abstract class GitHubNuKeeperCommand : CommandBase + { + private readonly GitHubEngine _engine; + + [Argument(1, Name = "Token", + Description = + "GitHub personal access token to authorise access to GitHub server.")] + // ReSharper disable once UnassignedGetOnlyAutoProperty + // ReSharper disable once MemberCanBePrivate.Global + protected string GitHubToken { get; } + + [Option(CommandOptionType.SingleValue, ShortName = "x", LongName = "maxrepo", + Description = "The maximum number of repositories to change. Defaults to 10.")] + // ReSharper disable once MemberCanBePrivate.Global + protected int AllowedMaxRepositoriesChangedChange { get; } = 10; + + [Option(CommandOptionType.SingleValue, ShortName = "f", LongName = "fork", + Description = + "Prefer to make branches on a fork of the target repository, or on that repository itself. Allowed values are PreferFork, PreferSingleRepository, SingleRepositoryOnly. Defaults to PreferFork.")] + // ReSharper disable once MemberCanBePrivate.Global + protected ForkMode ForkMode { get; } = ForkMode.PreferFork; + + [Option(CommandOptionType.SingleValue, ShortName = "p", LongName = "maxpr", + Description = "The maximum number of pull requests to raise on any repository. Defaults to 3.")] + // ReSharper disable once MemberCanBePrivate.Global + protected int MaxPullRequestsPerRepository { get; } = 3; + + [Option(CommandOptionType.MultipleValue, ShortName = "l", LongName = "label", + Description = + "Label to apply to GitHub pull requests. Defaults to 'nukeeper'. Multiple labels can be provided by specifying this option multiple times.")] + // ReSharper disable once UnassignedGetOnlyAutoProperty + // ReSharper disable once MemberCanBePrivate.Global + protected string[] Label { get; } = { "nukeeper" }; + + [Option(CommandOptionType.SingleValue, ShortName = "g", LongName = "api", + Description = + "GitHub Api Base Url. If you are using an internal GitHub server and not the public one, you must set it to the api url for your GitHub server.")] + // ReSharper disable once UnassignedGetOnlyAutoProperty + // ReSharper disable once MemberCanBePrivate.Global + protected string GithubApiEndpoint { get; } + + [Option(CommandOptionType.SingleValue, ShortName = "r", LongName = "report", + Description = + "Controls if a CSV report file of possible updates is generated. Allowed values are Off, On, ReportOnly (which skips applying updates). Defaults to Off.")] + protected ReportMode ReportMode { get; } = ReportMode.Off; + + protected GitHubNuKeeperCommand(GitHubEngine engine, IConfigureLogLevel logger, IFileSettingsCache fileSettingsCache) : + base(logger, fileSettingsCache) + { + _engine = engine; + } + + protected override ValidationResult PopulateSettings(SettingsContainer settings) + { + var baseResult = base.PopulateSettings(settings); + if (!baseResult.IsSuccess) + { + return baseResult; + } + + var apiBase = GithubEndpointWithFallback(); + + if (string.IsNullOrWhiteSpace(apiBase)) + { + return ValidationResult.Failure("No GitHub Api base found"); + } + + if (!Uri.TryCreate(apiBase, UriKind.Absolute, out var githubUri)) + { + return ValidationResult.Failure($"Bad GitHub Api base '{GithubApiEndpoint}'"); + } + + var token = ReadToken(); + if (string.IsNullOrWhiteSpace(token)) + { + return ValidationResult.Failure("The required GitHub access token was not found"); + } + + var githubUrl = GitSettingsReader.EnsureTrailingSlash(githubUri); + + settings.GithubAuthSettings = new GithubAuthSettings(githubUrl, token); + + settings.UserSettings.MaxRepositoriesChanged = AllowedMaxRepositoriesChangedChange; + settings.PackageFilters.MaxPackageUpdates = MaxPullRequestsPerRepository; + settings.UserSettings.ForkMode = ForkMode; + settings.UserSettings.ReportMode = ReportMode; + + var fileSetting = FileSettingsCache.Get(); + + settings.SourceControlServerSettings.Labels = + Concat.AllPopulated(Label, fileSetting.Label).ToList(); + + return ValidationResult.Success; + } + + protected override async Task Run(SettingsContainer settings) + { + await _engine.Run(settings); + return 0; + } + + private string GithubEndpointWithFallback() + { + const string defaultGithubApi = "https://api.github.com/"; + var fileSetting = FileSettingsCache.Get(); + return Concat.FirstValue(GithubApiEndpoint, fileSetting.Api, defaultGithubApi); + } + + private string ReadToken() + { + if (!string.IsNullOrWhiteSpace(GitHubToken)) + { + return GitHubToken; + } + + var envToken = Environment.GetEnvironmentVariable("NuKeeper_github_token"); + if (!string.IsNullOrWhiteSpace(envToken)) + { + return envToken; + } + + return string.Empty; + } + } +}