Example #1
0
 public void MatcherTests(string one, string two, bool match)
 {
     Assert.Equal(expected: match, actual: repositoryMatcher.IsMatch(one, two));
 }
Example #2
0
        public async Task <IEnumerable <Asset> > GetAssetsAsync(VersionControlDto versionControl, RepositoryDto repository)
        {
            List <Asset> results = new List <Asset>();
            StashClient  client  = new StashClient(versionControl.Endpoint, versionControl.ApiKey, usePersonalAccessTokenForAuthentication: true);

            ResponseWrapper <Project> projects = await client.Projects.Get();

            foreach (Project project in projects.Values ?? Enumerable.Empty <Project>())
            {
                ResponseWrapper <Repository> repositories = await client.Repositories.Get(project.Key, Options);

                foreach (Repository bitBucketRepository in repositories.Values ?? Enumerable.Empty <Repository>())
                {
                    bool isRepositoryFound = bitBucketRepository.Links.Clone.Select(c => c.Href).Concat(bitBucketRepository.Links.Self.Select(s => s.Href)).Any(link => matcher.IsMatch(link.ToString(), repository.Url));

                    if (isRepositoryFound)
                    {
                        ResponseWrapper <string> filePaths = await client.Repositories.GetFiles(project.Key, bitBucketRepository.Slug, Options);

                        foreach (string path in filePaths.Values ?? Enumerable.Empty <string>())
                        {
                            if (path.IsSupported())
                            {
                                File file = await client.Repositories.GetFileContents(project.Key, bitBucketRepository.Slug, path, new FileContentsOptions { Content = true, Limit = 10000 });

                                logger.LogInformation($"Adding '{path}' for repository {repository.RepositoryId}");

                                results.Add(new Asset {
                                    Id = Guid.NewGuid(), RepositoryId = repository.RepositoryId, Kind = path.GetEcosystemKind(), Path = path, Raw = string.Join(Environment.NewLine, file.FileContents)
                                });
                            }
                        }
                    }
                }
            }

            return(results);
        }