Exemplo n.º 1
0
        public async void ItCanRetrieveMultipleRepoSettingsForASingleOwner()
        {
            var results = await _store.GetRepoSettingsAsync("owner-0", "repo-0");

            results.Should().NotBeNull();
            results.OwnerId.Should().Be("owner-0");
            results.RepositoryId.Should().Be("repo-0");
        }
Exemplo n.º 2
0
        public async Task ItCanCreateAndRetrieveRepoSettings()
        {
            var repoSettings = new RepoSettings
            {
                OwnerId      = "owner-1",
                RepositoryId = "repo-1",
                OwnerIsOrg   = false,
                LastModified = DateTime.UtcNow
            };

            await _store.CreateOrUpdateRepoSettingsAsync(repoSettings);

            var retrievedRepoSettings = await _store.GetRepoSettingsAsync("owner-1", "repo-1");

            retrievedRepoSettings.Id.Should().Be("owner-1/repo-1");
            retrievedRepoSettings.OwnerId.Should().Be("owner-1");
            retrievedRepoSettings.RepositoryId.Should().Be("repo-1");
            (retrievedRepoSettings.OwnerIsOrg).Should().BeFalse();
            retrievedRepoSettings.LastModified.Should().BeCloseTo(repoSettings.LastModified);

            var retrievedByIdRepoSettings = await _store.GetRepoSettingsByIdAsync("owner-1/repo-1");

            retrievedByIdRepoSettings.Id.Should().Be("owner-1/repo-1");
            retrievedByIdRepoSettings.OwnerId.Should().Be("owner-1");
            retrievedByIdRepoSettings.RepositoryId.Should().Be("repo-1");
            (retrievedByIdRepoSettings.OwnerIsOrg).Should().BeFalse();
            retrievedByIdRepoSettings.LastModified.Should().BeCloseTo(repoSettings.LastModified);
        }
Exemplo n.º 3
0
        private async Task <ContactInfo> GetPublisherContactInfo(string ownerId, string repoId)
        {
            try
            {
                ProgressLog.Info("Attempting to retrieve publisher contact information from repository settings");
                // get repoSettings
                var repoSettings = await RepoSettingsStore.GetRepoSettingsAsync(ownerId, repoId);

                if (repoSettings?.DefaultPublisher != null)
                {
                    ProgressLog.Info("Returning publisher from repository settings");
                    return(repoSettings.DefaultPublisher);
                }
                // no repo settings publisher, try at owner level
                ProgressLog.Info("No publisher info found in repository settings");
                if (ownerId != null)
                {
                    ProgressLog.Info("Attempting to retrieve publisher contact information from repository owner's settings");
                    var ownerSettings = await OwnerSettingsStore.GetOwnerSettingsAsync(ownerId);

                    if (ownerSettings?.DefaultPublisher != null)
                    {
                        ProgressLog.Info("Returning publisher from repository owner's settings");
                        return(ownerSettings.DefaultPublisher);
                    }
                }
                // no settings / publisher found for that repo
                ProgressLog.Info("No publisher info found in repository owner's settings");
                return(null);
            }
            catch (Exception)
            {
                ProgressLog.Error("Error when attempting to retrieve publisher contact information from repository/owner settings");
                return(null);
            }
        }
Exemplo n.º 4
0
        private async Task <PortalInfoDrop> GetPortalSettingsInfo(string ownerId, string repoId, string authenticationToken)
        {
            try
            {
                ProgressLog.Info("Attempting to retrieve portal settings information from owner settings");
                if (ownerId != null)
                {
                    var portalInfo = new PortalInfoDrop
                    {
                        OwnerId        = ownerId,
                        RepositoryName = repoId
                    };

                    ProgressLog.Info("Attempting to retrieve publisher contact information from repository owner's settings");
                    var ownerSettings = await OwnerSettingsStore.GetOwnerSettingsAsync(ownerId);

                    if (ownerSettings != null)
                    {
                        portalInfo.IsOrg             = ownerSettings.IsOrg;
                        portalInfo.ShowDashboardLink = ownerSettings.DisplayDataDockLink;
                        if (!string.IsNullOrEmpty(ownerSettings.TwitterHandle))
                        {
                            portalInfo.Twitter = ownerSettings.TwitterHandle;
                        }

                        var client = GitHubClientFactory.CreateClient(authenticationToken);
                        if (ownerSettings.IsOrg)
                        {
                            var org = await client.Organization.Get(ownerId);

                            if (org == null)
                            {
                                return(portalInfo);
                            }

                            portalInfo.OwnerDisplayName = org.Name ?? ownerId;
                            if (ownerSettings.DisplayGitHubBlogUrl)
                            {
                                portalInfo.Website = org.Blog;
                            }
                            if (ownerSettings.DisplayGitHubAvatar)
                            {
                                portalInfo.LogoUrl = org.AvatarUrl;
                            }
                            if (ownerSettings.DisplayGitHubDescription)
                            {
                                portalInfo.Description = org.Bio;
                            }
                            if (ownerSettings.DisplayGitHubBlogUrl)
                            {
                                portalInfo.Website = org.Blog;
                            }
                            if (ownerSettings.DisplayGitHubLocation)
                            {
                                portalInfo.Location = org.Location;
                            }
                            if (ownerSettings.DisplayGitHubIssuesLink)
                            {
                                portalInfo.GitHubHtmlUrl = org.HtmlUrl;
                            }
                        }
                        else
                        {
                            var user = await client.User.Get(ownerId);

                            if (user == null)
                            {
                                return(portalInfo);
                            }

                            portalInfo.OwnerDisplayName = user.Name ?? ownerId;
                            if (ownerSettings.DisplayGitHubBlogUrl)
                            {
                                portalInfo.Website = user.Blog;
                            }
                            if (ownerSettings.DisplayGitHubAvatar)
                            {
                                portalInfo.LogoUrl = user.AvatarUrl;
                            }
                            if (ownerSettings.DisplayGitHubDescription)
                            {
                                portalInfo.Description = user.Bio;
                            }
                            if (ownerSettings.DisplayGitHubBlogUrl)
                            {
                                portalInfo.Website = user.Blog;
                            }
                            if (ownerSettings.DisplayGitHubLocation)
                            {
                                portalInfo.Location = user.Location;
                            }
                            if (ownerSettings.DisplayGitHubIssuesLink)
                            {
                                portalInfo.GitHubHtmlUrl = user.HtmlUrl;
                            }
                        }
                    }
                    ProgressLog.Info("Looking up repository portal search buttons from settings for {0} repository.", repoId);

                    var repoSettings = await RepoSettingsStore.GetRepoSettingsAsync(ownerId, repoId);

                    var repoSearchButtons = repoSettings?.SearchButtons;
                    if (!string.IsNullOrEmpty(repoSearchButtons))
                    {
                        portalInfo.RepoSearchButtons = GetSearchButtons(repoSearchButtons);
                    }
                    return(portalInfo);
                }
                // no settings
                ProgressLog.Info("No owner settings found");
                return(null);
            }
            catch (Exception)
            {
                ProgressLog.Error("Error when attempting to retrieve portal information from owner settings");
                return(null);
            }
        }