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

Branch name parser update and Pivotal Tracker id from branch name. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/heroku_feature_deployments/deployer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module HerokuFeatureDeployments
class Deployer

attr :pivotal_ticket_id

def initialize(options = {})
@branch_name = options[:branch_name] || get_branch_name
@remote_name = options[:remote_name] || @branch_name.underscore
Expand All @@ -15,8 +17,11 @@ def initialize(options = {})
# PivotalTracker::Client.token = config.pivotal_tracker_api_key
end

def deploy(pivotal_ticket_id)
@pivotal_ticket_id = pivotal_ticket_id
# options
# :pivotal_ticket_id - if nil, ticket id will be fetched from branch
# name.
def deploy(options = {})
@pivotal_ticket_id = options[:pivotal_ticket_id]
if app_exists?
add_environment_variables
add_collaborators
Expand Down Expand Up @@ -85,8 +90,13 @@ def create_pull_request
# end

def get_branch_name
`git branch`.split("\n").select {|s| s =~ /\*/ }.first.gsub(/\*/, '').
strip
`git rev-parse --abbrev-ref HEAD`.strip
end

# Default to ticket id from branch name in format:
# "48586573-pg-tags" -> "48586573".
def pivotal_ticket_id(branch_name = get_branch_name)
@pivotal_ticket_id ||= ((branch_name =~ /^(\d+)/ rescue false) ? $1 : nil)
end

def create_db
Expand Down
3 changes: 1 addition & 2 deletions lib/tasks/heroku_feature_deployments.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ namespace :hfd do

desc 'Deploy the current branch'
task deploy: :environment do
HerokuFeatureDeployments::Deployer.new.
deploy(ENV['PIVOTAL_TICKET_ID'])
HerokuFeatureDeployments::Deployer.new.deploy(ENV['PIVOTAL_TICKET_ID'])
end

desc 'Undeploy the current branch'
Expand Down