diffhub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in diffhub.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ diffhub (0.0.1)
5
+ github_api
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ faraday (0.8.4)
12
+ multipart-post (~> 1.1)
13
+ github_api (0.7.0)
14
+ faraday (~> 0.8.1)
15
+ hashie (~> 1.2.0)
16
+ multi_json (~> 1.3)
17
+ nokogiri (~> 1.5.2)
18
+ oauth2
19
+ hashie (1.2.0)
20
+ httpauth (0.1)
21
+ jwt (0.1.5)
22
+ multi_json (>= 1.0)
23
+ multi_json (1.3.6)
24
+ multipart-post (1.1.5)
25
+ nokogiri (1.5.5)
26
+ oauth2 (0.8.0)
27
+ faraday (~> 0.8)
28
+ httpauth (~> 0.1)
29
+ jwt (~> 0.1.4)
30
+ multi_json (~> 1.0)
31
+ rack (~> 1.2)
32
+ rack (1.4.1)
33
+ rake (0.9.2.2)
34
+ rspec (2.8.0)
35
+ rspec-core (~> 2.8.0)
36
+ rspec-expectations (~> 2.8.0)
37
+ rspec-mocks (~> 2.8.0)
38
+ rspec-core (2.8.0)
39
+ rspec-expectations (2.8.0)
40
+ diff-lcs (~> 1.1.2)
41
+ rspec-mocks (2.8.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ diffhub!
48
+ rake
49
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 dreamfall
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ ## diffhub
2
+
3
+ Simple CLI for uploading `dit diff` compand output to private gist on github.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'diffhub'
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install diffhub
14
+
15
+ ## Usage
16
+
17
+ TODO: Write usage instructions here
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Run all specs in spec directory'
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => :spec
data/bin/diffhub ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'diffhub'
4
+
5
+ cli = Diffhub::Cli.new(ARGV)
6
+ cli.execute!
data/diffhub.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'diffhub/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "diffhub"
8
+ gem.version = Diffhub::VERSION
9
+ gem.authors = ["Vasili Kachalko"]
10
+ gem.email = ["amarant.st@gmail.com"]
11
+ gem.description = %q{Uploads the output of "git diff" comand to a gist}
12
+ gem.summary = %q{Fast and easy diff upload to github's gist}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'github_api'
21
+ end
data/lib/diffhub.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "diffhub/version"
2
+ require "diffhub/cli"
3
+ require "diffhub/git_hub"
@@ -0,0 +1,14 @@
1
+ module Diffhub
2
+ class Cli
3
+ attr_reader :args, :github
4
+
5
+ def initialize(args=[])
6
+ @args = args
7
+ @github = GitHub.new
8
+ end
9
+
10
+ def execute!
11
+ github.upload_diff!
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'yaml'
2
+ require 'github_api'
3
+
4
+ module Diffhub
5
+ class GitHub
6
+ attr_reader :github_gist
7
+
8
+ def initialize
9
+ credentials = YAML.load_file(ENV['HOME'] + '/.github_config.yml')
10
+
11
+ raise ArgumentError, "No password given" unless credentials['password']
12
+ raise ArgumentError, "No login given" unless credentials['login']
13
+ @github_gist = ::Github::Gists.new credentials
14
+ end
15
+
16
+ def upload_diff!
17
+ response = github_gist.create(:public => false, :files => {'git.diff' => {:content => `git diff`}}, :description => '')
18
+ p response.html_url
19
+ rescue Github::Error::UnprocessableEntity
20
+ p 'no diff given'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Diffhub
2
+ VERSION = "0.0.1"
3
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Diffhub::Cli do
4
+ before do
5
+ Diffhub::GitHub.should_receive(:new)
6
+ end
7
+
8
+ describe '#args' do
9
+ it 'returns empty array if no arguments passed' do
10
+ cli = described_class.new
11
+ cli.args.should eq([])
12
+ end
13
+
14
+ it 'returns passed arguments' do
15
+ cli = described_class.new(%w[hello there])
16
+ cli.args.should eq(%w[hello there])
17
+ end
18
+ end
19
+
20
+ describe '#execute!' do
21
+ it 'executes upload to github' do
22
+ cli = described_class.new
23
+ github = mock(:gh)
24
+ github.should_receive(:upload_diff!)
25
+ cli.stub(:github) { github }
26
+ cli.execute!
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Diffhub::GitHub do
4
+ describe '.new' do
5
+ it 'passes login and password to github API gem' do
6
+ credentials = {'login' => 'gorbypuff', 'password' => 'thecat' }
7
+ YAML.stub(:load_file) { credentials }
8
+ Github::Gists.should_receive(:new, credentials)
9
+ gh = described_class.new
10
+ end
11
+
12
+ it 'raises error if no password given in credentials file' do
13
+ credentials = {'login' => 'gorbypuff'}
14
+ YAML.stub(:load_file) { credentials }
15
+ Github::Gists.stub(:new)
16
+ expect { described_class.new }.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it 'raises error if no login given in credentials file' do
20
+ credentials = {'password' => 'thecat'}
21
+ YAML.stub(:load_file) { credentials }
22
+ Github::Gists.stub(:new)
23
+ expect { described_class.new }.to raise_error(ArgumentError)
24
+ end
25
+ end
26
+
27
+ describe "#upload_diff!" do
28
+ it 'sends gist to a github' do
29
+ gh_gist = mock(:gh_api)
30
+ args = {:public => false, :files => {'git.diff' => {:content => "superdiff"}}, :description => ''}
31
+ gh_gist.should_receive(:create).with(args) { mock(html_url: '') }
32
+ Diffhub::GitHub.any_instance.stub(:github_gist) { gh_gist }
33
+ module Kernel
34
+ def `(cmd)
35
+ 'superdiff'
36
+ end
37
+
38
+ def p(_); end
39
+ end
40
+ credentials = {'login' => 'gorbypuff', 'password' => 'thecat' }
41
+ YAML.stub(:load_file) { credentials }
42
+ Github::Gists.stub(:new)
43
+ Diffhub::GitHub.new.upload_diff!
44
+ end
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ require 'diffhub'
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diffhub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vasili Kachalko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: github_api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Uploads the output of "git diff" comand to a gist
31
+ email:
32
+ - amarant.st@gmail.com
33
+ executables:
34
+ - diffhub
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/diffhub
45
+ - diffhub.gemspec
46
+ - lib/diffhub.rb
47
+ - lib/diffhub/cli.rb
48
+ - lib/diffhub/git_hub.rb
49
+ - lib/diffhub/version.rb
50
+ - spec/cli_spec.rb
51
+ - spec/git_hub_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.24
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Fast and easy diff upload to github's gist
77
+ test_files:
78
+ - spec/cli_spec.rb
79
+ - spec/git_hub_spec.rb
80
+ - spec/spec_helper.rb