Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 76a10c5

Browse files
Merge remote-tracking branch 'remotes/origin/features/octorun-js' into fixes/octorun-refactor-authentication
# Conflicts: # octorun/src/authentication.js # octorun/src/bin/app-login.js # src/GitHub.Api/Tasks/OctorunTask.cs
2 parents f435e4d + c5d6949 commit 76a10c5

File tree

14 files changed

+72
-72
lines changed

14 files changed

+72
-72
lines changed

octorun/.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
OCTOKIT_CLIENT_ID=
22
OCTOKIT_CLIENT_SECRET=
3+
OCTOKIT_USER_AGENT=
34
OCTORUN_USER=
45
OCTORUN_TOKEN=

octorun/src/api.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ function ApiWrapper() {
55
this.octokit = octokitWrapper.createOctokit();
66

77
if (!config.user || !config.token) {
8-
throw "User and/or Token missing";
8+
throw "user and/or token missing";
9+
}
10+
11+
if (!config.appName) {
12+
throw "appName missing";
913
}
1014

1115
this.octokit.authenticate({

octorun/src/authentication.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ var badCredentialsRegex = new RegExp("bad credentials", "gi");
99
var scopes = ["user", "repo", "gist", "write:public_key"];
1010

1111
var handleAuthentication = function (username, password, onSuccess, onFailure, twoFactor) {
12+
if (!config.clientId || !config.clientSecret) {
13+
throw "clientId and/or clientSecret missing";
14+
}
15+
16+
if (!config.appName) {
17+
throw "appName missing";
18+
}
19+
1220
var octokit = octokitWrapper.createOctokit();
1321

1422
octokit.authenticate({
@@ -20,7 +28,8 @@ var handleAuthentication = function (username, password, onSuccess, onFailure, t
2028
var headers;
2129
if (twoFactor) {
2230
headers = {
23-
"X-GitHub-OTP": twoFactor
31+
"X-GitHub-OTP": twoFactor,
32+
"user-agent": config.appName
2433
};
2534
}
2635

octorun/src/bin/app-login.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ if (commander.twoFactor) {
3636

3737
var twoFactor = readlineSync.question('Two Factor: ');
3838

39-
handleAuthentication(username, password, twoFactor);
39+
try {
40+
handleAuthentication(username, password, twoFactor);
41+
}
42+
catch (error) {
43+
output.error(error);
44+
process.exit();
45+
}
4046
}
4147
else {
4248
var data = '';
@@ -54,7 +60,13 @@ if (commander.twoFactor) {
5460
.split(/\r?\n/)
5561
.filter(function (item) { return item; });
5662

57-
handleAuthentication(items[0], items[1], items[2]);
63+
try {
64+
handleAuthentication(items[0], items[1], items[2]);
65+
}
66+
catch (error) {
67+
output.error(error);
68+
process.exit();
69+
}
5870
});
5971
}
6072
}
@@ -67,7 +79,13 @@ else {
6779
hideEchoBack: true
6880
});
6981

70-
handleAuthentication(username, password);
82+
try {
83+
handleAuthentication(username, password);
84+
}
85+
catch (error) {
86+
output.error(error);
87+
process.exit();
88+
}
7189
}
7290
else {
7391
var data = '';
@@ -85,7 +103,13 @@ else {
85103
.split(/\r?\n/)
86104
.filter(function (item) { return item; });
87105

88-
handleAuthentication(items[0], items[1]);
106+
try {
107+
handleAuthentication(items[0], items[1]);
108+
}
109+
catch (error) {
110+
output.error(error);
111+
process.exit();
112+
}
89113
});
90114
}
91115
}

octorun/src/configuration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require("dotenv").config({silent: true});
22

33
var clientId = process.env.OCTOKIT_CLIENT_ID;
44
var clientSecret = process.env.OCTOKIT_CLIENT_SECRET;
5-
var appName = process.env.OCTORUN_APP_NAME | "octorun";
5+
var appName = process.env.OCTOKIT_USER_AGENT;
66
var user = process.env.OCTORUN_USER;
77
var token = process.env.OCTORUN_TOKEN;
88

src/GitHub.Api/Application/ApplicationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static partial class ApplicationInfo
1010
public const string ApplicationName = "GitHubUnity";
1111
public const string ApplicationProvider = "GitHub";
1212
#endif
13-
public const string ApplicationSafeName = "unity-internal-test";
13+
public const string ApplicationSafeName = "GitHubUnity";
1414
public const string ApplicationDescription = "GitHub for Unity";
1515

1616
internal static string ClientId { get; private set; } = "";

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ public ITask InitializeRepository()
8888

8989
var targetPath = NPath.CurrentDirectory;
9090

91-
var unityYamlMergeExec = Environment.IsWindows
92-
? Environment.UnityApplication.Parent.Combine("Data", "Tools", "UnityYAMLMerge.exe")
93-
: Environment.UnityApplication.Combine("Contents", "Tools", "UnityYAMLMerge");
91+
var unityYamlMergeExec = Environment.UnityApplicationContents.Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);
9492

9593
var yamlMergeCommand = Environment.IsWindows
9694
? $@"'{unityYamlMergeExec}' merge -p ""$BASE"" ""$REMOTE"" ""$LOCAL"" ""$MERGED"""

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public DefaultEnvironment(ICacheContainer cacheContainer)
4242
this.CacheContainer = cacheContainer;
4343
}
4444

45-
public void Initialize(string unityVersion, NPath extensionInstallPath, NPath unityPath, NPath assetsPath)
45+
public void Initialize(string unityVersion, NPath extensionInstallPath, NPath unityApplicationPath, NPath unityApplicationContentsPath, NPath assetsPath)
4646
{
4747
ExtensionInstallPath = extensionInstallPath;
48-
UnityApplication = unityPath;
48+
UnityApplication = unityApplicationPath;
49+
UnityApplicationContents = unityApplicationContentsPath;
4950
UnityAssetsPath = assetsPath;
5051
UnityProjectPath = assetsPath.Parent;
5152
UnityVersion = unityVersion;
@@ -109,6 +110,7 @@ public string GetEnvironmentVariable(string variable)
109110
public IFileSystem FileSystem { get { return NPath.FileSystem; } set { NPath.FileSystem = value; } }
110111
public string UnityVersion { get; set; }
111112
public NPath UnityApplication { get; set; }
113+
public NPath UnityApplicationContents { get; set; }
112114
public NPath UnityAssetsPath { get; set; }
113115
public NPath UnityProjectPath { get; set; }
114116
public NPath ExtensionInstallPath { get; set; }
@@ -140,9 +142,8 @@ public NPath NodeJsExecutablePath
140142
{
141143
if (!nodeJsExecutablePath.IsInitialized)
142144
{
143-
nodeJsExecutablePath = IsWindows
144-
? UnityApplication.Parent.Combine("Data", "Tools", "nodejs", "node.exe")
145-
: UnityApplication.Combine("Contents", "Tools", "nodejs", "node");
145+
nodeJsExecutablePath =
146+
UnityApplicationContents.Combine("Tools", "nodejs", "node" + ExecutableExtension);
146147
}
147148

148149
return nodeJsExecutablePath;
@@ -207,7 +208,7 @@ public static bool OnMac
207208
}
208209
set { onMac = value; }
209210
}
210-
public string ExecutableExtension { get { return IsWindows ? ".exe" : null; } }
211+
public string ExecutableExtension { get { return IsWindows ? ".exe" : string.Empty; } }
211212
protected static ILogging Logger { get; } = LogHelper.GetLogger<DefaultEnvironment>();
212213
}
213214
}

src/GitHub.Api/Platform/IEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace GitHub.Unity
44
{
55
public interface IEnvironment
66
{
7-
void Initialize(string unityVersion, NPath extensionInstallPath, NPath unityPath, NPath assetsPath);
7+
void Initialize(string unityVersion, NPath extensionInstallPath, NPath unityApplicationPath, NPath unityApplicationContentsPath, NPath assetsPath);
88
void InitializeRepository(NPath? expectedRepositoryPath = null);
99
string ExpandEnvironmentVariables(string name);
1010
string GetEnvironmentVariable(string v);
@@ -20,6 +20,7 @@ public interface IEnvironment
2020
bool IsMac { get; }
2121
string UnityVersion { get; }
2222
NPath UnityApplication { get; }
23+
NPath UnityApplicationContents { get; }
2324
NPath UnityAssetsPath { get; }
2425
NPath UnityProjectPath { get; }
2526
NPath ExtensionInstallPath { get; }

src/GitHub.Api/Tasks/OctorunTask.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
5+
using System.Reflection;
56
using System.Threading;
67
using GitHub.Logging;
78

@@ -58,6 +59,7 @@ class OctorunTask : ProcessTask<OctorunResult>
5859
private readonly string userToken;
5960

6061
private readonly NPath pathToNodeJs;
62+
private readonly NPath pathToOctorunJs;
6163
private readonly string arguments;
6264

6365
public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOctorunJs, string arguments,
@@ -73,13 +75,18 @@ public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOcto
7375
this.user = user;
7476
this.userToken = userToken;
7577
this.pathToNodeJs = pathToNodeJs;
78+
this.pathToOctorunJs = pathToOctorunJs;
7679
this.arguments = $"{pathToOctorunJs} {arguments}";
7780
}
7881

7982
public override void Configure(ProcessStartInfo psi)
8083
{
8184
base.Configure(psi);
8285

86+
psi.WorkingDirectory = pathToOctorunJs.Parent.Parent.Parent;
87+
88+
psi.EnvironmentVariables.Add("OCTOKIT_USER_AGENT", $"{ApplicationInfo.ApplicationSafeName}/{ApplicationInfo.Version}");
89+
8390
if (clientId != null)
8491
{
8592
psi.EnvironmentVariables.Add("OCTOKIT_CLIENT_ID", clientId);

0 commit comments

Comments
 (0)