pori 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pori
2
2
 
3
- A command line toos for Bitbucket to create private repository.(only git)
3
+ A command line toos for Bitbucket to create, delete private repository.(only git)
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,9 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### create repository
22
+
21
23
  $ cd path/to/local-git-directory
22
24
  $ pori
23
25
 
26
+ ### delete repository
27
+
28
+ $ cd path/to/local-git-directory
29
+ $ pori delete
30
+
24
31
  ## Requirements
25
32
 
26
33
  * [Git](http://git-scm.com/)
data/bin/pori CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'pori'
4
- Pori::Runner.execute(*ARGV)
4
+ Pori::Commands.run(*ARGV)
@@ -2,4 +2,3 @@
2
2
 
3
3
  require "pori/version"
4
4
  require "pori/commands"
5
- require "pori/runner"
@@ -1,46 +1,104 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'pit'
4
+ require 'httparty'
4
5
 
5
6
  module Pori
6
7
  class Commands
7
- def initialize(args)
8
- @args = args
8
+ def initialize(*args)
9
+ @command = args.empty? ? :create : args.shift.to_sym
9
10
 
10
- config = Pit.get("bitbucket", :require => {
11
- "username" => "your account in bitbucket",
12
- "password" => "your password in bitbucket"
13
- })
14
- @username = config['username']
15
- @password = config['password']
11
+ config = Pit.get("bitbucket",
12
+ require: {
13
+ "username" => "your account in bitbucket",
14
+ "password" => "your password in bitbucket"
15
+ }
16
+ )
17
+
18
+ @options = {
19
+ basic_auth: { username: config['username'], password: config['password'] },
20
+ headers: { "User-Agent" => "Pori #{Pori::VERSION} - https://github.com/glidenote/pori" }
21
+ }
22
+
23
+ @repo = repo_name
24
+ @username = config['username']
16
25
  end
17
26
 
18
- def self.run(args)
19
- self.new(args).run
27
+ def self.run(*args)
28
+ self.new(*args).run
20
29
  end
21
30
 
22
31
  def run
23
- # 今は決め打ち、動的に変更する
24
- self.send('create')
32
+ self.send(@command)
25
33
  end
26
34
 
27
35
  def create
28
- repo = new_repo_name
36
+ endpoint = 'https://api.bitbucket.org/1.0/repositories/'
37
+
38
+ @options.merge!(
39
+ { body:
40
+ { name: @repo, scm: "git", is_private: "true" }
41
+ }
42
+ )
43
+ response = HTTParty.post(endpoint, @options)
44
+
45
+ if response.code.to_i == 200
46
+ puts "Successfully created."
47
+ puts "git remote add origin ssh://git@bitbucket.org/#{@username}/#{@repo}.git"
48
+ system "git remote add origin ssh://git@bitbucket.org/#{@username}/#{@repo}.git"
49
+ else
50
+ $stdout.puts "Something was wrong... o_O"
51
+ $stdout.puts
52
+ $stdout.puts response
53
+ end
54
+ end
29
55
 
30
- puts "curl --request POST --user #{@username}:#{@password.chars.map{|c| '*'}.join} https://api.bitbucket.org/1.0/repositories/ --data name=#{repo} --data scm=git --data is_private=true"
31
- system "curl --request POST --user #{@username}:#{@password} https://api.bitbucket.org/1.0/repositories/ --data name=#{repo} --data scm=git --data is_private=true"
32
- puts "git remote add origin ssh://git@bitbucket.org/#{@username}/#{repo}.git"
33
- system "git remote add origin ssh://git@bitbucket.org/#{@username}/#{repo}.git"
56
+ def delete
57
+ if del_flags
58
+ endpoint = "https://api.bitbucket.org/1.0/repositories/#{@username}/#{@repo}"
59
+ response = HTTParty.delete(endpoint, @options)
60
+ if response.code.to_i == 204
61
+ puts "Successfully deleted."
62
+ else
63
+ $stdout.puts "Something was wrong... o_O"
64
+ $stdout.puts
65
+ $stdout.puts response
66
+ end
67
+ else
68
+ puts "Canceled."
69
+ end
34
70
  end
35
71
 
36
72
  private
37
- def new_repo_name
73
+ def repo_name
38
74
  raise Exception, "Not a git repository" unless is_git_repo?
39
- Dir.pwd.split('/')[-1]
75
+ tmp_dir = `git rev-parse -q --git-dir`.chomp
76
+ if tmp_dir == ".git"
77
+ repo_name = File.basename(Dir.pwd)
78
+ else
79
+ repo_dir_name = File.dirname("#{tmp_dir}") # => /Users/akira/repos/pori/.git
80
+ repo_name = File.basename("#{repo_dir_name}") # => pori
81
+ end
82
+ repo_name
40
83
  end
41
84
 
42
85
  def is_git_repo?
43
86
  system('git rev-parse --git-dir >/dev/null 2>&1;')
44
87
  end
88
+
89
+ def del_flags
90
+ confirm = false
91
+
92
+ print "Please type in the name of the repository to confirm [(#{@repo})] :"
93
+ del_repo = STDIN.gets.chomp
94
+
95
+ if del_repo == @repo
96
+ print "Really delete repository? [y/N] :"
97
+ yes_or_no = STDIN.gets.chomp
98
+ if yes_or_no =~ /yes|y/i
99
+ confirm = true
100
+ end
101
+ end
102
+ end
45
103
  end
46
104
  end
@@ -1,3 +1,3 @@
1
1
  module Pori
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,7 +4,7 @@ require File.expand_path('../lib/pori/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Akira Maeda"]
6
6
  gem.email = ["glidenote@gmail.com"]
7
- gem.summary = %q{A command line tool for Bitbucket to create private repositories.(only git)}
7
+ gem.summary = %q{A command line tool for Bitbucket to create, delete private repositories.(only git)}
8
8
  gem.homepage = "http://github.com/glidenote/pori/"
9
9
 
10
10
  gem.files = `git ls-files`.split($\)
@@ -16,5 +16,6 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_dependency 'pit'
18
18
  gem.add_dependency 'rake'
19
+ gem.add_dependency 'httparty'
19
20
  gem.add_development_dependency 'rspec'
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pit
16
- requirement: &70344883657960 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,31 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70344883657960
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70344883657300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: httparty
48
+ requirement: !ruby/object:Gem::Requirement
28
49
  none: false
29
50
  requirements:
30
51
  - - ! '>='
@@ -32,10 +53,15 @@ dependencies:
32
53
  version: '0'
33
54
  type: :runtime
34
55
  prerelease: false
35
- version_requirements: *70344883657300
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
36
62
  - !ruby/object:Gem::Dependency
37
63
  name: rspec
38
- requirement: &70344883656660 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
39
65
  none: false
40
66
  requirements:
41
67
  - - ! '>='
@@ -43,7 +69,12 @@ dependencies:
43
69
  version: '0'
44
70
  type: :development
45
71
  prerelease: false
46
- version_requirements: *70344883656660
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
47
78
  description:
48
79
  email:
49
80
  - glidenote@gmail.com
@@ -60,7 +91,6 @@ files:
60
91
  - bin/pori
61
92
  - lib/pori.rb
62
93
  - lib/pori/commands.rb
63
- - lib/pori/runner.rb
64
94
  - lib/pori/version.rb
65
95
  - pori.gemspec
66
96
  - spec/pori/.gitkeep
@@ -78,25 +108,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
108
  - - ! '>='
79
109
  - !ruby/object:Gem::Version
80
110
  version: '0'
81
- segments:
82
- - 0
83
- hash: 2418092421942208002
84
111
  required_rubygems_version: !ruby/object:Gem::Requirement
85
112
  none: false
86
113
  requirements:
87
114
  - - ! '>='
88
115
  - !ruby/object:Gem::Version
89
116
  version: '0'
90
- segments:
91
- - 0
92
- hash: 2418092421942208002
93
117
  requirements: []
94
118
  rubyforge_project:
95
- rubygems_version: 1.8.11
119
+ rubygems_version: 1.8.23
96
120
  signing_key:
97
121
  specification_version: 3
98
- summary: A command line tool for Bitbucket to create private repositories.(only git)
122
+ summary: A command line tool for Bitbucket to create, delete private repositories.(only
123
+ git)
99
124
  test_files:
100
125
  - spec/pori/.gitkeep
101
126
  - spec/spec.opts
102
127
  - spec/spec_helper.rb
128
+ has_rdoc:
@@ -1,18 +0,0 @@
1
- module Pori
2
- class Runner
3
- attr_reader :args
4
-
5
- def initialize(*args)
6
- @args = args
7
- end
8
-
9
- # Shortcut
10
- def self.execute(*args)
11
- new(*args).execute
12
- end
13
-
14
- def execute
15
- Commands.run(@args)
16
- end
17
- end
18
- end