git_httpsable-push 0.0.1.beta → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f65fb15539c1071c5fd91383d3b190e89cc29a25
4
- data.tar.gz: 6514248574d76fe39b9ebab139177e6bac2720ae
3
+ metadata.gz: d1b5925cced6faeef5e5a123474739743d4d2a24
4
+ data.tar.gz: 8aef2e3b5fd5106156f0572e8b0e090d99a4eeec
5
5
  SHA512:
6
- metadata.gz: 1e97a4f3fc0f0bf0bfe82241f14bcd701595c3d6c45921e17b8e11153bddbbfe13f7ec722f7ee291160a34acb6c06f4a17557a48d60300653e61f6a7739ede76
7
- data.tar.gz: bff98611e7ba657c8369da5115a4835749daf3d3a405c93194732045533dd4a57f851e3bbe22184e35ad1cac06157de981425da300e3f8a6b7aed07535753784
6
+ metadata.gz: d557dad3c3b6b192843ef58529d108e08860f6cbf40bf1c113c762ba05355122d83094d2888250dcae09802f5142db743b86d83d17ec1078a08ad233961af897
7
+ data.tar.gz: 1b863f6d2e91e22f98bf118a991a0d3fd963cb39f75326c8fccce4485c15d3313d0ecc896d234cc5862c2f302ae4757f17966ff962358e500a5dadf05c176698
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bundle_bin/*'
4
+ - 'vendor/bundle/**/*'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+
12
+ Style/FileName:
13
+ Exclude:
14
+ - exe/*
15
+
16
+ Style/RegexpLiteral:
17
+ MaxSlashes: 0
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## 0.1.0 (2015-03-06)
2
+
3
+
4
+ #### Features
5
+
6
+ * **app:** release
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in git_httpsable-push.gemspec
4
4
  gemspec
5
+ gem 'byebug' if RUBY_VERSION >= '2.0.0'
6
+ gem 'pry'
data/README.md CHANGED
@@ -3,9 +3,79 @@
3
3
  [![Gem Version](http://img.shields.io/gem/v/git_httpsable-push.svg?style=flat)](http://badge.fury.io/rb/git_httpsable-push)
4
4
  [![Build Status](http://img.shields.io/travis/packsaddle/ruby-git_httpsable-push/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-git_httpsable-push)
5
5
 
6
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/git_httpsable/push`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ ## Description
7
7
 
8
- TODO: Delete this and the text above, and describe your gem
8
+ * Easy to set up `git push` via `https://...`.
9
+ * Keep your `git push` via https **Safely**.
10
+
11
+ ## Usage
12
+
13
+ require `GITHUB_ACEESS_TOKEN`.
14
+
15
+ ```bash
16
+ # like git push
17
+ $ git httpsable-push origin master
18
+ ```
19
+
20
+ Whether you set `git://...` or `https://...` or `git@...`, you can push via `https://...`.
21
+
22
+ And this always masks your token.
23
+
24
+ e.g.
25
+
26
+ ```
27
+ $ git config --get remote.origin.url
28
+ git@github.com:packsaddle/ruby-git_httpsable-push.git
29
+ # GITHUB_ACCESS_TOKEN=__MY_TOKEN__
30
+
31
+ # success
32
+ $ git httpsable-push origin refactor/logger-to-class --verbose
33
+ I, [2015-03-06T19:29:54.250481 #33391] INFO -- GitHttpsable::Push: Starting Git
34
+ I, [2015-03-06T19:29:54.270408 #33391] INFO -- GitHttpsable::Push: git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' config '--list' 2>&1
35
+ I, [2015-03-06T19:29:54.281424 #33391] INFO -- GitHttpsable::Push: git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' config '--list' 2>&1
36
+ I, [2015-03-06T19:29:56.632766 #33391] INFO -- GitHttpsable::Push: git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' push 'https://MASKED@github.com/packsaddle/ruby-git_httpsable-push.git' 'refactor/logger-to-class' 2>&1
37
+ I, [2015-03-06T19:29:56.632944 #33391] INFO -- GitHttpsable::Push: {:output=>nil}
38
+
39
+ # error occurs
40
+ $ git httpsable-push origin refactor/logger-to-class --verbose
41
+ I, [2015-03-06T19:33:47.692967 #34984] INFO -- GitHttpsable::Push: Starting Git
42
+ I, [2015-03-06T19:33:47.701617 #34984] INFO -- GitHttpsable::Push: git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' config '--list' 2>&1
43
+ I, [2015-03-06T19:33:47.711167 #34984] INFO -- GitHttpsable::Push: git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' config '--list' 2>&1
44
+ I, [2015-03-06T19:33:50.657268 #34984] INFO -- GitHttpsable::Push: git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' push 'https://MASKED@github.com/packsaddle/ruby-git_httpsable-push.git' 'refactor/logger-to-class' 2>&1
45
+ E, [2015-03-06T19:33:50.657632 #34984] ERROR -- GitHttpsable::Push: Have a question? Please ask us:
46
+ E, [2015-03-06T19:33:50.657667 #34984] ERROR -- GitHttpsable::Push: https://github.com/packsaddle/ruby-git_httpsable-push/issues/new
47
+ E, [2015-03-06T19:33:50.657711 #34984] ERROR -- GitHttpsable::Push: options:
48
+ E, [2015-03-06T19:33:50.657778 #34984] ERROR -- GitHttpsable::Push: {"debug"=>false, "verbose"=>true, "force"=>false, "tags"=>false}
49
+ /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/git-1.2.9.1/lib/git/lib.rb:917:in `command': (Git::GitExecuteError) git '--git-dir=/Users/sane/work/ruby-study/git_httpsable-push/.git' '--work-tree=/Users/sane/work/ruby-study/git_httpsable-push' push 'https://MASKED@github.com/packsaddle/ruby-git_httpsable-push.git' 'refactor/logger-to-class' 2>&1:remote: Invalid username or password. (GitHttpsable::Push::GitHttpsablePushError)
50
+ fatal: Authentication failed for 'https://MASKED@github.com/packsaddle/ruby-git_httpsable-push.git/'
51
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/git-1.2.9.1/lib/git/lib.rb:727:in `push'
52
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/git-1.2.9.1/lib/git/base.rb:329:in `push'
53
+ from /Users/sane/work/ruby-study/git_httpsable-push/lib/git_httpsable/push/repository.rb:24:in `push'
54
+ from /Users/sane/work/ruby-study/git_httpsable-push/lib/git_httpsable/push/cli.rb:29:in `push'
55
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
56
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
57
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
58
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
59
+ from /Users/sane/work/ruby-study/git_httpsable-push/lib/git_httpsable/push/cli.rb:59:in `method_missing'
60
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:29:in `run'
61
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:126:in `run'
62
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
63
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
64
+ from /Users/sane/work/ruby-study/git_httpsable-push/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
65
+ from exe/git-httpsable-push:5:in `<main>'
66
+ ```
67
+
68
+ ## VS.
69
+
70
+ * `git push --quiet`, set remote url manually, error to `/dev/null`
71
+
72
+ ```
73
+ $ git push --quiet https://$GH_TOKEN@github.com/<repos_name>.git gh-pages 2> /dev/null
74
+ ```
75
+
76
+ This can push safely,
77
+ but if you forgot `--quiet` or `2> /dev/null`,
78
+ then you open your token to the world :(
9
79
 
10
80
  ## Installation
11
81
 
@@ -23,10 +93,6 @@ Or install it yourself as:
23
93
 
24
94
  $ gem install git_httpsable-push
25
95
 
26
- ## Usage
27
-
28
- TODO: Write usage instructions here
29
-
30
96
  ## Development
31
97
 
32
98
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec git_httpsable-push` to use the code located in this directory, ignoring other installed copies of this gem.
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'git_httpsable/push'
4
+ require 'git_httpsable/push/cli'
5
+ GitHttpsable::Push::CLI.start(ARGV)
@@ -29,7 +29,12 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
+ spec.add_runtime_dependency 'thor'
33
+ spec.add_runtime_dependency 'git'
34
+ spec.add_runtime_dependency 'git_clone_url'
35
+
32
36
  spec.add_development_dependency 'bundler', '~> 1.8'
33
37
  spec.add_development_dependency 'rake', '~> 10.0'
34
38
  spec.add_development_dependency 'test-unit'
39
+ spec.add_development_dependency 'mocha'
35
40
  end
@@ -1,7 +1,27 @@
1
+ require 'logger'
2
+ require 'git'
3
+ require 'uri'
4
+ require 'git_clone_url'
5
+
6
+ require 'git_httpsable/push/error'
7
+ require 'git_httpsable/push/mask_logger'
8
+ require 'git_httpsable/push/repository'
1
9
  require 'git_httpsable/push/version'
2
10
 
3
11
  module GitHttpsable
4
12
  module Push
5
- # Your code goes here...
13
+ ISSUE_URL = 'https://github.com/packsaddle/ruby-git_httpsable-push/issues/new'
14
+ def self.default_logger
15
+ MaskLogger.new($stderr)
16
+ end
17
+
18
+ def self.logger
19
+ return @logger if @logger
20
+ @logger = default_logger
21
+ end
22
+
23
+ class << self
24
+ attr_writer :logger
25
+ end
6
26
  end
7
27
  end
@@ -0,0 +1,64 @@
1
+ require 'thor'
2
+
3
+ module GitHttpsable
4
+ module Push
5
+ class CLI < Thor
6
+ def self.exit_on_failure?
7
+ true
8
+ end
9
+
10
+ desc 'version', 'Show the GitHttpsable::Push version'
11
+ map %w(-v --version) => :version
12
+
13
+ def version
14
+ puts "GitHttpsable::Push version #{::GitHttpsable::Push::VERSION}"
15
+ end
16
+
17
+ desc 'push', 'Git Push via HTTPS'
18
+ option :debug, type: :boolean, default: false
19
+ option :verbose, type: :boolean, default: false
20
+ option :force, type: :boolean, default: false, aliases: '-f'
21
+ option :tags, type: :boolean, default: false
22
+ def push(*args)
23
+ setup_logger(options)
24
+ params = {
25
+ force: options[:force],
26
+ tags: options[:tags]
27
+ }
28
+ repo = Repository.new('.')
29
+ repo.push(args[0], args[1], params)
30
+ rescue StandardError => e
31
+ suggest_messages(options)
32
+ raise e
33
+ end
34
+ default_command :push
35
+
36
+ no_commands do
37
+ def logger
38
+ ::GitHttpsable::Push.logger
39
+ end
40
+
41
+ def setup_logger(options)
42
+ if options[:debug]
43
+ logger.level = Logger::DEBUG
44
+ elsif options[:verbose]
45
+ logger.level = Logger::INFO
46
+ end
47
+ logger.debug(options)
48
+ end
49
+
50
+ def suggest_messages(options)
51
+ logger.error 'Have a question? Please ask us:'
52
+ logger.error ISSUE_URL
53
+ logger.error 'options:'
54
+ logger.error options
55
+ end
56
+
57
+ # http://stackoverflow.com/a/23955971/104080
58
+ def method_missing(method, *args)
59
+ self.class.start([self.class.default_command, method.to_s] + args)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ module GitHttpsable
2
+ module Push
3
+ class GitHttpsablePushError < StandardError
4
+ def initialize(message = nil)
5
+ return super unless message
6
+ super(mask_token(message.to_s))
7
+ end
8
+
9
+ def mask_token(text)
10
+ text.gsub(%r{://[^/@]*@}) { '://MASKED@' }
11
+ end
12
+ end
13
+
14
+ class NotExistRemoteUrlError < GitHttpsablePushError; end
15
+ class NoAuthDataError < GitHttpsablePushError; end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module GitHttpsable
2
+ module Push
3
+ class MaskLogger < Logger
4
+ def initialize(*args)
5
+ super(*args)
6
+ self.progname = "GitHttpsable::Push/#{VERSION}"
7
+ self.level = Logger::WARN
8
+ self.formatter = proc do |severity, datetime, progname, msg|
9
+ @default_formatter.call(
10
+ severity,
11
+ datetime,
12
+ progname,
13
+ msg.to_s.gsub(%r{://[^/@]*@}) { '://MASKED@' }
14
+ )
15
+ end
16
+
17
+ self
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,76 @@
1
+ module GitHttpsable
2
+ module Push
3
+ class Repository
4
+ def initialize(path, options = {})
5
+ @path = path
6
+ @options = { log: logger }.merge(options)
7
+ end
8
+
9
+ def push(remote = 'origin', branch = 'master', options = {})
10
+ logger.debug(remote: remote, branch: branch, options: options)
11
+ # check current branch's upstream remote and branch?
12
+ url = remote_url(remote)
13
+ fail NotExistRemoteUrlError, %(no "#{remote}" url) unless url
14
+ parsed = GitCloneUrl.parse(url)
15
+
16
+ converted_url = \
17
+ URI::Generic.build(
18
+ scheme: scheme,
19
+ userinfo: userinfo,
20
+ host: host(parsed.host),
21
+ port: port,
22
+ path: parsed.path
23
+ )
24
+ git.push(converted_url.to_s, branch, options)
25
+ rescue StandardError => e
26
+ raise e if e.is_a?(GitHttpsablePushError)
27
+
28
+ exception = GitHttpsablePushError.new('(' + e.class.name + ') ' + e.message)
29
+ exception.set_backtrace(e.backtrace)
30
+ raise exception
31
+ end
32
+
33
+ def logger
34
+ ::GitHttpsable::Push.logger
35
+ end
36
+
37
+ def git
38
+ @git ||= ::Git.open(@path, @options)
39
+ end
40
+
41
+ def remote_url(remote)
42
+ git.remote(remote) && git.remote(remote).url
43
+ end
44
+
45
+ def env_github_access_token
46
+ ENV['GITHUB_ACCESS_TOKEN']
47
+ end
48
+
49
+ def env_git_access_token
50
+ ENV['GIT_SERVER_ACCESS_TOKEN']
51
+ end
52
+
53
+ def userinfo
54
+ if env_git_access_token
55
+ env_git_access_token
56
+ elsif env_github_access_token
57
+ "#{env_github_access_token}:x-oauth-basic"
58
+ else
59
+ fail NoAuthDataError
60
+ end
61
+ end
62
+
63
+ def scheme
64
+ ENV['GIT_SERVER_SCHEME'] || 'https'
65
+ end
66
+
67
+ def host(host)
68
+ ENV['GIT_SERVER_HOST'] || host
69
+ end
70
+
71
+ def port
72
+ ENV['GIT_SERVER_PORT'] || nil
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,5 +1,5 @@
1
1
  module GitHttpsable
2
2
  module Push
3
- VERSION = '0.0.1.beta'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_httpsable-push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: git_clone_url
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +94,20 @@ dependencies:
52
94
  - - ">="
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
55
111
  description: "`git push` to https repo securely."
56
112
  email:
57
113
  - o.gata.ken@gmail.com
@@ -61,6 +117,8 @@ extensions: []
61
117
  extra_rdoc_files: []
62
118
  files:
63
119
  - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - CHANGELOG.md
64
122
  - CODE_OF_CONDUCT.md
65
123
  - Gemfile
66
124
  - LICENSE.txt
@@ -71,6 +129,10 @@ files:
71
129
  - exe/git-httpsable-push
72
130
  - git_httpsable-push.gemspec
73
131
  - lib/git_httpsable/push.rb
132
+ - lib/git_httpsable/push/cli.rb
133
+ - lib/git_httpsable/push/error.rb
134
+ - lib/git_httpsable/push/mask_logger.rb
135
+ - lib/git_httpsable/push/repository.rb
74
136
  - lib/git_httpsable/push/version.rb
75
137
  homepage: https://github.com/packsaddle/ruby-git_httpsable-push
76
138
  licenses:
@@ -87,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
149
  version: '0'
88
150
  required_rubygems_version: !ruby/object:Gem::Requirement
89
151
  requirements:
90
- - - ">"
152
+ - - ">="
91
153
  - !ruby/object:Gem::Version
92
- version: 1.3.1
154
+ version: '0'
93
155
  requirements: []
94
156
  rubyforge_project:
95
157
  rubygems_version: 2.4.5