Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 31513bd

Browse files
Move AuthenticationInfo.ToFetchOptions to extension methods to allow usage with null instance
1 parent 23b26fe commit 31513bd

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/GitTools.Core/GitTools.Core.Shared/Git/AuthenticationInfo.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,5 @@ public class AuthenticationInfo
77
public string Username { get; set; }
88
public string Password { get; set; }
99
public string Token { get; set; }
10-
11-
public FetchOptions ToFetchOptions()
12-
{
13-
var fetchOptions = new FetchOptions();
14-
15-
if (!string.IsNullOrEmpty(Username))
16-
{
17-
fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
18-
{
19-
Username = Username,
20-
Password = Password
21-
};
22-
}
23-
24-
return fetchOptions;
25-
}
2610
}
2711
}

src/GitTools.Core/GitTools.Core.Shared/Git/Extensions/AuthenticationInfoExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
namespace GitTools.Git
22
{
3+
using LibGit2Sharp;
34
using Logging;
45

56
public static class AuthenticationInfoExtensions
67
{
78
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();
89

10+
public static FetchOptions ToFetchOptions(this AuthenticationInfo authenticationInfo)
11+
{
12+
var fetchOptions = new FetchOptions();
13+
14+
if (authenticationInfo != null)
15+
{
16+
if (!string.IsNullOrEmpty(authenticationInfo.Username))
17+
{
18+
fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
19+
{
20+
Username = authenticationInfo.Username,
21+
Password = authenticationInfo.Password
22+
};
23+
}
24+
}
25+
26+
return fetchOptions;
27+
}
28+
929
public static bool IsEmpty(this AuthenticationInfo authenticationInfo)
1030
{
1131
if (authenticationInfo == null)

0 commit comments

Comments
 (0)