octopush 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gictocat.rb +54 -0
  3. data/lib/octopush.rb +27 -36
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe2ef05c127543a8644c954e3cd94a7bc84a577c
4
- data.tar.gz: f820363c56e43fbe2ce367b9f9e7505e440bd22d
3
+ metadata.gz: f4dda158a0983deb8a132eb47a962062d3752934
4
+ data.tar.gz: cded430ac329f0c3c7ef8298ef7e965686714090
5
5
  SHA512:
6
- metadata.gz: 9529e58a02413094e68fca3e6dba6f4dea6588f831fa685ff2e45ee044b9025f82dcffb65912161bbbae5040666c3a6929aca2d40ca297ef4f3e04f8b2fc516f
7
- data.tar.gz: c41d719d65fcbecc7ca5d2644cda43f8a853a24dca7a8a4af04431f3115d885c4b6852a6ebd10d4374f1dde189a6e974ee05255791a146c9d0ab07b7e371e54c
6
+ metadata.gz: 142a63650d5abb430a0e1ea93ab887233e432d84d2a3d22c8ae0009b6e55bbf18e5c370e9ab4c7a57f1097884added5cef8f2edf76b3a3afe26ed46b70c155a0
7
+ data.tar.gz: 7a6f128310f5f87b92e81ae3edf665818d1f52870d0693a1934b949ec4ab7aa05b081e04f5ad349c68dc609983267486745a46e0669f68ad881fc8e6423ec15f
data/lib/gictocat.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'colorize'
2
+ require 'github_api'
3
+
4
+ # mix in model for very simple github repo manipulation
5
+ # requires class to respond to repository name
6
+ module Gictocat
7
+
8
+ def initialize_repo(repository_name = repository_name)
9
+ puts "#{cyan_arrow} Initializing repo in '#{repository_name}'"
10
+ # re-initializing existing repos is safe:
11
+ # http://stackoverflow.com/questions/5149694/does-running-git-init-twice-initialize-a-repository-or-reinitialize-an-existing
12
+ `git init #{repository_name}`
13
+ end
14
+
15
+ def add_and_commit_readme
16
+ puts "#{cyan_arrow} Touching and committing README.md"
17
+ FileUtils.touch('README.md')
18
+ `git add README.md`
19
+ `git commit -m 'add README.md (via octopush)'`
20
+ end
21
+
22
+ def push_to_github
23
+ create_repo_on_github
24
+ add_github_remote
25
+ push_repo
26
+ end
27
+
28
+ def create_repo_on_github
29
+ puts "#{cyan_arrow} Creating repo '#{repository_name}' on GitHub"
30
+ github_user.repos.create(name: repository_name)
31
+ end
32
+
33
+ def add_github_remote(remote_name = 'origin')
34
+ puts "#{cyan_arrow} Adding GitHub as a remote"
35
+ `git remote add #{remote_name} https://github.com/#{configuration['username']}/#{repository_name}.git`
36
+ end
37
+
38
+ def push_repo
39
+ puts "#{cyan_arrow} Pushing repo to GitHub"
40
+ `git push -u origin master`
41
+ end
42
+
43
+ def github_user
44
+ @github_user ||= Github.new({
45
+ login: username,
46
+ password: password
47
+ })
48
+ end
49
+
50
+ def cyan_arrow
51
+ '==>'.colorize(:cyan)
52
+ end
53
+
54
+ end
data/lib/octopush.rb CHANGED
@@ -1,53 +1,50 @@
1
1
  require 'thor'
2
2
  require 'fileutils'
3
3
  require 'colorize'
4
- require 'github_api'
4
+ require_relative 'gictocat'
5
5
 
6
6
  CONFIGURATION_FILE = (ENV['HOME'] + '/.octopushrc')
7
7
 
8
8
  class Octopush < Thor
9
9
 
10
+ include Gictocat
11
+
10
12
  desc "octopush REPOSITORY_NAME", "uploads REPOSITORY_NAME to github (creates an empty one if needed)"
11
13
  def octopush(repository_name)
12
14
  @repository_name = repository_name
13
-
14
- # re-initializing existing repos is safe:
15
- # http://stackoverflow.com/questions/5149694/does-running-git-init-twice-initialize-a-repository-or-reinitialize-an-existing
16
- `git init #{repository_name}`
17
-
15
+ initialize_repo
18
16
  Dir.chdir("./#{repository_name}")
19
- FileUtils.touch('README.md')
20
- `git add README.md`
21
- `git commit -m 'add README.md (via octopush)'`
22
- create_on_github
23
- add_github_remote
24
- push_repo
17
+ add_and_commit_readme
18
+ push_to_github
19
+ end
20
+
21
+ desc "create_config", "Creates an empty octopush configuration in ~/.octopushrc"
22
+ def create_config
23
+ create_empty_configuration
25
24
  end
26
25
 
27
26
  private
28
27
 
29
- def create_on_github
30
- github_user.repos.create(name: repository_name)
28
+ def repository_name
29
+ @repository_name
31
30
  end
32
31
 
33
- def add_github_remote(remote_name = 'origin')
34
- `git remote add #{remote_name} https://github.com/#{configuration['username']}/#{repository_name}.git`
32
+ def username
33
+ return configuration['username'] if configuration['username']
34
+ ask "Github Username:"
35
35
  end
36
36
 
37
- def push_repo
38
- `git push -u origin master`
37
+ def password
38
+ return configuration['password'] if configuration['password']
39
+ ask("GitHub Password:", :echo => false)
39
40
  end
40
41
 
41
42
  def configuration
42
- @configuration ||= load_configuration
43
- end
44
-
45
- def load_configuration
46
43
  begin
47
- YAML.load(File.read(CONFIGURATION_FILE))
44
+ @configuration ||= YAML.load(File.read(CONFIGURATION_FILE))
48
45
  rescue
49
- create_empty_configuration
50
- exit
46
+ puts "#{red_arrow} Run octopush create_config for storing credentials"
47
+ return @configuration = {} # an empty configuration..
51
48
  end
52
49
  end
53
50
 
@@ -55,22 +52,16 @@ class Octopush < Thor
55
52
  configuration ="username: <your_username>\npassword: <your_password>"
56
53
  File.open(CONFIGURATION_FILE, 'wb') { |f| f.write(configuration) }
57
54
 
58
- puts ('*' * 50).colorize(:red)
59
- puts "No configuration found!".colorize(:red)
55
+ puts "#{red_arrow} No configuration found!"
60
56
  puts "Initialized configuration file in ~/.octopushrc"
61
- puts ".. go edit it"
62
- puts ('*' * 50).colorize(:red)
63
57
  end
64
58
 
65
- def repository_name
66
- @repository_name
59
+ def red_arrow
60
+ '==>'.colorize(:red)
67
61
  end
68
62
 
69
- def github_user
70
- @github_user ||= Github.new({
71
- login: configuration['username'],
72
- password: configuration['password']
73
- })
63
+ def cyan_arrow
64
+ '==>'.colorize(:cyan)
74
65
  end
75
66
 
76
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martino Visintin
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - lib/octopush.rb
63
+ - lib/gictocat.rb
63
64
  - bin/octopush
64
65
  homepage: https://github.com/vise890/octopush
65
66
  licenses: