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

Add git-credentials features #69

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ activate :deploy do |deploy|

# strategy is optional (default is :force_push)
deploy.strategy = :submodule

# Git credentials helper (default is :none_helper)
deploy.credentials = :cache_helper
deploy.credentials_timeout = 3600 # (default is 12h)
end

# To deploy the build directory to a remote host via ftp:
Expand Down
1 change: 1 addition & 0 deletions lib/middleman-deploy/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "middleman-deploy/extension"
require "middleman-deploy/methods"
require "middleman-deploy/strategies"
require "middleman-deploy/credentials"
require "middleman-deploy/pkg-info"

module Middleman
Expand Down
2 changes: 2 additions & 0 deletions lib/middleman-deploy/credentials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'middleman-deploy/credentials/git/cache'
require 'middleman-deploy/credentials/git/none'
27 changes: 27 additions & 0 deletions lib/middleman-deploy/credentials/git/cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

module Middleman
module Deploy
module Credentials
module Git
class CacheHelper
attr_accessor :timeout
def initialize(timeout)
self.timeout = timeout
end
def save_credentials
unless credentials_active?
`git config --global credential.helper 'cache --timeout=#{timeout}' `
puts "Git credentials-helper has cached your data for #{timeout} seconds"
else
puts "Git credentials already active"
end
end

def credentials_active?
`git config --global credential.helper` != ''
end
end
end
end
end
end
15 changes: 15 additions & 0 deletions lib/middleman-deploy/credentials/git/none.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

module Middleman
module Deploy
module Credentials
module Git
class NoneHelper
def initialize(*args); end
def save_credentials
# No implementation for none helper
end
end
end
end
end
end
6 changes: 4 additions & 2 deletions lib/middleman-deploy/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Middleman
module Deploy

class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags, :commit_message); end
class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags, :commit_message, :credentials, :credentials_timeout); end

class << self

Expand All @@ -26,7 +26,9 @@ def registered(app, options_hash={}, &block)
options.branch ||= "gh-pages"
options.strategy ||= :force_push
options.commit_message ||= nil

options.credentials ||= :none_helper
options.credentials_timeout ||= 3600 * 12

options.build_before ||= false

@@options = options
Expand Down
7 changes: 7 additions & 0 deletions lib/middleman-deploy/methods/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def process
strategy_instance = strategy_class_name.constantize.new(self.server_instance.build_dir, self.options.remote, self.options.branch, self.options.commit_message)

strategy_instance.process

camelized_helper = self.options.credentials.to_s.split('_').map { |word| word.capitalize}.join
helper_class_name = "Middleman::Deploy::Credentials::Git::#{camelized_helper}"
helper_instance = helper_class_name.constantize.new(self.options.credentials_timeout)

helper_instance.save_credentials

end

end
Expand Down