Пример #1
0
        public async Task <Dictionary <PackageURL, double> > FindSource(PackageURL purl)
        {
            Logger.Trace("FindSource({0})", purl);

            var repositoryMap = new Dictionary <PackageURL, double>();

            if (purl == null)
            {
                Logger.Warn("FindSource was passed an invalid purl.");
                return(repositoryMap);
            }

            var purlNoVersion = new PackageURL(purl.Type, purl.Namespace, purl.Name,
                                               null, purl.Qualifiers, purl.Subpath);

            Logger.Debug("Searching for source code for {0}", purlNoVersion.ToString());

            try
            {
                RepoSearch repoSearcher = new RepoSearch();
                var        repos        = await(repoSearcher.ResolvePackageLibraryAsync(purl) ??
                                                Task.FromResult(new Dictionary <PackageURL, double>()));
                if (repos.Any())
                {
                    foreach (var key in repos.Keys)
                    {
                        repositoryMap[key] = repos[key];
                    }
                    Logger.Debug("Identified {0} repositories.", repos.Count);
                }
                else
                {
                    Logger.Warn("No repositories found for package {0}", purl);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex, "Error identifying source repository for {0}: {1}", purl, ex.Message);
            }

            return(repositoryMap);
        }
Пример #2
0
        public async Task FindSource(PackageURL purl)
        {
            var purlNoVersion = new PackageURL(purl.Type, purl.Namespace, purl.Name,
                                               null, purl.Qualifiers, purl.Subpath);

            Logger.Debug("Searching for source code for {0}", purlNoVersion.ToString());

            RepoSearch repoSearcher = new RepoSearch();
            Dictionary <PackageURL, float> repos = await repoSearcher.ResolvePackageLibraryAsync(purl);

            if (repos.Count > 0)
            {
                foreach (KeyValuePair <PackageURL, float> item in repos)
                {
                    var githubUrl = $"https://github.com/{item.Key.Namespace}/{item.Key.Name}";
                    Logger.Info("Found: {0} ({1}). Probability Score: {2}", item.Key.ToString(), githubUrl, item.Value);
                }
            }
            else
            {
                Logger.Warn("Could not find repository for package {0}", purl.ToString());
            }
        }
Пример #3
0
        public async Task <HealthMetrics?> CheckHealth(PackageURL purl)
        {
            BaseProjectManager?packageManager = ProjectManagerFactory.CreateProjectManager(purl);

            if (packageManager != null)
            {
                string?content = await packageManager.GetMetadataAsync(purl);

                if (!string.IsNullOrWhiteSpace(content))
                {
                    RepoSearch repoSearcher = new RepoSearch(ProjectManagerFactory);
                    foreach ((PackageURL githubPurl, double _) in await repoSearcher.ResolvePackageLibraryAsync(purl))
                    {
                        try
                        {
                            GitHubHealthAlgorithm?healthAlgorithm = new GitHubHealthAlgorithm(githubPurl);
                            HealthMetrics?        health          = await healthAlgorithm.GetHealth();

                            return(health);
                        }
                        catch (Exception ex)
                        {
                            Logger.Warn(ex, "Unable to calculate health for {0}: {1}", githubPurl, ex.Message);
                        }
                    }
                }
                else
                {
                    Logger.Warn("No metadata found for {0}", purl.ToString());
                }
            }
            else
            {
                throw new ArgumentException($"Invalid Package URL type: {purl.Type}");
            }
            return(null);
        }