Beispiel #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;
     }
 }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
 private async Task InitializeRemoteAsync(Template template) {
     var origin = await _gitClient.GetRemoteOriginAsync(template.LocalFolderPath);
     if (origin != null) {
         template.RemoteUrl = origin;
     }
 }
Beispiel #4
0
        private async Task AddFolderToCache(string repoPath) {
            var template = new Template() {
                LocalFolderPath = repoPath,
                Name = PathUtils.GetFileOrDirectoryName(repoPath),
            };

            await InitializeRemoteAsync(template);

            _cache.Add(template);
        }
        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());
        }
Beispiel #6
0
 internal static bool SearchMatches(string[] keywords, Template template) {
     return SearchMatches(keywords, template.Name) || SearchMatches(keywords, template.Description);
 }