Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit log, working solution #88

Open
lizdeika opened this issue Dec 6, 2018 · 1 comment
Open

Commit log, working solution #88

lizdeika opened this issue Dec 6, 2018 · 1 comment

Comments

@lizdeika
Copy link

lizdeika commented Dec 6, 2018

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
@Blacklizardu
Copy link

Blacklizardu commented Nov 1, 2023

In git_log you can even do this to make it even prettier

def git_log
         return unless revisions_present?

         output, _status = Open3.capture2e 'git',
                                           '--no-pager',
                                           'log',
                                           '--no-merges',
                                           '--pretty=',
                                           '--format=format:%ad - *%s*%d -- _%an_',
                                           '--date-order',
                                           '--date=iso',
                                           "^#{previous_revision}",
                                           current_revision
         if output.empty?

         'No commits (empty deploy)'

         else

         output.strip

         end
       end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants