Sha256: 8504b744429c5b1af4495682869620c80725c6908632730c17c2cb79d02f8a42

Contents?: true

Size: 1.88 KB

Versions: 7

Compression:

Stored size: 1.88 KB

Contents

namespace :ci do
  namespace :redmine do
    desc 'Set up Redmine'
    task :setup do
      require 'highline/import'

      ENV['REDMINE_HOSTNAME'] ||= ask('Redmine URL: ')
      ENV['REDMINE_HOSTNAME'] = nil if ENV['REDMINE_HOSTNAME'] == ''

      ENV['REDMINE_API_KEY'] ||= ask('Redmine API Key: ') { |q| q.echo = '*' }
      ENV['REDMINE_API_KEY'] = nil if ENV['REDMINE_API_KEY'] == ''
    end

    desc 'Update Redmine tickets'
    task update_tickets: ['ci:rugged:setup', 'ci:redmine:setup'] do
      api_key = ENV['REDMINE_API_KEY']
      hostname = ENV['REDMINE_HOSTNAME']
      next if api_key.nil? || hostname.nil?

      resolved_tickets = []
      @attachments   ||= []

      require 'ndr_dev_support/rake_ci/redmine/ticket_resolver'

      begin
        ticket_resolver = NdrDevSupport::RakeCI::Redmine::TicketResolver.new(api_key, hostname)
        resolved_tickets = ticket_resolver.process_commit(@commit.author[:name],
                                                          @friendly_revision_name,
                                                          @commit.message)
      rescue
        @attachments << {
          color: 'danger',
          title: 'Redmine Update Error',
          text: 'Ticket(s) could not be resolved on Redmine!',
          footer: 'bundle exec rake ci:redmine:update_tickets'
        }
      end

      next if resolved_tickets.empty?
      resolved_tickets.map! { |ticket_id| "https://#{hostname}/issues/#{ticket_id}" }

      issue_s = resolved_tickets.count == 1 ? 'issue' : 'issues'
      attachment = {
        color: 'good',
        title: "#{issue_s.capitalize} Resolved",
        text: "Tests pass, so #{issue_s} #{resolved_tickets.join(', ')}" \
              " #{resolved_tickets.count == 1 ? 'has' : 'have'} been resolved",
        footer: 'bundle exec rake ci:minitest',
        mrkdwn_in: ['text']
      }
      @attachments << attachment
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ndr_dev_support-5.4.2 lib/tasks/ci/redmine.rake
ndr_dev_support-5.4.1 lib/tasks/ci/redmine.rake
ndr_dev_support-5.4.0 lib/tasks/ci/redmine.rake
ndr_dev_support-5.3.1 lib/tasks/ci/redmine.rake
ndr_dev_support-5.3.0 lib/tasks/ci/redmine.rake
ndr_dev_support-5.2.0 lib/tasks/ci/redmine.rake
ndr_dev_support-5.1.0 lib/tasks/ci/redmine.rake