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

Commit c3b6370

Browse files
Proving the user agent to octokit
1 parent b7bb946 commit c3b6370

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ var twoFactorRegex = new RegExp("must specify two-factor authentication otp code
99
var badCredentialsRegex = new RegExp("bad credentials", "gi");
1010

1111
var handleBasicAuthentication = function (username, password, onSuccess, onRequiresTwoFa, onFailure) {
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({
@@ -44,6 +52,14 @@ var handleBasicAuthentication = function (username, password, onSuccess, onRequi
4452
}
4553

4654
var handleTwoFactorAuthentication = function (username, password, twoFactor, onSuccess, onFailure) {
55+
if (!config.clientId || !config.clientSecret) {
56+
throw "clientId and/or clientSecret missing";
57+
}
58+
59+
if (!config.appName) {
60+
throw "appName missing";
61+
}
62+
4763
var octokit = octokitWrapper.createOctokit();
4864

4965
octokit.authenticate({

octorun/src/bin/app-login.js

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

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

34-
handleTwoFactorAuthentication(username, password, twoFactor);
34+
try {
35+
handleTwoFactorAuthentication(username, password, twoFactor);
36+
}
37+
catch (error) {
38+
output.error(error);
39+
process.exit();
40+
}
3541
}
3642
else {
3743
var data = '';
@@ -49,7 +55,13 @@ if (commander.twoFactor) {
4955
.split(/\r?\n/)
5056
.filter(function (item) { return item; });
5157

52-
handleTwoFactorAuthentication(items[0], items[1], items[2]);
58+
try {
59+
handleTwoFactorAuthentication(items[0], items[1], items[2]);
60+
}
61+
catch (error) {
62+
output.error(error);
63+
process.exit();
64+
}
5365
});
5466
}
5567
}
@@ -76,7 +88,13 @@ else {
7688
hideEchoBack: true
7789
});
7890

79-
handleBasicAuthentication(username, password);
91+
try {
92+
handleBasicAuthentication(username, password);
93+
}
94+
catch (error) {
95+
output.error(error);
96+
process.exit();
97+
}
8098
}
8199
else {
82100
var data = '';
@@ -94,7 +112,13 @@ else {
94112
.split(/\r?\n/)
95113
.filter(function (item) { return item; });
96114

97-
handleBasicAuthentication(items[0], items[1]);
115+
try {
116+
handleBasicAuthentication(items[0], items[1]);
117+
}
118+
catch (error) {
119+
output.error(error);
120+
process.exit();
121+
}
98122
});
99123
}
100124
}

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.OCTOKIT_USER_AGENT | "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/Tasks/OctorunTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public override void Configure(ProcessStartInfo psi)
8080
{
8181
base.Configure(psi);
8282

83-
psi.EnvironmentVariables.Add("OCTOKIT_USER_AGENT", ApplicationInfo.ApplicationSafeName+ AssemblyName.Version.ToString());
83+
psi.EnvironmentVariables.Add("OCTOKIT_USER_AGENT", $"{ApplicationInfo.ApplicationSafeName}/{ApplicationInfo.Version}");
8484

8585
if (clientId != null)
8686
{

0 commit comments

Comments
 (0)