-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathhex.rb
98 lines (84 loc) · 2.66 KB
/
hex.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true
module PackageManager
class Hex < Base
HAS_VERSIONS = true
HAS_DEPENDENCIES = true
HAS_OWNERS = true
URL = "https://hex.pm"
COLOR = "#6e4a7e"
def self.package_link(db_project, version = nil)
"https://hex.pm/packages/#{db_project.name}/#{version}"
end
def self.download_url(db_project, version = nil)
"https://repo.hex.pm/tarballs/#{db_project.name}-#{version}.tar"
end
def self.documentation_url(name, version = nil)
"http://hexdocs.pm/#{name}/#{version}"
end
def self.project_names
page = 1
projects = []
while page < 1000
r = get("https://hex.pm/api/packages?page=#{page}")
break if r == []
projects += r
page += 1
end
projects.map { |project| project["name"] }
end
def self.recent_names
(get("https://hex.pm/api/packages?sort=inserted_at").map { |project| project["name"] } +
get("https://hex.pm/api/packages?sort=updated_at").map { |project| project["name"] }).uniq
end
def self.project(name)
sleep 30
get("https://hex.pm/api/packages/#{name}")
end
def self.mapping(raw_project)
links = raw_project["meta"].fetch("links", {}).transform_keys(&:downcase)
MappingBuilder.build_hash(
name: raw_project["name"],
homepage: links.except("github").first.try(:last),
repository_url: links["github"],
description: raw_project["meta"]["description"],
licenses: repo_fallback(raw_project["meta"].fetch("licenses", []).join(","), links.except("github").first.try(:last))
)
end
def self.versions(raw_project, _name)
raw_project["releases"].map do |version|
VersionBuilder.build_hash(
number: version["version"],
published_at: version["inserted_at"]
)
end
end
def self.dependencies(name, version, _mapped_project)
deps = get("https://hex.pm/api/packages/#{name}/releases/#{version}")["requirements"]
return [] if deps.nil?
deps.map do |k, v|
{
project_name: k,
requirements: v["requirement"],
kind: "runtime",
optional: v["optional"],
platform: self.name.demodulize,
}
end
end
def self.download_registry_users(name)
json = get_json("https://hex.pm/api/packages/#{name}")
json["owners"].map do |user|
{
uuid: "hex-#{user['username']}",
email: user["email"],
login: user["username"],
}
end
rescue StandardError
[]
end
def self.registry_user_url(login)
"https://hex.pm/users/#{login}"
end
end
end