Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
1 change: 1 addition & 0 deletions octorun/.env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OCTOKIT_CLIENT_ID=
OCTOKIT_CLIENT_SECRET=
OCTOKIT_USER_AGENT=
OCTORUN_USER=
OCTORUN_TOKEN=
6 changes: 5 additions & 1 deletion octorun/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ function ApiWrapper() {
this.octokit = octokitWrapper.createOctokit();

if (!config.user || !config.token) {
throw "User and/or Token missing";
throw "user and/or token missing";
}

if (!config.appName) {
throw "appName missing";
}

this.octokit.authenticate({
Expand Down
20 changes: 18 additions & 2 deletions octorun/src/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ var twoFactorRegex = new RegExp("must specify two-factor authentication otp code
var badCredentialsRegex = new RegExp("bad credentials", "gi");

var handleBasicAuthentication = function (username, password, onSuccess, onRequiresTwoFa, onFailure) {
if (!config.clientId || !config.clientSecret) {
throw "clientId and/or clientSecret missing";
}

if (!config.appName) {
throw "appName missing";
}

var octokit = octokitWrapper.createOctokit();

octokit.authenticate({
Expand Down Expand Up @@ -44,6 +52,14 @@ var handleBasicAuthentication = function (username, password, onSuccess, onRequi
}

var handleTwoFactorAuthentication = function (username, password, twoFactor, onSuccess, onFailure) {
if (!config.clientId || !config.clientSecret) {
throw "clientId and/or clientSecret missing";
}

if (!config.appName) {
throw "appName missing";
}

var octokit = octokitWrapper.createOctokit();

octokit.authenticate({
Expand All @@ -54,11 +70,11 @@ var handleTwoFactorAuthentication = function (username, password, twoFactor, onS

octokit.authorization.create({
scopes: scopes,
note: config.appName,
client_id: config.clientId,
client_secret: config.clientSecret,
headers: {
"X-GitHub-OTP": twoFactor
"X-GitHub-OTP": twoFactor,
"user-agent": config.appName
}
}, function (err, res) {
if (err) {
Expand Down
32 changes: 28 additions & 4 deletions octorun/src/bin/app-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ if (commander.twoFactor) {

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

handleTwoFactorAuthentication(username, password, twoFactor);
try {
handleTwoFactorAuthentication(username, password, twoFactor);
}
catch (error) {
output.error(error);
process.exit();
}
}
else {
var data = '';
Expand All @@ -49,7 +55,13 @@ if (commander.twoFactor) {
.split(/\r?\n/)
.filter(function (item) { return item; });

handleTwoFactorAuthentication(items[0], items[1], items[2]);
try {
handleTwoFactorAuthentication(items[0], items[1], items[2]);
}
catch (error) {
output.error(error);
process.exit();
}
});
}
}
Expand All @@ -76,7 +88,13 @@ else {
hideEchoBack: true
});

handleBasicAuthentication(username, password);
try {
handleBasicAuthentication(username, password);
}
catch (error) {
output.error(error);
process.exit();
}
}
else {
var data = '';
Expand All @@ -94,7 +112,13 @@ else {
.split(/\r?\n/)
.filter(function (item) { return item; });

handleBasicAuthentication(items[0], items[1]);
try {
handleBasicAuthentication(items[0], items[1]);
}
catch (error) {
output.error(error);
process.exit();
}
});
}
}
2 changes: 1 addition & 1 deletion octorun/src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require("dotenv").config({silent: true});

var clientId = process.env.OCTOKIT_CLIENT_ID;
var clientSecret = process.env.OCTOKIT_CLIENT_SECRET;
var appName = process.env.OCTORUN_APP_NAME | "octorun";
var appName = process.env.OCTOKIT_USER_AGENT;
var user = process.env.OCTORUN_USER;
var token = process.env.OCTORUN_TOKEN;

Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Application/ApplicationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static partial class ApplicationInfo
public const string ApplicationName = "GitHubUnity";
public const string ApplicationProvider = "GitHub";
#endif
public const string ApplicationSafeName = "unity-internal-test";
public const string ApplicationSafeName = "GitHubUnity";
public const string ApplicationDescription = "GitHub for Unity";

internal static string ClientId { get; private set; } = "";
Expand Down
7 changes: 7 additions & 0 deletions src/GitHub.Api/Tasks/OctorunTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using GitHub.Logging;

Expand Down Expand Up @@ -57,6 +58,7 @@ class OctorunTask : ProcessTask<OctorunResult>
private readonly string userToken;

private readonly NPath pathToNodeJs;
private readonly NPath pathToOctorunJs;
private readonly string arguments;

public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOctorunJs, string arguments,
Expand All @@ -72,13 +74,18 @@ public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOcto
this.user = user;
this.userToken = userToken;
this.pathToNodeJs = pathToNodeJs;
this.pathToOctorunJs = pathToOctorunJs;
this.arguments = $"{pathToOctorunJs} {arguments}";
}

public override void Configure(ProcessStartInfo psi)
{
base.Configure(psi);

psi.WorkingDirectory = pathToOctorunJs.Parent.Parent.Parent;

psi.EnvironmentVariables.Add("OCTOKIT_USER_AGENT", $"{ApplicationInfo.ApplicationSafeName}/{ApplicationInfo.Version}");

if (clientId != null)
{
psi.EnvironmentVariables.Add("OCTOKIT_CLIENT_ID", clientId);
Expand Down