コード例 #1
0
 private string GetTemplateOwner(Template template) {
     string owner;
     string name;
     if (ParseUtils.ParseGitHubRepoOwnerAndName(template.RemoteUrl, out owner, out name)) {
         return owner;
     } else {
         return null;
     }
 }
コード例 #2
0
ファイル: GitHubTemplateSource.cs プロジェクト: zooba/PTVS
        public async Task<TemplateEnumerationResult> GetTemplatesAsync(string filter, string continuationToken, CancellationToken cancellationToken) {
            var terms = new List<string>();
            terms.Add("cookiecutter");

            var keywords = SearchUtils.ParseKeywords(filter);
            if (keywords != null && keywords.Length > 0) {
                terms.AddRange(keywords);
            }

            var templates = new List<Template>();

            try {
                GitHubRepoSearchResult result;
                if (continuationToken == null) {
                    result = await _client.StartSearchRepositoriesAsync(terms.ToArray());
                } else {
                    result = await _client.SearchRepositoriesAsync(continuationToken);
                }

                foreach (var repo in result.Items) {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (await _client.FileExistsAsync(repo, TemplateDefinitionFileName)) {
                        var template = new Template();
                        template.RemoteUrl = repo.HtmlUrl;
                        template.Name = repo.FullName;
                        template.Description = repo.Description;
                        template.AvatarUrl = repo.Owner.AvatarUrl;
                        template.OwnerUrl = repo.Owner.HtmlUrl;
                        templates.Add(template);
                    }
                }

                return new TemplateEnumerationResult(templates, result.Links.Next);
            } catch (WebException ex) {
                throw new TemplateEnumerationException(Strings.GitHubSearchError, ex);
            }
        }
コード例 #3
0
ファイル: LocalTemplateSource.cs プロジェクト: zooba/PTVS
 private async Task InitializeRemoteAsync(Template template) {
     var origin = await _gitClient.GetRemoteOriginAsync(template.LocalFolderPath);
     if (origin != null) {
         template.RemoteUrl = origin;
     }
 }
コード例 #4
0
ファイル: LocalTemplateSource.cs プロジェクト: zooba/PTVS
        private async Task AddFolderToCache(string repoPath) {
            var template = new Template() {
                LocalFolderPath = repoPath,
                Name = PathUtils.GetFileOrDirectoryName(repoPath),
            };

            await InitializeRemoteAsync(template);

            _cache.Add(template);
        }
コード例 #5
0
        public async Task LoadLocalFeed() {
            ITemplateSource source = new FeedTemplateSource(new Uri(LocalFeedPath));
            Assert.IsTrue(File.Exists(LocalFeedPath));

            var result = await source.GetTemplatesAsync(null, null, CancellationToken.None);

            Assert.IsNull(result.ContinuationToken);
            Assert.AreEqual(6, result.Templates.Count);

            var expected = new Template[] {
                new Template() {
                    RemoteUrl = "https://github.com/brettcannon/python-azure-web-app-cookiecutter",
                    Name = "brettcannon/python-azure-web-app-cookiecutter",
                },
                new Template() {
                    RemoteUrl = "https://github.com/pydanny/cookiecutter-django",
                    Name = "pydanny/cookiecutter-django",
                },
                new Template() {
                    RemoteUrl = "https://github.com/sloria/cookiecutter-flask",
                    Name = "sloria/cookiecutter-flask",
                },
                new Template() {
                    RemoteUrl = "https://github.com/pydanny/cookiecutter-djangopackage",
                    Name = "pydanny/cookiecutter-djangopackage",
                },
                new Template() {
                    RemoteUrl = "https://github.com/marcofucci/cookiecutter-simple-django",
                    Name = "marcofucci/cookiecutter-simple-django",
                },
                new Template() {
                    RemoteUrl = "https://github.com/agconti/cookiecutter-django-rest",
                    Name = "agconti/cookiecutter-django-rest",
                },
            };

            CollectionAssert.AreEqual(expected, result.Templates.ToArray(), new TemplateComparer());
        }
コード例 #6
0
ファイル: SearchUtils.cs プロジェクト: jsschultz/PTVS
 internal static bool SearchMatches(string[] keywords, Template template) {
     return SearchMatches(keywords, template.Name) || SearchMatches(keywords, template.Description);
 }