Class: Pori::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/pori/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Commands

Returns a new instance of Commands.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pori/commands.rb', line 8

def initialize(*args)
  @command = args.empty? ? :create : args.shift.to_sym

  config = Pit.get("bitbucket",
    require: {
      "username" => "your account in bitbucket",
      "password" => "your password in bitbucket"
    }
  )

  @options   = {
    basic_auth: { username: config['username'], password: config['password'] },
    headers:    { "User-Agent" => "Pori #{Pori::VERSION} - https://github.com/glidenote/pori" }
  }

  @repo      = repo_name
  @username  = config['username']
end

Class Method Details

.run(*args) ⇒ Object



27
28
29
# File 'lib/pori/commands.rb', line 27

def self.run(*args)
  self.new(*args).run
end

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pori/commands.rb', line 35

def create
  endpoint = 'https://api.bitbucket.org/1.0/repositories/'

  @options.merge!(
    { body:
      { name: @repo, scm: "git", is_private: "true" }
    }
  )
  response = HTTParty.post(endpoint, @options)

  if response.code.to_i == 200
    puts "Successfully created."
    puts "git remote add origin ssh://[email protected]/#{@username}/#{@repo}.git"
    system "git remote add origin ssh://[email protected]/#{@username}/#{@repo}.git"
  else
    $stdout.puts "Something was wrong... o_O"
    $stdout.puts
    $stdout.puts response
  end
end

#deleteObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pori/commands.rb', line 56

def delete
  if del_flags
    endpoint = "https://api.bitbucket.org/1.0/repositories/#{@username}/#{@repo}"
    response = HTTParty.delete(endpoint, @options)
    if response.code.to_i == 204
      puts "Successfully deleted."
    else
      $stdout.puts "Something was wrong... o_O"
      $stdout.puts
      $stdout.puts response
    end
  else
    puts "Canceled."
  end
end

#runObject



31
32
33
# File 'lib/pori/commands.rb', line 31

def run
  self.send(@command)
end