Module: Capistrano::Committed

Defined in:
lib/capistrano/committed.rb,
lib/capistrano/committed/output.rb,
lib/capistrano/committed/version.rb,
lib/capistrano/committed/github_api.rb

Defined Under Namespace

Classes: GithubApi, Output

Constant Summary collapse

VERSION =
'0.0.13'
@@settings =
{}

Class Method Summary collapse

Class Method Details

.add_buffer_to_time(time, buffer_in_days = nil) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/capistrano/committed.rb', line 98

def add_buffer_to_time(time, buffer_in_days = nil)
  check_type __callee__, 'time', time.is_a?(Time)

  buffer_in_days = get_setting(:commit_buffer, buffer_in_days)
  check_type __callee__, 'buffer_in_days', buffer_in_days.is_a?(Numeric)

  (time - days_to_seconds(buffer_in_days)).iso8601
end

.add_dates_to_revisions(revisions, github, git_user = nil, git_repo = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/capistrano/committed.rb', line 63

def add_dates_to_revisions(revisions, github, git_user = nil, git_repo = nil)
  check_type __callee__, 'revisions', revisions.is_a?(Hash)
  check_type __callee__, 'github', github.is_a?(Capistrano::Committed::GithubApi)

  git_user = get_setting(:user, git_user)
  check_type __callee__, 'git_user', git_user.is_a?(String)

  git_repo = get_setting(:repo, git_repo)
  check_type __callee__, 'git_repo', git_repo.is_a?(String)

  revisions.each do |release, revision|
    next if release == :next || release == :previous
    commit = github.get_commit(git_user,
                               git_repo,
                               revision[:sha])

    unless commit.nil?
      revisions[release][:date] = commit[:commit][:committer][:date]
    end
  end
  revisions
end

.days_to_seconds(days) ⇒ Object



92
93
94
95
96
# File 'lib/capistrano/committed.rb', line 92

def days_to_seconds(days)
  check_type __callee__, 'days', days.is_a?(Numeric)

  days * 24 * 60 * 60
end

.get_earliest_date_from_revisions(revisions) ⇒ Object



86
87
88
89
90
# File 'lib/capistrano/committed.rb', line 86

def get_earliest_date_from_revisions(revisions)
  check_type __callee__, 'revisions', revisions.is_a?(Hash)

  revisions.values.map{ |r| Time.parse(r[:date]) unless r[:date].nil? }.compact.min
end

.get_issue_urls(message, issue_match = nil, issue_postprocess = nil, issue_url = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/capistrano/committed.rb', line 107

def get_issue_urls(message, issue_match = nil, issue_postprocess = nil, issue_url = nil)
  check_type __callee__, 'message', message.is_a?(String)

  issue_match = get_setting(:issue_match, issue_match)
  check_type __callee__,
             'issue_match',
             (issue_match.is_a?(String) || issue_match.is_a?(Regexp))

  issue_postprocess = get_setting(:issue_postprocess, issue_postprocess)
  check_type __callee__, 'issue_postprocess', issue_postprocess.is_a?(Array)
  issue_postprocess.each { |method|
    check_type __callee__,
               format('issue_postprocess[:%s]', method.to_s),
               method.is_a?(Symbol)
  }

  issue_url = get_setting(:issue_url, issue_url)
  check_type __callee__, 'issue_url', issue_url.is_a?(String)

  matches = message.scan(Regexp.new(issue_match))
  return [] unless matches
  matches.map! { |match|
    issue = match[0]
    issue_postprocess.each { |method|
      issue = issue.send(method)
    }
    format(issue_url, issue)
  }
  matches.uniq
end

.get_revisions_from_lines(lines, search = nil, branch = nil, limit = nil) ⇒ Object



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
# File 'lib/capistrano/committed.rb', line 28

def get_revisions_from_lines(lines, search = nil, branch = nil, limit = nil)
  check_type __callee__, 'lines', lines.is_a?(Array)
  lines.each_with_index { |line, index|
    check_type __callee__,
               format('lines[%d]', index),
               line.is_a?(String)
  }

  search = revision_search_regex if search.nil?
  check_type __callee__, 'search', search.is_a?(Regexp)

  branch = get_setting(:branch, branch)
  check_type __callee__, 'branch', (branch.is_a?(Symbol) || branch.is_a?(String))

  limit = get_setting(:revision_limit, limit)
  check_type __callee__, 'limit', limit.is_a?(Integer)

  revisions = {}
  lines.each do |line|
    matches = search.match(line)
    next if matches.nil?
    next unless matches[:branch].to_s == branch.to_s
    revisions[matches[:release]] = {
      branch:   matches[:branch],
      sha:      matches[:sha],
      release:  matches[:release],
      user:     matches[:user],
      entries:  {}
    }
    # Only store a certain number of revisions
    break if revisions.count == limit
  end
  pad_revisions(revisions)
end

.get_setting(setting, variable = nil) ⇒ Object



15
16
17
# File 'lib/capistrano/committed.rb', line 15

def get_setting(setting, variable = nil)
   variable.nil? ? @@settings[setting] : variable
end

.import_settings(settings, merge = nil) ⇒ Object



11
12
13
# File 'lib/capistrano/committed.rb', line 11

def import_settings(settings, merge = nil)
  merge.nil? ? @@settings = settings : @@settings.merge!(settings)
end

.revision_search_regex(revision_line = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/capistrano/committed.rb', line 19

def revision_search_regex(revision_line = nil)
  revision_line = get_setting(:revision_line, revision_line)
  check_type __callee__, 'revision_line', revision_line.is_a?(String)

  search = Regexp.escape(revision_line)
  search = search.gsub('%\{', '(?<').gsub('\}', '>.+)')
  Regexp.new(search)
end