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

Update for mina 1.X #13

Open
wants to merge 3 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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ Or use the ENV variables:
ENV['SLACK_EMOJI'] = ''
ENV['SLACK_STAGE'] = '' # or ENV['to']

### Add tasks
Invoke tasks in your deploy.rb

```Ruby
task deploy do
run(:local) { invoke :'slack:starting' }
deploy do
# [...]
on :launch do
# [...]
end
end
run(:local) { invoke :'slack:finished' }
end
```

## Contributing

1. Fork it ( http://github.com/<my-github-username>/mina-slack/fork )
Expand Down
16 changes: 8 additions & 8 deletions lib/mina/slack/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Required
set_default :slack_url, -> { ENV['SLACK_URL'] }
set_default :slack_room, -> { ENV['SLACK_ROOM'] }
set :slack_url, -> { ENV['SLACK_URL'] }
set :slack_room, -> { ENV['SLACK_ROOM'] }
# Optional
set_default :slack_stage, -> { ENV['SLACK_STAGE'] || ENV['to'] || fetch(:rails_env, 'production') }
set_default :slack_application, -> { ENV['SLACK_APPLICATION'] || application }
set_default :slack_username, -> { ENV['SLACK_USERNAME'] || 'deploybot' }
set_default :slack_emoji, -> { ENV['SLACK_EMOJI'] || ':cloud:' }
set :slack_stage, -> { ENV['SLACK_STAGE'] || ENV['to'] || fetch(:rails_env, 'production') }
set :slack_application, -> { ENV['SLACK_APPLICATION'] || fetch(:application) }
set :slack_username, -> { ENV['SLACK_USERNAME'] || 'deploybot' }
set :slack_emoji, -> { ENV['SLACK_EMOJI'] || ':cloud:' }
# Git
set_default :deployer, -> { ENV['GIT_AUTHOR_NAME'] || %x[git config user.name].chomp }
set_default :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{branch}].strip }
set :deployer, -> { ENV['GIT_AUTHOR_NAME'] || %x[git config user.name].chomp }
set :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{fetch(:branch)}].strip }
26 changes: 18 additions & 8 deletions lib/mina/slack/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
require 'json'
require 'net/http'


# Before and after hooks for mina deploy
before_mina :deploy, :'slack:starting'
after_mina :deploy, :'slack:finished'


# Slack tasks
namespace :slack do

task :starting do
slack_room = fetch(:slack_room)
slack_url = fetch(:slack_url)

if slack_url and slack_room
announcement = "#{announced_deployer} is deploying #{announced_application_name} to #{announced_stage}"

Expand All @@ -24,6 +21,9 @@
end

task :finished do
slack_room = fetch(:slack_room)
slack_url = fetch(:slack_url)

if slack_url and slack_room
end_time = Time.now
start_time = fetch(:start_time)
Expand All @@ -39,18 +39,23 @@


def announced_stage
slack_stage
fetch(:slack_stage)
end

def announced_deployer
deployer
fetch(:deployer)
end

def short_revision
deployed_revision = fetch(:deployed_revision)

deployed_revision[0..7] if deployed_revision
end

def announced_application_name
slack_application = fetch(:slack_application)
branch = fetch(:branch)

"".tap do |output|
output << slack_application if slack_application
output << " `#{branch}`" if branch
Expand All @@ -59,6 +64,11 @@ def announced_application_name
end

def post_slack_message(message)
slack_emoji = fetch(:slack_emoji)
slack_room = fetch(:slack_room)
slack_url = fetch(:slack_url)
slack_username = fetch(:slack_username)

# Parse the URI and handle the https connection
uri = URI.parse(slack_url)
http = Net::HTTP.new(uri.host, uri.port)
Expand Down