public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config[nameof(IHasCredentials.CredentialName)];

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

            var credentials = GitHubCredentials.TryCreate(credentialName, config);

            if (credentials == null)
            {
                return(Enumerable.Empty <string>());
            }

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

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

            var client = new GitHubClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.OrganizationName);

            var orgs = await client.GetOrganizationsAsync(CancellationToken.None).ConfigureAwait(false);

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

            return(names);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];

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

            var credentials = GitHubCredentials.TryCreate(credentialName, config);

            if (credentials == null)
            {
                return(Enumerable.Empty <string>());
            }

            string ownerName      = AH.CoalesceString(credentials.OrganizationName, credentials.UserName);
            string repositoryName = AH.CoalesceString(config["RepositoryName"], credentials.RepositoryName);

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

            var client = new GitHubClient(credentials.ApiUrl, credentials.UserName, credentials.Password, credentials.OrganizationName);

            var milestones = await client.GetMilestonesAsync(ownerName, repositoryName, "open", CancellationToken.None).ConfigureAwait(false);

            var titles = from m in milestones
                         let title = m["title"]?.ToString()
                                     where !string.IsNullOrEmpty(title)
                                     select title;

            if (SDK.ProductName == "BuildMaster")
            {
                titles = new[] { "$ReleaseName", "$ReleaseNumber" }.Concat(titles);
            }
            return(titles);
        }
        protected override ExtendedRichDescription GetDescription(IOperationConfiguration config)
        {
            var credentials     = string.IsNullOrEmpty(config[nameof(CredentialName)]) ? null : GitHubCredentials.TryCreate(config[nameof(CredentialName)], config);
            var repositoryOwner = AH.CoalesceString(config[nameof(OrganizationName)], credentials?.OrganizationName, config[nameof(UserName)], credentials?.UserName, "(unknown)");
            var repositoryName  = AH.CoalesceString(config[nameof(RepositoryName)], credentials?.RepositoryName, "(unknown)");

            return(new ExtendedRichDescription(
                       new RichDescription("Set build status on GitHub commit ", new Hilite(config[nameof(CommitHash)]), " to ", new Hilite(config[nameof(Status)])),
                       new RichDescription("in repository ", new Hilite(repositoryOwner), "/", new Hilite(repositoryName))
                       ));
        }