Exemple #1
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];

            if (string.IsNullOrEmpty(credentialName))
            {
                return(Enumerable.Empty <string>());
            }

            var credentials = ResourceCredentials.Create <GitLabCredentials>(credentialName);

            string ownerName = AH.CoalesceString(credentials.GroupName, credentials.UserName);

            if (string.IsNullOrEmpty(ownerName))
            {
                return(Enumerable.Empty <string>());
            }

            var client = new GitLabClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.GroupName);
            var repos  = await client.GetProjectsAsync(CancellationToken.None).ConfigureAwait(false);


            var names = from m in repos
                        let name = m["path_with_namespace"]?.ToString()
                                   where !string.IsNullOrEmpty(name)
                                   select name;

            if (SDK.ProductName == "BuildMaster")
            {
                names = new[] { $"{ownerName}/$ApplicationName" }.Concat(names);
            }
            return(names);
        }
        public async Task <IEnumerable <ProjectDto> > GetProjectsAsync()
        {
            this.IsPending = true;
            try
            {
                if (this.UserId == null)
                {
                    throw new InvalidOperationException("UserId is null");
                }

                using (var client = new GitLabClient(this.GitOptions))
                {
                    var projects = await client.GetProjectsAsync(this.UserId.Value);

                    return(projects);
                }
            }
            catch (Exception ex)
            {
                this.errorService.AddError(ex);
                return(new ProjectDto[0]);
            }
            finally
            {
                this.IsPending = false;
            }
        }
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            string ownerName = AH.CoalesceString(config[nameof(GitLabCredentials.GroupName)], config[nameof(GitLabCredentials.UserName)]);

            if (string.IsNullOrEmpty(ownerName))
            {
                return(Enumerable.Empty <string>());
            }

            GitLabClient client;

            try
            {
                client = new GitLabClient(config[nameof(GitLabCredentials.ApiUrl)], config[nameof(GitLabCredentials.UserName)], AH.CreateSecureString(config[nameof(GitLabCredentials.Password)].ToString()), config[nameof(GitLabCredentials.GroupName)]);
            }
            catch (InvalidOperationException)
            {
                return(Enumerable.Empty <string>());
            }

            var repos = await client.GetProjectsAsync(CancellationToken.None).ConfigureAwait(false);

            var names = from m in repos
                        let name = m["path_with_namespace"]?.ToString()
                                   where !string.IsNullOrEmpty(name)
                                   select name;

            return(names);
        }