예제 #1
0
        public void PublishWithTemplateInvokesHtmlFileGenerator()
        {
            var portalInfo = new PortalInfoDrop {
                OwnerId = "git-user", RepositoryName = "repo-id", OwnerDisplayName = "Git User"
            };
            var templateVariables =
                new Dictionary <string, object>
            {
                { "ownerId", portalInfo?.OwnerId },
                { "repoName", portalInfo?.RepositoryName },
                { "portalInfo", portalInfo },
            };

            Repo.Publish(null, templateVariables);
            MockHtmlFileGenerator.Verify(
                x => x.HandleResource(
                    It.Is <INode>(n => (n as IUriNode).Uri.Equals(_publishedSubject)),
                    It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >()),
                Times.Once);
        }
예제 #2
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);
            }
        }