Exemplo n.º 1
0
        private void textBoxRemoteUrl_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxRemoteUrl.Text))
            {
                return;
            }
            if (textBoxRemoteUrl.Text.Contains("tfs") || textBoxRemoteUrl.Text.Contains("azure"))
            {
                RepoSourceTypeEnum = RepoSourceTypeEnum.AzureDevOps;
            }
            else if (textBoxRemoteUrl.Text.Contains("github.com"))
            {
                RepoSourceTypeEnum = RepoSourceTypeEnum.GitHub;
            }
            else
            {
                RepoSourceTypeEnum = RepoSourceTypeEnum.Unknown;
            }
            labelRepoType.Visible = true;
            labelRepoType.Text    = RepoSourceTypeEnum.ToString();

            var lastPart = textBoxRemoteUrl.Text.Split('/').Last();

            textBoxLocalFolderName.Text = lastPart.Replace(".git", "");

            RemoteURL = textBoxRemoteUrl.Text;
        }
Exemplo n.º 2
0
        public static bool CloneGitRepo(string url, string localPath, RepoSourceTypeEnum repoSourceType)
        {
            if (!IsSiteAccessible(url))
            {
                return(false);
            }

            var hasUserNameOrPassword = GetUserNameAndPassword(out var userName,
                                                               out var password, repoSourceType);

            try
            {
                var co = new CloneOptions
                {
                    CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
                    {
                        Username = userName,
                        Password = password
                    }
                };
                Repository.Clone(url, localPath, co);
                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"CloneGitRepoAsync: {ex.Message}");
                if (!hasUserNameOrPassword)
                {
                    Debug.WriteLine("CloneGitRepoAsync username or password is blank");
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Acquires username and password by RepoSourceTypeEnum
        /// Returns false if both parameters are blank
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="repoSourceTypeEnum"></param>
        /// <returns></returns>
        private static bool GetUserNameAndPassword(out string userName, out string password,
                                                   RepoSourceTypeEnum repoSourceTypeEnum)
        {
            var iniFile = new IniFile(FormMain.OptionsIni);

            var repoTypePrefix = repoSourceTypeEnum == RepoSourceTypeEnum.AzureDevOps ? "AzureDevOps" : "GitHub";

            userName = iniFile.ReadString(OptionsForm.AuthenticationSection, $"{repoTypePrefix}UserName", "");
            password = ConvertHexStringToString(iniFile.ReadString(OptionsForm.AuthenticationSection,
                                                                   $"{repoTypePrefix}Password",
                                                                   ""));

            var useUserNamePassword =
                iniFile.ReadBool(OptionsForm.AuthenticationSection, "UseUsernameAndPassword", true);

            if (repoSourceTypeEnum == RepoSourceTypeEnum.AzureDevOps && !useUserNamePassword)
            {
                var adoHexPat = iniFile.ReadString(OptionsForm.AuthenticationSection, "AzureDevOpsPAT", "");
                userName = ConvertHexStringToString(adoHexPat);
                password = ConvertHexStringToString(adoHexPat);
                var emptyPassword = !string.IsNullOrEmpty(password);
                return(emptyPassword);
            }
            else
            {
                var emptyUserName = !string.IsNullOrEmpty(userName);
                var emptyPassword = !string.IsNullOrEmpty(password);
                return(emptyUserName || emptyPassword);
            }
        }
Exemplo n.º 4
0
 public static async Task CloneGitRepoAsync(string url, string localPath, RepoSourceTypeEnum repoSourceType)
 {
     await Task.Run(() => { CloneGitRepo(url, localPath, repoSourceType); });
 }