Sha256: 837ab5b1bee7425138ed20d727bd65a880b5d48ff010bf46c77424340ffdef06

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require 'tracker_api'

module GitFlower
  class PivotalProject
    def initialize(pivotal_token, project_id)
      client = TrackerApi::Client.new(token: pivotal_token)
      # we only have one project so this works well
      @project = client.project(project_id)
    end

    def create_story(type, options)
      if type == "feature"
        create_feature(options)
      elsif type == "hotfix"
        create_hotfix(options)
      end
    end

    def create_hotfix(options)
      story_owner_ids = find_users(options[:owner_usernames]).map(&:id)
      project.create_story(name: options[:name],
                           labels: options[:labels],
                           story_type: 'bug',
                           current_state: 'started',
                           owner_ids: story_owner_ids)
    end

    def create_feature(options)
      story_owner_ids = find_users(options[:owner_usernames]).map(&:id)
      project.create_story(name: options[:name],
                           labels: options[:labels],
                           story_type: 'feature',
                           current_state: 'started',
                           estimate: 0,
                           owner_ids: story_owner_ids)
    end

    private

    attr_reader :project

    def find_users(owner_usernames)
      project.memberships.map(&:person).select do |person|
        owner_usernames.include? person.email.split("@").first
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git_flower-0.1.3 lib/git_flower/pivotal_project.rb
git_flower-0.1.2 lib/git_flower/pivotal_project.rb
git_flower-0.1.1 lib/git_flower/pivotal_project.rb