-
Notifications
You must be signed in to change notification settings - Fork 203
/
cpan.rb
70 lines (61 loc) · 2.53 KB
/
cpan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true
module PackageManager
class CPAN < Base
HAS_VERSIONS = true
HAS_DEPENDENCIES = true
URL = "https://metacpan.org"
COLOR = "#0298c3"
def self.package_link(db_project, _version = nil)
"https://metacpan.org/release/#{db_project.name}"
end
def self.project_names
page = 1
projects = []
loop do
r = get("https://fastapi.metacpan.org/v1/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=5000&from=#{page * 5000}")["hits"]["hits"]
break if r == []
projects += r
page += 1
end
projects.map { |project| project["fields"]["distribution"] }.uniq
end
def self.recent_names
names = get("https://fastapi.metacpan.org/v1/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=100")["hits"]["hits"]
names.map { |project| project["fields"]["distribution"] }.uniq
end
def self.project(name)
get("https://fastapi.metacpan.org/v1/release/#{name}")
end
def self.mapping(raw_project)
MappingBuilder.build_hash(
name: raw_project["distribution"],
homepage: raw_project.fetch("resources", {})["homepage"],
description: raw_project["abstract"],
licenses: raw_project.fetch("license", []).join(","),
repository_url: repo_fallback(raw_project.fetch("resources", {}).fetch("repository", {})["web"], raw_project.fetch("resources", {})["homepage"]),
versions: versions(raw_project, raw_project["distribution"])
)
end
def self.versions(raw_project, _name)
versions = get("https://fastapi.metacpan.org/v1/release/_search?q=distribution:#{raw_project['distribution']}&size=5000&_source=version,date")["hits"]["hits"]
versions.map do |version|
VersionBuilder.build_hash(
number: version["_source"]["version"],
published_at: version["_source"]["date"]
)
end
end
def self.dependencies(_name, version, mapped_project)
versions = get("https://fastapi.metacpan.org/v1/release/_search?q=distribution:#{mapped_project[:name]}&size=5000&_source=version,dependency")["hits"]["hits"]
version_data = versions.find { |v| v["_source"]["version"] == version }
version_data["_source"]["dependency"].select { |dep| dep["relationship"] == "requires" }.map do |dep|
{
project_name: dep["module"].gsub("::", "-"),
requirements: dep["version"],
kind: dep["phase"],
platform: name.demodulize,
}
end
end
end
end