Sha256: cb413009e8baa1be73cbf96bd4ebf46d26b4b7de9acdf6b0f3145481f76d5932

Contents?: true

Size: 1.73 KB

Versions: 33

Compression:

Stored size: 1.73 KB

Contents

require "rake"
require "rake/tasklib"
require 'octokit'
require 'netrc'

module Fog
  module Rake
    class GithubReleaseTask < ::Rake::TaskLib
      def initialize
        desc "Update the changelog since the last release"
        task(:github_release) do

          File.open('CHANGELOG.md', 'r') do |file|
            file.each_line do |line|
              @current_line = line
               if release_header?
                 create_release if !release_exists? && @release
                 @release_tag = release_match[1]
                 @release = line
               else
                 @release << line
               end
            end
          end
        end
      end

      private

      def create_release
        github.create_release "fog/fog", "v#{@release_tag}", {:name => "v#{@release_tag}", :body => @release}
        puts "creating release #{@release_tag}"
      end

      def releases
        return @releases if @releases
        response = github.releases("fog/fog")
        @releases = response.map {|r| r.tag_name }
      end

      def release_exists?
        releases.find {|r| r == "v#{@release_tag}" } != nil
      end

      def release_header?
        release_match != nil
      end

      def release_match
        @current_line.match /## (\d+\.\d+\.\d+) \d+\/\d+\d+/
      end

      def github
        unless @github
          Octokit.auto_paginate = true
          @github  = Octokit::Client.new :netrc => true
          unless @github.login
            @github = nil
            raise "Please create a ~/.netrc file to authenticate with github. For more information please see https://github.com/octokit/octokit.rb/blob/master/README.md#using-a-netrc-file"
          end
        end
        @github
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
fog-1.41.0 lib/tasks/github_release_task.rb
fog-1.40.0 lib/tasks/github_release_task.rb
fog-1.39.0 lib/tasks/github_release_task.rb
fog-1.38.0 lib/tasks/github_release_task.rb
fog-1.37.0 lib/tasks/github_release_task.rb
fog-1.36.0 lib/tasks/github_release_task.rb
fog-1.35.0 lib/tasks/github_release_task.rb
fog-2.0.0.pre.0 lib/tasks/github_release_task.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/tasks/github_release_task.rb
fog-1.34.0 lib/tasks/github_release_task.rb
fog-1.33.0 lib/tasks/github_release_task.rb
fog-1.32.0 lib/tasks/github_release_task.rb
fog-1.31.0 lib/tasks/github_release_task.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/tasks/github_release_task.rb
fog-1.30.0 lib/tasks/github_release_task.rb
fog-1.29.0 lib/tasks/github_release_task.rb
fog-1.28.0 lib/tasks/github_release_task.rb
fog-1.27.0 lib/tasks/github_release_task.rb
fog-1.26.0 lib/tasks/github_release_task.rb
fog-1.25.0 lib/tasks/github_release_task.rb