Class: GithubTag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/github_tag.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object


61
62
63
64
65
66
67
# File 'app/models/github_tag.rb', line 61

def <=>(other)
  if parsed_number.is_a?(String) || other.parsed_number.is_a?(String)
    other.number <=> number
  else
    other.parsed_number <=> parsed_number
  end
end

#follows_semver?Boolean


93
94
95
# File 'app/models/github_tag.rb', line 93

def follows_semver?
  valid_number?
end

#github_urlObject


101
102
103
# File 'app/models/github_tag.rb', line 101

def github_url
  "#{github_repository.url}/releases/tag/#{name}"
end

#has_projects?Boolean


38
39
40
# File 'app/models/github_tag.rb', line 38

def has_projects?
  github_repository && github_repository.projects.without_versions.length > 0
end

#notify_firehoseObject


55
56
57
58
59
# File 'app/models/github_tag.rb', line 55

def notify_firehose
  github_repository.projects.without_versions.each do |project|
    Firehose.new_version(project, project.platform, self)
  end
end

#notify_subscribersObject


42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/github_tag.rb', line 42

def notify_subscribers
  github_repository.projects.without_versions.each do |project|
    subscriptions = project.subscriptions
    subscriptions = subscriptions.include_prereleases if prerelease?

    subscriptions.group_by(&:notification_user).each do |user, subscriptions|
      next if user.nil?
      next if user.muted?(project)
      VersionsMailer.new_version(user, project, self).deliver_later
    end
  end
end

#notify_web_hooksObject


26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/github_tag.rb', line 26

def notify_web_hooks
  github_repository.projects.without_versions.each do |project|
    repos = project.subscriptions.map(&:github_repository).compact.uniq
    repos.each do |repo|
      requirements = repo.repository_dependencies.select{|rd| rd.project == project }.map(&:requirements)
      repo.web_hooks.each do |web_hook|
        web_hook.send_new_version(project, project.platform, self, requirements)
      end
    end
  end
end

#numberObject


97
98
99
# File 'app/models/github_tag.rb', line 97

def number
  name
end

#parsed_numberObject


69
70
71
# File 'app/models/github_tag.rb', line 69

def parsed_number
  semantic_version || number
end

#prerelease?Boolean


85
86
87
# File 'app/models/github_tag.rb', line 85

def prerelease?
  !!parsed_number.try(:pre)
end

#semantic_versionObject


73
74
75
76
77
78
79
# File 'app/models/github_tag.rb', line 73

def semantic_version
  @semantic_version ||= begin
    Semantic::Version.new(number)
  rescue ArgumentError
    nil
  end
end

#send_notificationsObject


18
19
20
21
22
23
24
# File 'app/models/github_tag.rb', line 18

def send_notifications
  if has_projects?
    notify_subscribers
    notify_firehose
    notify_web_hooks
  end
end

#send_notifications_asyncObject


13
14
15
16
# File 'app/models/github_tag.rb', line 13

def send_notifications_async
  return if published_at && published_at < 1.week.ago
  TagNotificationsWorker.perform_async(self.id) if has_projects?
end

#stable?Boolean


81
82
83
# File 'app/models/github_tag.rb', line 81

def stable?
  !prerelease?
end

#to_sObject


9
10
11
# File 'app/models/github_tag.rb', line 9

def to_s
  name
end

#valid_number?Boolean


89
90
91
# File 'app/models/github_tag.rb', line 89

def valid_number?
  !!semantic_version
end