octonaut 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,7 +39,7 @@ GLOBAL OPTIONS
39
39
  -u, --login=arg - GitHub login (default: none)
40
40
 
41
41
  COMMANDS
42
- archive_link - Get repository tarball or zipball archive URL
42
+ archive-link - Get repository tarball or zipball archive URL
43
43
  authorize - Create and store an API token using username and password
44
44
  browse - Browse resource on github.com
45
45
  contents - Get repository contents
@@ -56,9 +56,17 @@ COMMANDS
56
56
  repo, repository - Display details for a repository
57
57
  repos, repositories - List repositories for a user or organization
58
58
  scopes - List scopes for a token
59
+ star - Star a repository
60
+ stargazers - List stargazers
61
+ starred - List or check starred repositories for a user
62
+ subscribe - Subscribe to a repository
63
+ subscribers - List subscribers for a repository
64
+ subscriptions - List user repository subscriptions
59
65
  tokens, authorizations - Manage tokens
60
66
  unfollow - Unfollow a user
61
- user, whois - View profile for a user
67
+ unstar - Unstar a repository
68
+ unsubscribe - Unsubscribe to a repository
69
+ user, whois - Manage users
62
70
  ```
63
71
 
64
72
  View a user's profile:
@@ -138,7 +146,7 @@ $ octonaut markdown "# Header #"
138
146
  ```
139
147
  Convert markdown using STDIN
140
148
  ```
141
- $ echo "Fixed in #3 " | be bin/octonaut markdown -c pengwynn/octonaut
149
+ $ echo "Fixed in #3 " | octonaut markdown -c pengwynn/octonaut
142
150
  <p>Fixed in <a href="https://github.com/pengwynn/octonaut/issues/3" class="issue-link" title="authorize command">#3</a> </p>"
143
151
  ```
144
152
 
@@ -147,7 +155,7 @@ $ echo "Fixed in #3 " | be bin/octonaut markdown -c pengwynn/octonaut
147
155
  ## Extend with plugins
148
156
 
149
157
  Octonaut makes it simple to extend the CLI with new commands just by adding
150
- some Ruby files to `~/.octonaut/plugins`:
158
+ some Ruby files to `~/.octonaut_plugins`:
151
159
 
152
160
  ```
153
161
  $ cat ~/.octonaut_plugins/test.rb
@@ -5,12 +5,14 @@ require 'launchy'
5
5
  require 'octokit'
6
6
  require 'octonaut/printer'
7
7
  require 'octonaut/helpers'
8
+ require 'octonaut/utils'
8
9
  require 'octonaut/version'
9
10
 
10
11
  module Octonaut
11
12
  extend GLI::App
12
13
  extend Octonaut::Printer
13
14
  extend Octonaut::Helpers
15
+ extend Octonaut::Utils
14
16
 
15
17
  def self.config_path
16
18
  path = if ENV['OCTONAUT_ENV'] == 'TEST'
@@ -0,0 +1,126 @@
1
+ module Octonaut
2
+
3
+
4
+ desc "List or check starred repositories for a user"
5
+ arg_name 'login or repository', :optional
6
+ command :starred do |c|
7
+
8
+ c.desc "Sort repos by: created, updated"
9
+ c.flag :sort
10
+
11
+ c.desc "Sort direction: asc or desc"
12
+ c.flag :direction
13
+
14
+ c.action do |global,options,args|
15
+ target = args.shift
16
+ if target && target[/\//]
17
+ user, repo = target.split("/")
18
+ login = @client.login
19
+ else
20
+ login = target || @client.login
21
+ end
22
+
23
+ if repo
24
+ # TODO: Fix this upstream to take a single arg
25
+ result = @client.starred?(user, repo) ? "" : "not "
26
+ puts "#{login} has #{result}starred #{user}/#{repo}"
27
+ elsif login.nil?
28
+ puts "Please authenticate or provide a GitHub login"
29
+ else
30
+ opts = Octonaut.supplied_flags(options)
31
+ ls_repos @client.starred(login, opts)
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ desc "Star a repository"
38
+ arg_name 'repository'
39
+ command :star do |c|
40
+ c.action do |global,options,args|
41
+ repo = args.shift
42
+ raise ArgumentError.new "Repository required" if repo.nil?
43
+
44
+ puts "Starred #{repo}" if @client.star(repo)
45
+ end
46
+ end
47
+
48
+ desc "Unstar a repository"
49
+ arg_name 'repository'
50
+ command :unstar do |c|
51
+ c.action do |global,options,args|
52
+ repo = args.shift
53
+ raise ArgumentError.new "Repository required" if repo.nil?
54
+
55
+ puts "Unstarred #{repo}" if @client.unstar(repo)
56
+ end
57
+ end
58
+
59
+ desc "List stargazers"
60
+ arg_name 'repository'
61
+ command :stargazers do |c|
62
+ c.action do |global,options,args|
63
+ repo = args.shift
64
+ raise ArgumentError.new "Repository required" if repo.nil?
65
+
66
+ ls_users @client.stargazers(repo)
67
+ end
68
+ end
69
+
70
+ desc "Subscribe to a repository"
71
+ arg_name "repository"
72
+ command :subscribe do |c|
73
+ c.desc "Ignore notifications"
74
+ c.switch [:i, :ignored]
75
+ c.action do |global,options,args|
76
+ repo = args.shift
77
+ raise ArgumentError.new "Repository required" if repo.nil?
78
+
79
+ opts = Octonaut.supplied_flags(options).select {|k, v| k == 'ignored'}
80
+ if @client.update_subscription(repo, opts)
81
+ message = "Subscribed to #{repo}"
82
+ message << " and ignored" if opts['ignored']
83
+ puts message
84
+ else
85
+ puts "Could not subscribe to #{repo}"
86
+ end
87
+ end
88
+ end
89
+
90
+ desc "Unsubscribe to a repository"
91
+ arg_name "repository"
92
+ command :unsubscribe do |c|
93
+ c.action do |global,options,args|
94
+ repo = args.shift
95
+ raise ArgumentError.new "Repository required" if repo.nil?
96
+
97
+ if @client.delete_subscription(repo)
98
+ puts "Unsubscribed to #{repo}"
99
+ else
100
+ puts "Could not unsubscribe to #{repo}"
101
+ end
102
+ end
103
+ end
104
+
105
+ desc "List subscribers for a repository"
106
+ arg_name "repository"
107
+ command :subscribers do |c|
108
+ c.action do |global,options,args|
109
+ repo = args.shift
110
+ raise ArgumentError.new "Repository required" if repo.nil?
111
+
112
+ ls_users @client.subscribers(repo)
113
+ end
114
+ end
115
+
116
+ desc "List user repository subscriptions"
117
+ arg_name "user", :optional
118
+ command :subscriptions do |c|
119
+ c.action do |global,options,args|
120
+ user = args.shift || @client.login
121
+ raise ArgumentError.new "User or authentication required" if user.nil?
122
+ ls_repos @client.subscriptions(user)
123
+ end
124
+ end
125
+
126
+ end
@@ -49,7 +49,7 @@ module Octonaut
49
49
 
50
50
  desc "Get repository tarball or zipball archive URL"
51
51
  arg_name "repo"
52
- command :archive_link do |c|
52
+ command 'archive-link' do |c|
53
53
  c.desc "Archive format"
54
54
  c.default_value "tar"
55
55
  c.flag [:f, :format]
@@ -7,25 +7,53 @@ module Octonaut
7
7
  end
8
8
  end
9
9
 
10
- desc "View profile for a user"
11
- arg_name 'login'
10
+ desc 'Manage users'
12
11
  command [:user, :whois] do |c|
13
- c.action do |global,options,args|
14
- login = args.shift
15
- begin
16
- user = @client.user login
17
- case user['type']
18
- when 'Organization'
19
- print_org_table user
20
- else
21
- print_user_table user
12
+ c.default_command :show
13
+ c.desc "View a user profile"
14
+ c.arg_name 'login'
15
+ c.command :show do |show|
16
+ show.action do |global,options,args|
17
+ login = args.shift
18
+ begin
19
+ user = @client.user login
20
+ case user['type']
21
+ when 'Organization'
22
+ print_org_table user
23
+ else
24
+ print_user_table user
25
+ end
26
+ rescue Octokit::NotFound
27
+ puts "User or organization #{login} not found"
28
+ end
29
+ end
30
+ end
31
+
32
+ c.desc "Update a user profile"
33
+ c.command :update do |update|
34
+
35
+ update.arg_name "Name", :optional
36
+ update.flag :name
37
+ update.arg_name "Email", :optional
38
+ update.flag :email
39
+ update.arg_name "Blog", :optional
40
+ update.flag :blog
41
+ update.arg_name "Company", :optional
42
+ update.flag :company
43
+ update.arg_name "Location", :optional
44
+ update.flag :location
45
+ update.arg_name "Hireable", :optional
46
+ update.switch :hireable
47
+ update.action do |global,options,args|
48
+ opts = Octonaut.supplied_flags(options)
49
+ if @client.update_user(opts)
50
+ puts "User profile updated"
22
51
  end
23
- rescue Octokit::NotFound
24
- puts "User or organization #{login} not found"
25
52
  end
26
53
  end
27
54
  end
28
55
 
56
+
29
57
  desc "View followers for a user"
30
58
  arg_name 'login', :optional
31
59
  command :followers do |c|
@@ -42,7 +42,7 @@ module Octonaut
42
42
  end
43
43
 
44
44
  def ls_repos(repos, options = {})
45
- repos.each {|r| puts r.name }
45
+ repos.each {|r| puts r.full_name }
46
46
  end
47
47
  end
48
48
  end
@@ -0,0 +1,9 @@
1
+ module Octonaut
2
+ module Utils
3
+
4
+ def supplied_flags(options = {})
5
+ options.dup.select {|k, v| k.is_a?(String) }
6
+ end
7
+
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Octonaut
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+
3
+ describe Octonaut do
4
+
5
+ context "stars" do
6
+
7
+ it "lists your starred repositories" do
8
+ request = stub_get("https://defunkt:il0veruby@api.github.com/users/defunkt/starred").
9
+ to_return(json_response("starred.json"))
10
+
11
+
12
+ Octonaut.run %w(-u defunkt -p il0veruby starred)
13
+ expect(request).to have_been_made
14
+
15
+ expect($stdout.string).to eq(fixture('starred.ls').read)
16
+ end
17
+
18
+ it "lists stars for a user" do
19
+ request = stub_get("https://api.github.com/users/pengwynn/starred").
20
+ to_return(json_response("starred.json"))
21
+
22
+
23
+ Octonaut.run %w(starred pengwynn)
24
+ expect(request).to have_been_made
25
+
26
+ expect($stdout.string).to eq(fixture('starred.ls').read)
27
+ end
28
+
29
+ it "requires a username to list stars" do
30
+ request = stub_get("https://api.github.com/users/pengwynn/starred").
31
+ to_return(json_response("starred.json"))
32
+
33
+ Octonaut.run %w(starred)
34
+ expect(request).to have_not_been_made
35
+
36
+ expect($stdout.string).to eq("Please authenticate or provide a GitHub login\n")
37
+ end
38
+
39
+ it "stars a repository" do
40
+ request = stub_put("https://defunkt:il0veruby@api.github.com/user/starred/defunkt/dotjs").
41
+ to_return(:status => 204)
42
+
43
+ Octonaut.run %w(-u defunkt -p il0veruby star defunkt/dotjs)
44
+ expect(request).to have_been_made
45
+
46
+ expect($stdout.string).to eq("Starred defunkt/dotjs\n")
47
+ end
48
+
49
+ it "unstars a repository" do
50
+ request = stub_delete("https://defunkt:il0veruby@api.github.com/user/starred/defunkt/dotjs").
51
+ to_return(:status => 204)
52
+
53
+ Octonaut.run %w(-u defunkt -p il0veruby unstar defunkt/dotjs)
54
+ expect(request).to have_been_made
55
+
56
+ expect($stdout.string).to eq("Unstarred defunkt/dotjs\n")
57
+ end
58
+
59
+ it "checks if you've starred a repository" do
60
+ request = stub_get("https://defunkt:il0veruby@api.github.com/user/starred/defunkt/dotjs").
61
+ to_return(:status => 204)
62
+
63
+ Octonaut.run %w(-u defunkt -p il0veruby starred defunkt/dotjs)
64
+ expect(request).to have_been_made
65
+
66
+ expect($stdout.string).to eq("defunkt has starred defunkt/dotjs\n")
67
+ end
68
+
69
+ it "indicates a user has not starred a repo" do
70
+ request = stub_get("https://defunkt:il0veruby@api.github.com/user/starred/defunkt/dotjs").
71
+ to_return(:status => 404)
72
+
73
+ Octonaut.run %w(-u defunkt -p il0veruby starred defunkt/dotjs)
74
+ expect(request).to have_been_made
75
+
76
+ expect($stdout.string).to eq("defunkt has not starred defunkt/dotjs\n")
77
+ end
78
+
79
+ it "lists stargazers for a repository" do
80
+ request = stub_get("/repos/defunkt/dotjs/stargazers").
81
+ to_return(json_response("users.json"))
82
+
83
+ Octonaut.run %w(stargazers defunkt/dotjs)
84
+
85
+ expect(request).to have_been_made
86
+ expect($stdout.string).to eq(fixture('users.ls').read)
87
+ end
88
+
89
+ end
90
+
91
+ context "subscriptions" do
92
+
93
+ it "subscribes to a repository" do
94
+ request = stub_put("https://defunkt:il0veruby@api.github.com/repos/defunkt/dotjs/subscription").
95
+ to_return(:status => 204)
96
+
97
+ Octonaut.run %w(-u defunkt -p il0veruby subscribe defunkt/dotjs)
98
+ expect(request).to have_been_made
99
+ expect($stdout.string).to eq("Subscribed to defunkt/dotjs\n")
100
+ end
101
+
102
+ it "marks a subscription as ignored" do
103
+ request = stub_put("https://defunkt:il0veruby@api.github.com/repos/defunkt/dotjs/subscription").
104
+ with(:body => {:ignored => true}).
105
+ to_return(:status => 204)
106
+
107
+ Octonaut.run %w(-u defunkt -p il0veruby subscribe -i defunkt/dotjs)
108
+ expect(request).to have_been_made
109
+ expect($stdout.string).to eq("Subscribed to defunkt/dotjs and ignored\n")
110
+ end
111
+
112
+ it "unsubscribes to a repository" do
113
+ request = stub_delete("https://defunkt:il0veruby@api.github.com/repos/defunkt/dotjs/subscription").
114
+ to_return(:status => 204)
115
+
116
+ Octonaut.run %w(-u defunkt -p il0veruby unsubscribe defunkt/dotjs)
117
+ expect(request).to have_been_made
118
+ expect($stdout.string).to eq("Unsubscribed to defunkt/dotjs\n")
119
+ end
120
+
121
+ it "lists subscribers for a repository" do
122
+ request = stub_get("https://api.github.com/repos/defunkt/dotjs/subscribers").
123
+ to_return(json_response("subscribers.json"))
124
+
125
+ Octonaut.run %w(subscribers defunkt/dotjs)
126
+ expect(request).to have_been_made
127
+ expect($stdout.string).to eq(fixture('subscribers.ls').read)
128
+ end
129
+
130
+ it "lists subscribed repositories" do
131
+ request = stub_get("https://defunkt:il0veruby@api.github.com/users/defunkt/subscriptions").
132
+ to_return(json_response("repositories.json"))
133
+
134
+ Octonaut.run %w(-u defunkt -p il0veruby subscriptions)
135
+ expect(request).to have_been_made
136
+ expect($stdout.string).to eq(fixture('repositories.ls').read)
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -54,7 +54,7 @@ describe Octonaut do
54
54
  with("pengwynn/octonaut", :format => "zipball", :ref => "master").
55
55
  and_return(url)
56
56
 
57
- Octonaut.run %w(archive_link -f zip pengwynn/octonaut)
57
+ Octonaut.run %w(archive-link -f zip pengwynn/octonaut)
58
58
  expect($stdout.string).to eq(url)
59
59
 
60
60
  end
@@ -1,30 +1,30 @@
1
- ace
2
- acts_as_textiled
3
- ambition
4
- ambitious_activeldap
5
- ambitious_activerecord
6
- barefootexamples
7
- body_matcher
8
- burn
9
- cache_fu
10
- cheat
11
- cheat.el
12
- choice
13
- cijoe
14
- coffee-mode
15
- colored
16
- currency_converter
17
- defunkt.github.com
18
- djangode
19
- dodgeball.github.com
20
- dotenv
21
- dotjs
22
- electron-wordwrap
23
- emacs
24
- email_reply_parser
25
- evilbot
26
- exception_logger
27
- facebox
28
- faceup
29
- fakefs
30
- fixture_scenarios_builder
1
+ defunkt/ace
2
+ defunkt/acts_as_textiled
3
+ defunkt/ambition
4
+ defunkt/ambitious_activeldap
5
+ defunkt/ambitious_activerecord
6
+ defunkt/barefootexamples
7
+ defunkt/body_matcher
8
+ defunkt/burn
9
+ defunkt/cache_fu
10
+ defunkt/cheat
11
+ defunkt/cheat.el
12
+ defunkt/choice
13
+ defunkt/cijoe
14
+ defunkt/coffee-mode
15
+ defunkt/colored
16
+ defunkt/currency_converter
17
+ defunkt/defunkt.github.com
18
+ defunkt/djangode
19
+ defunkt/dodgeball.github.com
20
+ defunkt/dotenv
21
+ defunkt/dotjs
22
+ defunkt/electron-wordwrap
23
+ defunkt/emacs
24
+ defunkt/email_reply_parser
25
+ defunkt/evilbot
26
+ defunkt/exception_logger
27
+ defunkt/facebox
28
+ defunkt/faceup
29
+ defunkt/fakefs
30
+ defunkt/fixture_scenarios_builder