class Stenographer::Inputs::GithubInput
Constants
- COMMIT_MESSAGE_PARSER
- GRAMMAR
Public Instance Methods
parse(params)
click to toggle source
# 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
Private Instance Methods
branch_to_environment(branch)
click to toggle source
# File lib/stenographer/inputs/github_input.rb, line 57 def branch_to_environment(branch) Stenographer.branch_mapping[branch.to_sym].presence || branch end
commit_id(commit)
click to toggle source
# File lib/stenographer/inputs/github_input.rb, line 81 def commit_id(commit) commit[:id] end
commit_message(commit)
click to toggle source
# File lib/stenographer/inputs/github_input.rb, line 77 def commit_message(commit) commit[:message] end
parse_changelog_message(commit)
click to toggle source
# File lib/stenographer/inputs/github_input.rb, line 69 def parse_changelog_message(commit) regex = /\[changelog (.*)\]/i match = commit.match(regex) match.present? ? match[1] : nil end
parse_tracker_ids(commit)
click to toggle source
# File lib/stenographer/inputs/github_input.rb, line 85 def parse_tracker_ids(commit) parsed = suppress(Citrus::ParseError) do COMMIT_MESSAGE_PARSER.parse(commit) end parsed&.value end
tracked_branch?(branch)
click to toggle source
# File lib/stenographer/inputs/github_input.rb, line 61 def tracked_branch?(branch) if Stenographer.tracked_branches.blank? true else Stenographer.tracked_branches.include?(branch) end end