Esempio n. 1
0
        public async Task RefreshVersionControlByIdAsync(Guid VcsId)
        {
            Vcs versionControl = await context.VcsSources.FindAsync(VcsId);

            await context.Entry(versionControl).Collection(vcs => vcs.Repositories).LoadAsync();

            context.VcsRepositories.RemoveRange(versionControl.Repositories.Where(r => r.IsIgnored == false));
            await context.SaveChangesAsync();

            var versionControlDto = new VersionControlDto {
                ApiKey = versionControl.ApiKey, Endpoint = versionControl.Endpoint, Kind = versionControl.Kind, VcsId = versionControl.Id
            };

            encryptionService.Decrypt(versionControlDto);

            IEnumerable <VcsRepository> items = await this.versionControlProvider.GetRepositoriesAsync(versionControlDto);

            foreach (VcsRepository repository in items)
            {
                context.VcsRepositories.Add(repository);
                await context.SaveChangesAsync();
            }

            foreach (var repository in context.VcsRepositories.Where(r => r.VcsId == VcsId))
            {
                await RefreshRepositoryByIdAsync(repository.Id);
            }
        }
Esempio n. 2
0
        public async Task RefreshRepositoryByIdAsync(Guid repositoryId)
        {
            VcsRepository repository = await context.VcsRepositories.FindAsync(repositoryId);

            Vcs versionControl = await context.VcsSources.FindAsync(repository.VcsId);

            logger.LogInformation($"Refreshing repository: {repository.Url}");
            await context.Entry(repository).Collection(r => r.Assets).LoadAsync();

            context.Assets.RemoveRange(repository.Assets);
            await context.SaveChangesAsync();

            var versionControlDto = new VersionControlDto {
                ApiKey = versionControl.ApiKey, Endpoint = versionControl.Endpoint, VcsId = versionControl.Id, Kind = versionControl.Kind, IsEnabled = versionControl.IsEnabled
            };
            var repositoryDto = new RepositoryDto {
                VcsId = repository.VcsId, Url = repository.Url, WebUrl = repository.WebUrl
            };

            encryptionService.Decrypt(versionControlDto);
            IEnumerable <Asset> items = await versionControlProvider.GetAssetsAsync(versionControlDto, repositoryDto);

            foreach (Asset asset in items)
            {
                context.Assets.Add(asset);
                await context.SaveChangesAsync();
                await RefreshAssetByIdAsync(asset.Id);
            }
        }
Esempio n. 3
0
        public async Task <IEnumerable <VcsRepository> > GetRepositoriesAsync(VersionControlDto versionControl)
        {
            StashClient client = new StashClient(versionControl.Endpoint, versionControl.ApiKey, usePersonalAccessTokenForAuthentication: true);

            List <VcsRepository> results = new List <VcsRepository>();

            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 repository in repositories.Values ?? Enumerable.Empty <Atlassian.Stash.Entities.Repository>())
                {
                    results.Add(new VcsRepository
                    {
                        Id     = Guid.NewGuid(),
                        VcsId  = versionControl.VcsId,
                        WebUrl = repository.Links.Self[0].Href.ToString(),
                        Url    = repository.Links.Clone[0].Href.ToString()
                    });
                }
            }

            logger.LogInformation($"Found {results.Count} repositories for {versionControl.Endpoint}");

            return(results);
        }
        public async Task <IEnumerable <Asset> > GetAssetsAsync(VersionControlDto versionControl, RepositoryDto repository)
        {
            using (var scope = logger.BeginScope($"{nameof(GetAssetsAsync)}::[{repository.Url}]"))
            {
                List <Asset> results = new List <Asset>();

                foreach (IVersionControlProvider provider in providers.Where(provider => provider.Kind == versionControl.Kind))
                {
                    try
                    {
                        IEnumerable <Asset> assets = await provider.GetAssetsAsync(versionControl, repository);

                        results.AddRange(assets);
                    }
                    catch (Exception e)
                    {
                        logger.LogError(e, $"{nameof(GetAssetsAsync)}::[{repository.Url}]::ERROR");
                    }
                }

                logger.LogInformation($"{nameof(GetAssetsAsync)}::[{repository.Url}]::RESULTS::{results.Count}");

                return(results);
            }
        }
        public async Task <IEnumerable <VcsRepository> > GetRepositoriesAsync(VersionControlDto versionControl)
        {
            List <VcsRepository> results = new List <VcsRepository>();

            foreach (IVersionControlProvider provider in providers.Where(provider => provider.Kind == versionControl.Kind))
            {
                IEnumerable <VcsRepository> repositories = await provider.GetRepositoriesAsync(versionControl);

                results.AddRange(repositories);
            }

            logger.LogInformation($"{nameof(GetRepositoriesAsync)}::[{versionControl.Endpoint}]::RESULTS::{results.Count}");

            return(results);
        }
Esempio n. 6
0
        public async Task <VersionControlDto> CreateVersionControl(VersionControlDto dto)
        {
            encryptionService.Encrypt(dto);

            Vcs vcs = new Vcs
            {
                Id        = Guid.NewGuid(),
                ApiKey    = dto.ApiKey,
                Endpoint  = dto.Endpoint,
                Kind      = dto.Kind,
                IsEnabled = dto.IsEnabled
            };

            context.VcsSources.Add(vcs);
            await context.SaveChangesAsync();

            return(new VersionControlDto {
                Endpoint = vcs.Endpoint, ApiKey = vcs.ApiKey, Kind = vcs.Kind, VcsId = vcs.Id
            });
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public async Task <VersionControlDto> UpdateAsync(VersionControlDto dto)
        {
            encryptionService.Encrypt(dto);

            Vcs versionControl = context.VcsSources.Find(dto.VcsId);

            versionControl.Endpoint  = dto.Endpoint;
            versionControl.Kind      = dto.Kind;
            versionControl.IsEnabled = dto.IsEnabled;
            versionControl.ApiKey    = dto.ApiKey;

            context.VcsSources.Update(versionControl);
            await context.SaveChangesAsync();

            return(new VersionControlDto
            {
                Endpoint = versionControl.Endpoint,
                ApiKey = versionControl.ApiKey,
                Kind = versionControl.Kind,
                VcsId = versionControl.Id,
                Repositories = context.VcsRepositories.Count(x => x.VcsId == versionControl.Id)
            });
        }
Esempio n. 9
0
 public void Encrypt(VersionControlDto versionControl)
 {
     versionControl.ApiKey = Encrypt(versionControl.ApiKey);
 }
Esempio n. 10
0
 public async Task <IEnumerable <VcsRepository> > GetRepositoriesAsync(VersionControlDto source)
 {
     return(await Task.FromResult(Enumerable.Empty <VcsRepository>()));
 }
Esempio n. 11
0
 public async Task <IEnumerable <Asset> > GetAssetsAsync(VersionControlDto versionControl, RepositoryDto repository)
 {
     return(await Task.FromResult(Enumerable.Empty <Asset>()));
 }