diff --git a/octorun/src/api.js b/octorun/src/api.js index 32322ef6a..fcaf96c50 100644 --- a/octorun/src/api.js +++ b/octorun/src/api.js @@ -65,24 +65,24 @@ ApiWrapper.prototype.getOrgs = function (callback) { }; ApiWrapper.prototype.publish = function (name, desc, private, organization, callback) { + var callbackHandler = function (error, result) { + callback(error, (!result) ? null : [result.data.name, result.data.clone_url]); + }; + if (organization) { this.octokit.repos.createForOrg({ org: organization, name: name, description: desc, private: private - }, function (error, result) { - callback(error, (!result) ? null : result.data.clone_url); - }); + }, callbackHandler); } else { this.octokit.repos.create({ name: name, description: desc, private: private - }, function (error, result) { - callback(error, (!result) ? null : result.data.clone_url); - }); + }, callbackHandler); } }; diff --git a/octorun/src/authentication.js b/octorun/src/authentication.js index d724fca8f..43a2de5bb 100644 --- a/octorun/src/authentication.js +++ b/octorun/src/authentication.js @@ -2,9 +2,7 @@ var endOfLine = require('os').EOL; var config = require("./configuration"); var octokitWrapper = require("./octokit"); -var lockedRegex = new RegExp("number of login attempts exceeded", "gi"); var twoFactorRegex = new RegExp("must specify two-factor authentication otp code", "gi"); -var badCredentialsRegex = new RegExp("bad credentials", "gi"); var scopes = ["user", "repo", "gist", "write:public_key"]; @@ -48,12 +46,6 @@ var handleAuthentication = function (username, password, onSuccess, onFailure, t else if (twoFactorRegex.test(err.message)) { onSuccess(password, "2fa"); } - else if (lockedRegex.test(err.message)) { - onFailure("locked") - } - else if (badCredentialsRegex.test(err.message)) { - onFailure("badcredentials") - } else { onFailure(err) } diff --git a/octorun/src/bin/app-login.js b/octorun/src/bin/app-login.js index 98137e7a9..f3484c31b 100644 --- a/octorun/src/bin/app-login.js +++ b/octorun/src/bin/app-login.js @@ -13,15 +13,12 @@ var handleAuthentication = function (username, password, twoFactor) { authentication.handleAuthentication(username, password, function (token, status) { if (status) { output.custom(status, token); - process.exit(); } else { output.success(token); - process.exit(); } }, function (error) { output.error(error); - process.exit(); }, twoFactor); } @@ -41,7 +38,6 @@ if (commander.twoFactor) { } catch (error) { output.error(error); - process.exit(); } } else { @@ -108,7 +104,6 @@ else { } catch (error) { output.error(error); - process.exit(); } }); } diff --git a/octorun/src/bin/app-organizations.js b/octorun/src/bin/app-organizations.js index 401c977ae..480289aa1 100644 --- a/octorun/src/bin/app-organizations.js +++ b/octorun/src/bin/app-organizations.js @@ -14,21 +14,18 @@ try { apiWrapper.getOrgs(function (error, result) { if (error) { output.error(error); - process.exit(); } else { - results = []; + var results = []; for (var i = 0; i < result.length; i++) { results.push(result[i].name); results.push(result[i].login); } output.success(results); - process.exit(); } }); } catch (error) { output.error(error); - process.exit(); } \ No newline at end of file diff --git a/octorun/src/bin/app-publish.js b/octorun/src/bin/app-publish.js index 1b3257da2..5fe602390 100644 --- a/octorun/src/bin/app-publish.js +++ b/octorun/src/bin/app-publish.js @@ -2,6 +2,7 @@ var commander = require("commander"); var package = require('../../package.json') var ApiWrapper = require('../api') var endOfLine = require('os').EOL; +var output = require('../output'); commander .version(package.version) @@ -13,11 +14,8 @@ commander if(!commander.repository) { - process.stdout.write("repository required"); - process.stdout.write(endOfLine); commander.help(); process.exit(-1); - return; } var private = false; @@ -31,46 +29,13 @@ try { apiWrapper.publish(commander.repository, commander.description, private, commander.organization, function (error, result) { if (error) { - process.stdout.write("error"); - process.stdout.write(endOfLine); - - process.stdout.write(""); - process.stdout.write(endOfLine); - - process.stdout.write(""); - process.stdout.write(endOfLine); - - if (error) { - process.stdout.write(error.toString()); - process.stdout.write(endOfLine); - } - - process.exit(); + output.error(error); } else { - process.stdout.write("success"); - process.stdout.write(endOfLine); - - process.stdout.write(commander.repository); - process.stdout.write(endOfLine); - - process.stdout.write(result); - process.stdout.write(endOfLine); - process.exit(); + output.success(result); } }); } catch (error) { - process.stdout.write("error"); - process.stdout.write(endOfLine); - - process.stdout.write(""); - process.stdout.write(endOfLine); - - if (error) { - process.stdout.write(error.toString()); - process.stdout.write(endOfLine); - } - - process.exit(); + output.error(error); } \ No newline at end of file diff --git a/octorun/src/bin/app-usage.js b/octorun/src/bin/app-usage.js index b13a23a88..07bd3b91c 100644 --- a/octorun/src/bin/app-usage.js +++ b/octorun/src/bin/app-usage.js @@ -3,6 +3,7 @@ var package = require('../../package.json') var endOfLine = require('os').EOL; var fs = require('fs'); var util = require('util'); +var output = require('../output'); commander .version(package.version) @@ -50,38 +51,20 @@ if (fileContents && host) { res.on('data', function (d) { if (success) { - process.stdout.write("success"); - process.stdout.write(endOfLine); - process.stdout.write(d); - process.stdout.write(endOfLine); + output.custom("success", d, true); } else { - process.stdout.write("error"); - process.stdout.write(endOfLine); - - process.stdout.write(""); - process.stdout.write(endOfLine); - - process.stdout.write(d); - process.stdout.write(endOfLine); + output.custom("error", "", true); } }); res.on('end', function (d) { - process.exit(success ? 0 : -1); + process.exit(); }); }); req.on('error', function (error) { - process.stdout.write("Error"); - process.stdout.write(endOfLine); - - if (error) { - process.stdout.write(error.toString()); - process.stdout.write(endOfLine); - } - - process.exit(-1); + output.error(error); }); req.write(fileContents); diff --git a/octorun/src/output.js b/octorun/src/output.js index 22b19bdcb..cad4e002b 100644 --- a/octorun/src/output.js +++ b/octorun/src/output.js @@ -1,6 +1,6 @@ var endOfLine = require('os').EOL; -var outputResult = function (status, results, errors) { +var outputResult = function (status, results, errors, preventExit) { process.stdout.write(status); process.stdout.write(endOfLine); @@ -24,8 +24,9 @@ var outputResult = function (status, results, errors) { process.stdout.write(endOfLine); } } - - throw "Unsupported result output"; + else { + throw "Unsupported result output"; + } } if (errors) { @@ -37,26 +38,34 @@ var outputResult = function (status, results, errors) { for (var errorIndex = 0; errorIndex < errors.length; errorIndex++) { var error = errors[errorIndex]; if (typeof error !== 'string') { - throw "Unsupported result output"; + throw "Unsupported error output"; } process.stdout.write(error); process.stdout.write(endOfLine); } } + else if (errors.toString) { + process.stdout.write(errors.toString()); + process.stdout.write(endOfLine); + } else { process.stdout.write(errors); process.stdout.write(endOfLine); } } + + if (!preventExit) { + process.exit(); + } } var outputSuccess = function (results) { outputResult("success", results); } -var outputCustom = function (status, results) { - outputResult(status, results); +var outputCustom = function (status, results, preventExit) { + outputResult(status, results, undefined, preventExit); } var outputError = function (errors) { diff --git a/octorun/version b/octorun/version index 226095832..0af082cdd 100644 --- a/octorun/version +++ b/octorun/version @@ -1 +1 @@ -b91b7b60 \ No newline at end of file +46811135 \ No newline at end of file diff --git a/src/GitHub.Api/Application/ApiClient.cs b/src/GitHub.Api/Application/ApiClient.cs index 10a01e0f3..bf237ef48 100644 --- a/src/GitHub.Api/Application/ApiClient.cs +++ b/src/GitHub.Api/Application/ApiClient.cs @@ -247,12 +247,7 @@ private async Task CreateRepositoryInternal(string repositoryN }; } - if (ret.Output.Any()) - { - throw new ApiClientException(string.Join(Environment.NewLine, ret.Output)); - } - - throw new ApiClientException("Publish failed"); + throw new ApiClientException(ret.GetApiErrorMessage() ?? "Publish failed"); } catch (Exception ex) { @@ -294,12 +289,7 @@ private async Task GetOrganizationInternal(Action onSuccess, Act return; } - if (ret.Output.Any()) - { - throw new ApiClientException(string.Join(Environment.NewLine, ret.Output)); - } - - throw new ApiClientException("Error getting organizations"); + throw new ApiClientException(ret.GetApiErrorMessage() ?? "Error getting organizations"); } catch (Exception ex) { @@ -332,12 +322,7 @@ private async Task GetCurrentUserInternal() }; } - if (ret.Output.Any()) - { - throw new ApiClientException(string.Join(Environment.NewLine, ret.Output)); - } - - throw new ApiClientException("Error validating current user"); + throw new ApiClientException(ret.GetApiErrorMessage() ?? "Error validating current user"); } catch (KeychainEmptyException) { diff --git a/src/GitHub.Api/Authentication/Keychain.cs b/src/GitHub.Api/Authentication/Keychain.cs index 5e93f488c..542904020 100644 --- a/src/GitHub.Api/Authentication/Keychain.cs +++ b/src/GitHub.Api/Authentication/Keychain.cs @@ -323,6 +323,6 @@ private void UpdateConnections(Connection[] conns) public Connection[] Connections => connections.Values.ToArray(); public IList Hosts => connections.Keys.ToArray(); public bool HasKeys => connections.Any(); - public bool NeedsLoad => HasKeys && !string.IsNullOrEmpty(FindOrCreateAdapter(connections.First().Value.Host).Credential.Token); + public bool NeedsLoad => HasKeys && !string.IsNullOrEmpty(FindOrCreateAdapter(connections.First().Value.Host).Credential?.Token); } } \ No newline at end of file diff --git a/src/GitHub.Api/Authentication/LoginManager.cs b/src/GitHub.Api/Authentication/LoginManager.cs index 269458668..ce0a85ad2 100644 --- a/src/GitHub.Api/Authentication/LoginManager.cs +++ b/src/GitHub.Api/Authentication/LoginManager.cs @@ -193,22 +193,7 @@ private async Task TryLogin( return new LoginResultData(resultCodes, message, host, ret.Output[0]); } - if (ret.IsBadCredentials) - { - return new LoginResultData(LoginResultCodes.Failed, "Bad credentials.", host, ret.Output[0]); - } - - if (ret.IsLocked) - { - return new LoginResultData(LoginResultCodes.LockedOut, "Account locked.", host, ret.Output[0]); - } - - if (ret.Output.Any()) - { - return new LoginResultData(LoginResultCodes.Failed, "Failed.", host, ret.Output[0]); - } - - return new LoginResultData(LoginResultCodes.Failed, "Failed.", host); + return new LoginResultData(LoginResultCodes.Failed, ret.GetApiErrorMessage() ?? "Failed.", host); } } diff --git a/src/GitHub.Api/Installer/OctorunInstaller.cs b/src/GitHub.Api/Installer/OctorunInstaller.cs index 34f6e3c46..8b93c49d8 100644 --- a/src/GitHub.Api/Installer/OctorunInstaller.cs +++ b/src/GitHub.Api/Installer/OctorunInstaller.cs @@ -102,7 +102,7 @@ public class OctorunInstallDetails public const string DefaultZipMd5Url = "https://ghfvs-installer.github.com/unity/octorun/octorun.zip.md5"; public const string DefaultZipUrl = "https://ghfvs-installer.github.com/unity/octorun/octorun.zip"; - public const string PackageVersion = "b91b7b60"; + public const string PackageVersion = "46811135"; private const string PackageName = "octorun"; private const string zipFile = "octorun.zip"; diff --git a/src/GitHub.Api/Resources/octorun.zip b/src/GitHub.Api/Resources/octorun.zip index 24097006a..8e580d84c 100644 --- a/src/GitHub.Api/Resources/octorun.zip +++ b/src/GitHub.Api/Resources/octorun.zip @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dcdf06517450ccbad14e1bea863387bef84b24d3709eec50c371f918839606e6 -size 212554 +oid sha256:88514fe0aa33af8ccf81f31f4ca2d4e3b2e08df2f890bb1f18f8d9d5409f7a80 +size 219645 diff --git a/src/GitHub.Api/Resources/octorun.zip.md5 b/src/GitHub.Api/Resources/octorun.zip.md5 index b10619984..e4f79b239 100644 --- a/src/GitHub.Api/Resources/octorun.zip.md5 +++ b/src/GitHub.Api/Resources/octorun.zip.md5 @@ -1 +1 @@ -7cdaa49008b8c996343e07670100bce2 \ No newline at end of file +070a4561bf70031ad54ca5884f97f546 \ No newline at end of file diff --git a/src/GitHub.Api/Tasks/OctorunTask.cs b/src/GitHub.Api/Tasks/OctorunTask.cs index 1a0e04c58..f64fcc0cc 100644 --- a/src/GitHub.Api/Tasks/OctorunTask.cs +++ b/src/GitHub.Api/Tasks/OctorunTask.cs @@ -2,13 +2,12 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Reflection; +using System.Text.RegularExpressions; using System.Threading; -using GitHub.Logging; namespace GitHub.Unity { - class OctorunTaskOutputProcessor : BaseOutputProcessor + class OctorunResultOutputProcessor : BaseOutputProcessor { private int lineCount; private string status; @@ -68,7 +67,7 @@ public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOcto string user = null, string userToken = null, IOutputProcessor processor = null) - : base(token, processor ?? new OctorunTaskOutputProcessor()) + : base(token, processor ?? new OctorunResultOutputProcessor()) { this.clientId = clientId; this.clientSecret = clientSecret; @@ -114,9 +113,6 @@ public override void Configure(ProcessStartInfo psi) class OctorunResult { - public string Status { get; } - public string[] Output { get; } - public OctorunResult() { Status = "error"; @@ -129,10 +125,26 @@ public OctorunResult(string status, string[] output) Output = output; } + public string Status { get; } + public string[] Output { get; } public bool IsSuccess => Status.Equals("success", StringComparison.InvariantCultureIgnoreCase); public bool IsError => Status.Equals("error", StringComparison.InvariantCultureIgnoreCase); public bool IsTwoFactorRequired => Status.Equals("2fa", StringComparison.InvariantCultureIgnoreCase); - public bool IsLocked => Output.First().Equals("locked", StringComparison.InvariantCultureIgnoreCase); - public bool IsBadCredentials => Output.First().Equals("badcredentials", StringComparison.InvariantCultureIgnoreCase); } -} \ No newline at end of file + + static class OctorunResultExtensions + { + private static Regex ApiErrorMessageRegex = new Regex(@"\""message\"":\""(.*?)\""", RegexOptions.Compiled); + + internal static string GetApiErrorMessage(this OctorunResult octorunResult) + { + if (!octorunResult.IsError || !octorunResult.Output.Any()) + { + return null; + } + + var match = ApiErrorMessageRegex.Match(octorunResult.Output[0]); + return match.Success ? match.Groups[1].Value : octorunResult.Output[0]; + } + } +} diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs index b2031f83e..56d1731b5 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs @@ -253,7 +253,7 @@ private void ValidateAndSetGitInstallPath(string value) } else { - Logger.Warning("Software versions meet minimums Git:{0} GitLfs:{1}", + Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}", result.GitVersion, result.GitLfsVersion);