Class: Stenographer::Inputs::GithubInput

Inherits:
Object
  • Object
show all
Includes:
BaseInput
Defined in:
lib/stenographer/inputs/github_input.rb

Constant Summary collapse

GRAMMAR =
File.join(Stenographer::Engine.root, 'lib/stenographer/commit_message_parser')
COMMIT_MESSAGE_PARSER =
Citrus.load(GRAMMAR).first

Instance Method Summary collapse

Instance Method Details

#parse(params) ⇒ Object



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
# File 'lib/stenographer/inputs/github_input.rb', line 13

def parse(params)
  changes = []
  notification = JSON.parse(params[:payload], symbolize_names: true)
  commits = notification[:commits]

  return changes if commits.blank?

  branch = notification[:ref].split('/').last

  if tracked_branch?(branch)
    commits.each do |commit|
      message = commit_message(commit)
      source_id = commit_id(commit)
      subject = message.lines.first.strip
      changelog_message = parse_changelog_message(message)
      tracker_ids = parse_tracker_ids(message)

      next if Stenographer.use_changelog && changelog_message.blank?

      displayed_message = if Stenographer.use_changelog
                            changelog_message
                          elsif changelog_message.present?
                            changelog_message
                          else
                            subject
                          end

      changes << {
        subject: subject,
        message: displayed_message,
        source_id: source_id,
        visible: true,
        environments: branch_to_environment(branch),
        tracker_ids: tracker_ids.join(', '),
        source: commit.to_json
      }
    end
  end

  changes
end