Skip to content

Commit 5ef3ab5

Browse files
committed
Implemented the access token option
1 parent f94fb00 commit 5ef3ab5

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Source/GitReleaseManager.Cli/Options/BaseGitHubSubOptions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ namespace GitReleaseManager.Cli.Options
1010

1111
public abstract class BaseGitHubSubOptions : BaseSubOptions
1212
{
13-
[Option('u', "username", HelpText = "The username to access GitHub with.", Required = true)]
13+
[Option('u', "username", HelpText = "The username to access GitHub with.", Required = true, SetName = "Basic Auth")]
1414
public string UserName { get; set; }
1515

16-
[Option('p', "password", HelpText = "The password to access GitHub with.", Required = true)]
16+
[Option('p', "password", HelpText = "The password to access GitHub with.", Required = true, SetName = "Basic Auth")]
1717
public string Password { get; set; }
1818

19+
[Option("token", HelpText = "The Access Token to access GitHub with.", Required = true, SetName = "OAuth flow")]
20+
public string Token { get; set; }
21+
1922
[Option('o', "owner", HelpText = "The owner of the repository.", Required = true)]
2023
public string RepositoryOwner { get; set; }
2124

@@ -24,7 +27,10 @@ public abstract class BaseGitHubSubOptions : BaseSubOptions
2427

2528
public GitHubClient CreateGitHubClient()
2629
{
27-
var credentials = new Credentials(this.UserName, this.Password);
30+
var credentials = string.IsNullOrWhiteSpace(Token)
31+
? new Credentials(UserName, Password)
32+
: new Credentials(Token);
33+
2834
var github = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = credentials };
2935
return github;
3036
}

Source/GitReleaseManager.Cli/Program.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ private static int Main(string[] args)
3636
var fileSystem = new FileSystem();
3737

3838
return Parser.Default.ParseArguments<CreateSubOptions, AddAssetSubOptions, CloseSubOptions, PublishSubOptions, ExportSubOptions, InitSubOptions, ShowConfigSubOptions>(args)
39-
.MapResult(
40-
(CreateSubOptions opts) => CreateReleaseAsync(opts, fileSystem).Result,
41-
(AddAssetSubOptions opts) => AddAssetsAsync(opts).Result,
42-
(CloseSubOptions opts) => CloseMilestoneAsync(opts).Result,
43-
(PublishSubOptions opts) => PublishReleaseAsync(opts).Result,
44-
(ExportSubOptions opts) => ExportReleasesAsync(opts, fileSystem).Result,
45-
(InitSubOptions opts) => CreateSampleConfigFile(opts, fileSystem),
46-
(ShowConfigSubOptions opts) => ShowConfig(opts, fileSystem),
47-
errs => 1);
39+
.MapResult(
40+
(CreateSubOptions opts) => CreateReleaseAsync(opts, fileSystem).Result,
41+
(AddAssetSubOptions opts) => AddAssetsAsync(opts).Result,
42+
(CloseSubOptions opts) => CloseMilestoneAsync(opts).Result,
43+
(PublishSubOptions opts) => PublishReleaseAsync(opts).Result,
44+
(ExportSubOptions opts) => ExportReleasesAsync(opts, fileSystem).Result,
45+
(InitSubOptions opts) => CreateSampleConfigFile(opts, fileSystem),
46+
(ShowConfigSubOptions opts) => ShowConfig(opts, fileSystem),
47+
errs => 1);
4848
}
4949

5050
private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, IFileSystem fileSystem)

0 commit comments

Comments
 (0)