Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Set the equivalent of core.autocrlf=true in .gitattributes (#423)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
skolima authored and AnthonySteele committed Sep 11, 2018
1 parent 26d8e1c commit 18146f3
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .gitattributes
@@ -0,0 +1,4 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
272 changes: 136 additions & 136 deletions 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<int> 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<int> 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;
}
}
}

0 comments on commit 18146f3

Please sign in to comment.