-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathelpa.rb
86 lines (75 loc) · 2.18 KB
/
elpa.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
# frozen_string_literal: true
module Ecosystem
class Elpa < Base
def self.purl_type
'melpa'
end
def registry_url(package, version = nil)
"#{@registry_url}/#{package.name}.html"
end
def download_url(package, version)
return nil unless version.present?
"#{@registry_url}/#{package.name}-#{version}.tar"
end
def install_command(package, version = nil)
"M-x package-install RET #{package.name} RET"
end
def all_package_names
get_html("#{@registry_url}").css('table td a:first').map(&:text)
rescue
[]
end
def recently_updated_package_names
all_package_names
end
def fetch_package_metadata(name)
page = get_html("#{@registry_url}/#{name}.html", headers: { "Accept" => "text/html" })
{
name: name,
page: page
}
rescue
{}
end
def extract_fields(page)
keys = page.css('dl').first.css('dt').map(&:text)
values = page.css('dl').first.css('dd').map(&:text)
Hash[keys.zip(values)]
end
def map_package_metadata(package)
return nil if package[:page].blank?
fields = extract_fields(package[:page])
{
name: package[:name],
description: fields["Description"],
homepage: fields["Home page"],
repository_url: repo_fallback(fields["Home page"], ''),
page: package[:page]
}
rescue
nil
end
def versions_metadata(pkg_metadata, existing_version_numbers = [])
fields = extract_fields(pkg_metadata[:page])
filename = fields['Latest'].split(',')[0]
date = fields['Latest'].split(', ')[1]
version = filename.gsub("#{pkg_metadata[:name]}-",'').gsub('.tar','')
[{ number: version, published_at: date }]
end
def maintainers_metadata(name)
page = get_html("#{@registry_url}/#{name}.html", headers: { "Accept" => "text/html" })
fields = extract_fields(page)
fields['Maintainer'].split(', ').map do |string|
name, email = string.split(' <')
email = email.gsub('>','')
{
uuid: email,
name: name,
email: email
}
end
rescue StandardError
[]
end
end
end