aboutsummaryrefslogtreecommitdiff
blob: 7187f7d380d23d289d79f5285d7f98944837234b (plain)
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
99
100
101
102
require 'open-uri'

# Helpers for displaying package models
module PackagesHelper
  def restrict_label(version)
    abbreviated_label version.restrict,
                      'badge-danger kk-restrict-label',
                      :restrict_tooltip
  end

  def properties_label(version)
    abbreviated_label version.properties,
                      'badge-info kk-properties-label',
                      :properties_tooltip
  end

  def version_labels(version)
    capture do
      concat restrict_label(version)
      concat properties_label(version)
    end
  end

  def annotate_license_str(str)
    str.split(/\s/).map do |license|
      if license[0] =~ /[[:alpha:]]/ && !license.end_with?('?')
        link_to_license_text license
      else
        h license
      end
    end.join(' ').html_safe
  end

	# This parses commit messages for GLEP66 style bug annotations.
	# Bug: https://bugs.gentoo.org/NNNNNN
	# Closes: https://bugs.gentoo.org/NNNNNN
	#def glep66_bugs(commit_msg)
	#	bugs_list = []
	#	commit_msg.each_line do |line| {
	#		bugno = line[/(Bug\:|Closes\:)\s+https:\/\/bugs\.gentoo\.org\/(\d+)/, 1]
	#		bugs_list << "https://bugs.gentoo.org/#{bugno}" if !bugno.nil?
	#	}
	#	bugs_list
	#end

  def annotate_bugs(str)
    annotated_str = (h str).gsub(/([bB]ug\s+|[bB]ug\s+#|#)(\d+)/) do
      link_to_bug("#{$1}#{$2}", $2)
    end

    sanitize(annotated_str, tags: ['a'], attributes: ['href'])
  end

  # Filters duplicate masks
  def filter_masks(versions)
    masks = {}

    versions.each do |version|
      version.masks.each do |mask|
        masks[mask['reason']] = mask
      end
    end

    masks.values
  end

  def version_slot(slot, subslot = nil)
    title = "subslot #{subslot}" if subslot && !subslot.empty?

    content_tag :span,
                sanitize('&#x2008;:&#x2008;%s' % slot),
                class: 'kk-slot',
                title: title
  end

  # Returns a list of members belonging to a project
  def project_members(project)
    Portage::Util::Projects.cached_instance.inherited_members(project)
  end

  # Tries to find a matching changelog entry for a change object
  def matching_changelog_entry(change)
    changelog = Rails.cache.fetch("changelog/#{cp_to_atom(change.category, change.package)}", expires_in: 10.minutes) do
      CommitRepository.find_sorted_by('packages', change.category + '/' + change.package, 'date', 'desc', 5)
    end

    changelog.each do |changelog_entry|
      if changelog_entry.files['added'].include?('%s/%s/%s-%s.ebuild' % [change.category, change.package, change.package, change.version])
        return changelog_entry
      end
    end

    nil
  end

  # rubocop:disable Security/Open
  def documentation_label(package)
    doc = Nokogiri::XML(open('https://wiki.gentoo.org/api.php?action=query&titles=' + package + '&format=xml'))
    doc.xpath('//api/query/pages/page')[0].attr('missing').nil? ? (t :res_docs) : (t :res_search_docs)
  end
  # rubocop:enable Security/Open
end