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

Commit 97e9176

Browse files
Adding an OctorunTask
1 parent 8b22779 commit 97e9176

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

script

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain, IPr
3030
private readonly IGitHubClient githubClient;
3131
private readonly IProcessManager processManager;
3232
private readonly ITaskManager taskManager;
33+
private readonly NPath nodeJsExecutablePath;
34+
private readonly NPath octorunScriptPath;
3335
private readonly ILoginManager loginManager;
3436

3537
public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClient, IProcessManager processManager, ITaskManager taskManager, NPath nodeJsExecutablePath, NPath octorunScriptPath)
@@ -44,6 +46,8 @@ public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClie
4446
this.githubClient = githubClient;
4547
this.processManager = processManager;
4648
this.taskManager = taskManager;
49+
this.nodeJsExecutablePath = nodeJsExecutablePath;
50+
this.octorunScriptPath = octorunScriptPath;
4751
loginManager = new LoginManager(keychain, ApplicationInfo.ClientId, ApplicationInfo.ClientSecret,
4852
processManager: processManager,
4953
taskManager: taskManager,

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ string password
261261
{
262262
logger.Info("Login Username:{0} Script:{1}", username, octorunScript);
263263

264-
ApplicationAuthorization auth = null;
265-
var loginTask = new SimpleListProcessTask(taskManager.Token, nodeJsExecutablePath, $"{octorunScript} login");
264+
ApplicationAuthorization auth;
265+
var loginTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath, octorunScript,
266+
"login", ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
266267
loginTask.Configure(processManager, workingDirectory: octorunScript.Parent.Parent, withInput: true);
267268
loginTask.OnStartProcess += proc =>
268269
{
@@ -280,7 +281,7 @@ string password
280281

281282
if (ret.Count == 1)
282283
{
283-
if (ret[0] == ("Must specify two-factor authentication OTP code."))
284+
if (ret[0] == "Must specify two-factor authentication OTP code.")
284285
{
285286
keychain.SetToken(host, ret[0]);
286287
await keychain.Save(host);
@@ -312,8 +313,9 @@ string code
312313
{
313314
logger.Info("Continue Username:{0}", username);
314315

315-
ApplicationAuthorization auth = null;
316-
var loginTask = new SimpleListProcessTask(taskManager.Token, nodeJsExecutablePath, $"{octorunScript} login --twoFactor");
316+
ApplicationAuthorization auth;
317+
var loginTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath, octorunScript,
318+
"login --twoFactor", ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
317319
loginTask.Configure(processManager, workingDirectory: octorunScript.Parent.Parent, withInput: true);
318320
loginTask.OnStartProcess += proc =>
319321
{

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<Compile Include="Tasks\ConfigOutputProcessor.cs" />
141141
<Compile Include="Tasks\DownloadTask.cs" />
142142
<Compile Include="Tasks\ITaskManager.cs" />
143+
<Compile Include="Tasks\OctorunTask.cs" />
143144
<Compile Include="Tasks\ProcessTask.cs" />
144145
<Compile Include="Tasks\TaskBase.cs" />
145146
<Compile Include="Tasks\TaskCanceledExceptions.cs" />

src/GitHub.Api/Tasks/OctorunTask.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
using System.Threading;
4+
5+
namespace GitHub.Unity
6+
{
7+
class OctorunTask : SimpleListProcessTask
8+
{
9+
private readonly string clientId;
10+
private readonly string clientSecret;
11+
private readonly string user;
12+
private readonly string userToken;
13+
14+
public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOctorunJs, string arguments,
15+
string clientId = null,
16+
string clientSecret = null,
17+
string user = null,
18+
string userToken = null,
19+
IOutputProcessor<string, List<string>> processor = null)
20+
: base(token, pathToNodeJs, $"{pathToOctorunJs} {arguments}", processor)
21+
{
22+
this.clientId = clientId;
23+
this.clientSecret = clientSecret;
24+
this.user = user;
25+
this.userToken = userToken;
26+
}
27+
28+
public override void Configure(ProcessStartInfo psi)
29+
{
30+
base.Configure(psi);
31+
32+
if (clientId != null)
33+
{
34+
psi.EnvironmentVariables.Add("OCTOKIT_CLIENT_ID", clientId);
35+
}
36+
37+
if (clientSecret != null)
38+
{
39+
psi.EnvironmentVariables.Add("OCTOKIT_CLIENT_SECRET", clientSecret);
40+
}
41+
42+
if (user != null)
43+
{
44+
psi.EnvironmentVariables.Add("OCTORUN_USER", user);
45+
}
46+
47+
if (userToken != null)
48+
{
49+
psi.EnvironmentVariables.Add("OCTORUN_TOKEN", userToken);
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)