Skip to content

Commit log, working solutionΒ #88

Open
@lizdeika

Description

Hi,

For anyone still struggling with outputing useful info for non technical staff:

screeny
https://i.imgur.com/h0l2K9U.jpg

Snippet to add to the custom messaging class:

def payload_for_updated
  {
    attachments: [
      {
        color: 'good',
        title: "#{deployer} deployed #{application} to #{stage}",
        fields:
          [
            {
              title: 'Project',
              value: application,
              short: true
            },
            {
              title: 'Environment',
              value: stage,
              short: true
            }
          ].tap do |fields|
            if revisions_present?
              fields << {
                title: 'Log',
                value: git_log,
                short: false
              }
            end
          end,
        fallback: super[:text]
      }.tap do |attachment|
        attachment[:title_link] = deployed_link if revisions_present?
      end
    ]
  }
end

# Open3 used for safe capturing when passing ruby variables to the command
def git_log
  return unless revisions_present?

  output, _status = Open3.capture2e 'git',
                                    'log',
                                    '--no-decorate',
                                    '--oneline',
                                    '--format=format:%s',
                                    "^#{previous_revision}",
                                    current_revision
  output.strip
end

def deployed_link
  return unless revisions_present?

  "https://github.com/YOUR_ORG/YOUR_APP/compare/#{CGI.escape(previous_revision)}...#{CGI.escape(current_revision)}"
end

def revisions_present?
  current_revision && previous_revision
end

def current_revision
  fetch :current_revision
end

def previous_revision
  fetch :previous_revision
end

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions