Beispiel #1
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);
            }
        }
Beispiel #2
0
        public async Task<IPaginatedList<DependencyDto>> GetByRepositoryIdAsync(Guid repoId, IEnumerable<EcosystemKind> kinds, string search, int pageIndex = 1, int pageSize = 10)
        {
            var filter = kinds.ToIntArray();
            VcsRepository repository = context.VcsRepositories.Find(repoId);
            List<string> assetNames = context.Assets.Where(asset => asset.RepositoryId == repoId).Select(asset => extractor.ExtractPublishName(asset)).ToList();

            IQueryable<Dependency> query = context.Dependencies.AsQueryable();

            if (filter.Any())
            {
                query = query.Where(dependency => filter.Contains((int)dependency.Kind));
            }

            if (!string.IsNullOrWhiteSpace(search))
            {
                query = query.Where(dependency => dependency.Name.Contains(search));
            }

            query = query.Where(dependency => assetNames.Contains(dependency.Name) || context.DependencyVersions.Any(dv => dv.DependencyId == dependency.Id && string.Equals(dv.ProjectUrl, repository.Url) || string.Equals(dv.ProjectUrl, repository.WebUrl)));

            var paging = query.Select(dependency => new DependencyDto
            {
                Assets = context.AssetDependencies.Count(ad => ad.DependencyId == dependency.Id),
                DependencyId = dependency.Id,
                Kind = dependency.Kind,
                Name = dependency.Name,
                Versions = context.DependencyVersions.Count(dv => dv.DependencyId == dependency.Id)
            })
            .OrderByDescending(d => d.Assets)
            .ThenByDescending(d => d.Versions);

            return await PaginatedList<DependencyDto>.CreateAsync(paging, pageIndex, pageSize);
        }
Beispiel #3
0
        public async Task <RepositoryDto> ToggleIgnoreAsync(Guid repoId)
        {
            VcsRepository repository = await context.VcsRepositories.FindAsync(repoId);

            repository.IsIgnored = !repository.IsIgnored;
            await context.SaveChangesAsync();

            if (repository.IsIgnored)
            {
                context.RemoveRange(context.Assets.Where(asset => asset.RepositoryId == repoId));
            }
            else
            {
                context.Tasks.Add(new RefreshTask {
                    Scope = TaskScopeKind.Repository, TargetId = repoId
                });
            }

            await context.SaveChangesAsync();

            return(new RepositoryDto
            {
                VcsId = repository.VcsId,
                Assets = context.Assets.Count(asset => asset.RepositoryId == repoId),
                Url = repository.Url,
                WebUrl = repository.WebUrl,
                RepositoryId = repository.Id,
                IsIgnored = repository.IsIgnored
            });
        }
Beispiel #4
0
        public async Task <RepositoryDto> GetByIdAsync(Guid repoId)
        {
            VcsRepository repository = await context.VcsRepositories.FindAsync(repoId);

            return(new RepositoryDto
            {
                VcsId = repository.VcsId,
                Assets = context.Assets.Count(asset => asset.RepositoryId == repoId),
                Url = repository.Url,
                WebUrl = repository.WebUrl,
                RepositoryId = repository.Id,
                IsIgnored = repository.IsIgnored
            });
        }