Class: CronForGithub::Ping
- Inherits:
-
Object
- Object
- CronForGithub::Ping
- Defined in:
- lib/cron_for_github/ping.rb
Constant Summary collapse
- NAMESPACE =
'cron_for_github'
- BASE =
'master'
- RESERVED_REFS =
%w( tags gh-pages master branches trunk feature develop release hotfix )
Instance Method Summary collapse
- #clear(params) ⇒ Object
- #decide_cron_ref(text, caller = nil) ⇒ Object
- #decide_cron_ref_prefix(text, caller = nil) ⇒ Object
- #decide_head_ref(text) ⇒ Object
- #decide_slug(text) ⇒ Object
- #logger ⇒ Object
- #ping(params) ⇒ Object
Instance Method Details
#clear(params) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cron_for_github/ping.rb', line 40 def clear(params) client = Client.new slug = decide_slug(params[:slug]) cron_ref_prefix = decide_cron_ref_prefix(params[:namespace]) cron_refs = client.refs(slug, cron_ref_prefix) cron_refs .each do |clear_ref| client.delete_ref(slug, clear_ref) end end |
#decide_cron_ref(text, caller = nil) ⇒ Object
36 37 38 |
# File 'lib/cron_for_github/ping.rb', line 36 def decide_cron_ref(text, caller = nil) "#{decide_cron_ref_prefix(text, caller)}#{SecureRandom.uuid}" end |
#decide_cron_ref_prefix(text, caller = nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/cron_for_github/ping.rb', line 52 def decide_cron_ref_prefix(text, caller = nil) if caller != :ping && RESERVED_REFS.include?(text) fail ReservedNamespaceError, \ %("#{text}" is reserved. List: #{RESERVED_REFS.join(', ')}) end text = NAMESPACE if !text || text.empty? "heads/#{text}/" end |
#decide_head_ref(text) ⇒ Object
31 32 33 34 |
# File 'lib/cron_for_github/ping.rb', line 31 def decide_head_ref(text) text = BASE if !text || text.empty? "heads/#{text}" end |
#decide_slug(text) ⇒ Object
27 28 29 |
# File 'lib/cron_for_github/ping.rb', line 27 def decide_slug(text) text end |
#logger ⇒ Object
61 62 63 |
# File 'lib/cron_for_github/ping.rb', line 61 def logger ::CronForGithub.logger end |
#ping(params) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/cron_for_github/ping.rb', line 17 def ping(params) client = Client.new slug = decide_slug(params[:slug]) head_ref = decide_head_ref(params[:base]) cron_ref = decide_cron_ref(params[:namespace], __method__) latest_sha = client.latest_sha(slug, head_ref) client.create_ref(slug, cron_ref, latest_sha) end |