Sha256: f91c2156168380cba7f35ca24fedda51f76608e88e0928acf2f648e3ffa3c180

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Brief
  module Handlers
    class GithubMilestone < Base
      def prepare!
        @prepared ||= begin
                        if github_api_milestone.present?
                          element.milestone_url = github_api_milestone.url
                          element.milestone_number = github_api_milestone.number
                        else
                          element.milestone_url = create_in_github_api.url
                          element.milestone_number = github_api_milestone.number
                        end

                        element
                      end
      end

      def create_in_github_api
        @github_api_milestone ||= milestones_api.create_object(body: body, title: title)
      end

      def body
        document.parser.content_lines_under(title).reject(&:blank?).join("\n")
      end

      def milestones_api refresh=false
        Brief.repository_milestones.tap do |api|
          refresh ? api.refresh : api
        end
      end

      def github_api_milestone
        @github_api_milestone ||= milestones_api(true).all.detect {|milestone| milestone.title == element.title }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brief-0.0.5 lib/brief/handlers/github_milestone.rb
brief-0.0.4 lib/brief/handlers/github_milestone.rb
brief-0.0.3 lib/brief/handlers/github_milestone.rb
brief-0.0.2 lib/brief/handlers/github_milestone.rb