github_cli 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/CHANGELOG.md +9 -0
  2. data/Gemfile.lock +3 -3
  3. data/README.md +30 -0
  4. data/bin/ghc +13 -1
  5. data/features/repositories.feature +9 -0
  6. data/github_cli.gemspec +1 -1
  7. data/lib/github_cli.rb +2 -0
  8. data/lib/github_cli/api.rb +7 -2
  9. data/lib/github_cli/apis.rb +4 -0
  10. data/lib/github_cli/apis/authorization.rb +20 -10
  11. data/lib/github_cli/apis/blob.rb +8 -4
  12. data/lib/github_cli/apis/collaborator.rb +34 -0
  13. data/lib/github_cli/apis/commit.rb +8 -4
  14. data/lib/github_cli/apis/download.rb +20 -10
  15. data/lib/github_cli/apis/fork.rb +8 -4
  16. data/lib/github_cli/apis/gist.rb +70 -0
  17. data/lib/github_cli/apis/hook.rb +24 -12
  18. data/lib/github_cli/apis/issue.rb +40 -0
  19. data/lib/github_cli/apis/key.rb +20 -10
  20. data/lib/github_cli/apis/label.rb +40 -18
  21. data/lib/github_cli/apis/pull_request.rb +32 -16
  22. data/lib/github_cli/apis/reference.rb +20 -10
  23. data/lib/github_cli/apis/repository.rb +36 -19
  24. data/lib/github_cli/apis/tag.rb +8 -4
  25. data/lib/github_cli/apis/tree.rb +8 -4
  26. data/lib/github_cli/apis/watching.rb +20 -10
  27. data/lib/github_cli/command.rb +19 -0
  28. data/lib/github_cli/commands.rb +2 -0
  29. data/lib/github_cli/commands/authorizations.rb +5 -5
  30. data/lib/github_cli/commands/blobs.rb +2 -2
  31. data/lib/github_cli/commands/collaborators.rb +37 -0
  32. data/lib/github_cli/commands/commits.rb +2 -2
  33. data/lib/github_cli/commands/downloads.rb +5 -5
  34. data/lib/github_cli/commands/forks.rb +2 -2
  35. data/lib/github_cli/commands/gists.rb +103 -0
  36. data/lib/github_cli/commands/hooks.rb +6 -6
  37. data/lib/github_cli/commands/issues.rb +67 -18
  38. data/lib/github_cli/commands/keys.rb +5 -5
  39. data/lib/github_cli/commands/labels.rb +8 -8
  40. data/lib/github_cli/commands/pull_requests.rb +8 -8
  41. data/lib/github_cli/commands/references.rb +5 -5
  42. data/lib/github_cli/commands/repositories.rb +20 -20
  43. data/lib/github_cli/commands/tags.rb +2 -2
  44. data/lib/github_cli/commands/trees.rb +2 -2
  45. data/lib/github_cli/commands/watching.rb +5 -5
  46. data/lib/github_cli/errors.rb +33 -2
  47. data/lib/github_cli/formatters.rb +8 -0
  48. data/lib/github_cli/formatters/csv.rb +39 -0
  49. data/lib/github_cli/formatters/table.rb +36 -0
  50. data/lib/github_cli/subcommands.rb +6 -0
  51. data/lib/github_cli/terminal.rb +25 -0
  52. data/lib/github_cli/util.rb +35 -0
  53. data/lib/github_cli/version.rb +1 -1
  54. data/spec/github_cli/util_spec.rb +37 -0
  55. metadata +26 -13
@@ -2,6 +2,7 @@
2
2
 
3
3
  module GithubCLI
4
4
  class Command < Thor
5
+ include Thor::Actions
5
6
 
6
7
  API_CLASSES = %w(
7
8
  c_l_i
@@ -15,6 +16,24 @@ module GithubCLI
15
16
 
16
17
  class Comm < Struct.new(:namespace, :name, :desc, :usage); end
17
18
 
19
+
20
+ def self.output_formats
21
+ {
22
+ 'csv' => nil,
23
+ 'json' => nil,
24
+ 'pretty' => nil,
25
+ 'table' => nil
26
+ }
27
+ end
28
+
29
+ map "ls" => :list,
30
+ "del" => :delete
31
+
32
+ class_option :format, :type => :string, :aliases => '-f',
33
+ :default => 'table',
34
+ :banner => output_formats.keys.join('|'),
35
+ :desc => "Format of the output"
36
+
18
37
  def self.banner(task, namespace=true, subcommand=true)
19
38
  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
20
39
  end
@@ -4,9 +4,11 @@ module GithubCLI
4
4
  module Commands
5
5
  autoload :Authorizations, 'github_cli/commands/authorizations'
6
6
  autoload :Blobs, 'github_cli/commands/blobs'
7
+ autoload :Collaborators, 'github_cli/commands/collaborators'
7
8
  autoload :Commits, 'github_cli/commands/commits'
8
9
  autoload :Downloads, 'github_cli/commands/downloads'
9
10
  autoload :Forks, 'github_cli/commands/forks'
11
+ autoload :Gists, 'github_cli/commands/gists'
10
12
  autoload :Hooks, 'github_cli/commands/hooks'
11
13
  autoload :Issues, 'github_cli/commands/issues'
12
14
  autoload :Keys, 'github_cli/commands/keys'
@@ -9,14 +9,14 @@ module GithubCLI
9
9
  method_option :params, :type => :hash, :default => {},
10
10
  :desc => 'Additional request parameters e.i per_page:100'
11
11
  def list
12
- Authorization.all options[:params]
12
+ Authorization.all options[:params], options[:formats]
13
13
  end
14
14
 
15
15
  desc 'get <id>', 'Get a single authorization'
16
16
  method_option :params, :type => :hash, :default => {},
17
17
  :desc => 'Additional request parameters e.i per_page:100'
18
18
  def get(id)
19
- Authorization.get id, options[:params]
19
+ Authorization.get id, options[:params], options[:format]
20
20
  end
21
21
 
22
22
  desc 'create <user> <repo>', 'Create a new authorization'
@@ -30,7 +30,7 @@ module GithubCLI
30
30
  method_option :params, :type => :hash, :default => {},
31
31
  :desc => 'Additonal request parameters e.i per_page:100'
32
32
  def create
33
- Authorization.create options[:params]
33
+ Authorization.create options[:params], options[:format]
34
34
  end
35
35
 
36
36
  desc 'update <id>', 'Update an existing authorization'
@@ -44,14 +44,14 @@ module GithubCLI
44
44
  note_url - Optional string - A URL to remind you what the OAuth token is for.
45
45
  DESC
46
46
  def update(id)
47
- Authorization.update id, options[:params]
47
+ Authorization.update id, options[:params], options[:format]
48
48
  end
49
49
 
50
50
  desc 'delete <id>', 'Delete an authorization'
51
51
  method_option :params, :type => :hash, :default => {},
52
52
  :desc => 'Additonal request parameters e.i per_page:100'
53
53
  def delete(id)
54
- Authorization.delete id, options[:params]
54
+ Authorization.delete id, options[:params], options[:format]
55
55
  end
56
56
 
57
57
  end # Authorizations
@@ -9,7 +9,7 @@ module GithubCLI
9
9
  method_option :params, :type => :hash, :default => {},
10
10
  :desc => 'Additonal request parameters e.i per_page:100'
11
11
  def get(user, repo, sha)
12
- Blob.get user, repo, sha, options[:params]
12
+ Blob.get user, repo, sha, options[:params], options[:format]
13
13
  end
14
14
 
15
15
  desc 'create <user> <repo>', 'Create a new Blob'
@@ -22,7 +22,7 @@ module GithubCLI
22
22
  method_option :params, :type => :hash, :default => {},
23
23
  :desc => 'Additonal request parameters e.i per_page:100'
24
24
  def create(user, repo)
25
- Blob.create user, repo, options[:params]
25
+ Blob.create user, repo, options[:params], options[:format]
26
26
  end
27
27
 
28
28
  end # Blobs
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ class Commands::Collaborators < Command
5
+
6
+ namespace :collab
7
+
8
+ desc 'list <user> <repo>', 'Lists collaborators'
9
+ method_option :params, :type => :hash, :default => {},
10
+ :desc => 'Additional request parameters e.i per_page:100'
11
+ def list(user, repo)
12
+ Collaborator.all user, repo, options[:params], options[:format]
13
+ end
14
+
15
+ desc 'add <user> <repo> <collab>', 'Add a collaborator'
16
+ method_option :params, :type => :hash, :default => {},
17
+ :desc => 'Additional request parameters e.i per_page:100'
18
+ def add(user, repo, collab)
19
+ Collaborator.add user, repo, collab, options[:params], options[:format]
20
+ end
21
+
22
+ desc 'collab <user> <repo> <collab>', 'Checks if user is a collaborator on a given repo'
23
+ method_option :params, :type => :hash, :default => {},
24
+ :desc => 'Additional request parameters e.i per_page:100'
25
+ def collab(user, repo, collab)
26
+ Collaborator.collaborator? user, repo, collab, options[:params], options[:format]
27
+ end
28
+
29
+ desc 'remove <user> <repo> <id>', 'Remove a collaborator'
30
+ method_option :params, :type => :hash, :default => {},
31
+ :desc => 'Additonal request parameters e.i per_page:100'
32
+ def remove(user, repo, collab)
33
+ Collaborator.remove user, repo, collab, options[:params]. options[:format]
34
+ end
35
+
36
+ end # Collaborators
37
+ end # GithubCLI
@@ -9,7 +9,7 @@ module GithubCLI
9
9
  method_option :params, :type => :hash, :default => {},
10
10
  :desc => 'Additonal request parameters e.i per_page:100'
11
11
  def get(user, repo, sha)
12
- Commit.get user, repo, sha, options[:params]
12
+ Commit.get user, repo, sha, options[:params], options[:format]
13
13
  end
14
14
 
15
15
  desc 'create <user> <repo>', 'Create a Commit'
@@ -34,7 +34,7 @@ module GithubCLI
34
34
  method_option :params, :type => :hash, :default => {},
35
35
  :desc => 'Additonal request parameters e.i per_page:100'
36
36
  def create(user, repo)
37
- Commit.create user, repo, options[:params]
37
+ Commit.create user, repo, options[:params], options[:format]
38
38
  end
39
39
 
40
40
  end # Commit
@@ -9,14 +9,14 @@ module GithubCLI
9
9
  method_option :params, :type => :hash, :default => {},
10
10
  :desc => 'Additional request parameters e.i per_page:100'
11
11
  def list(user, repo)
12
- Download.all user, repo, options[:params]
12
+ Download.all user, repo, options[:params], options[:format]
13
13
  end
14
14
 
15
15
  desc 'get <user> <repo> <id>', 'Get a download'
16
16
  method_option :params, :type => :hash, :default => {},
17
17
  :desc => 'Additional request parameters e.i per_page:100'
18
18
  def get(user, repo, id)
19
- Download.get user, repo, id, options[:params]
19
+ Download.get user, repo, id, options[:params], options[:format]
20
20
  end
21
21
 
22
22
  desc 'create <user> <repo>', 'Create a new download resource'
@@ -36,7 +36,7 @@ module GithubCLI
36
36
  method_option :params, :type => :hash, :default => {},
37
37
  :desc => 'Additonal request parameters e.i per_page:100'
38
38
  def create(user, repo)
39
- Download.create user, repo, options[:params]
39
+ Download.create user, repo, options[:params], options[:format]
40
40
  end
41
41
 
42
42
  desc 'upload <resource> <filename>', 'Upload resource to s3'
@@ -53,14 +53,14 @@ module GithubCLI
53
53
  filename - Required filename, a path to a file location. \n
54
54
  DESC
55
55
  def upload(resource, filename)
56
- Download.upload resource, filename
56
+ Download.upload resource, filename, options[:format]
57
57
  end
58
58
 
59
59
  desc 'delete <user> <repo> <id>', 'Delete a download'
60
60
  method_option :params, :type => :hash, :default => {},
61
61
  :desc => 'Additonal request parameters e.i per_page:100'
62
62
  def delete(user, repo, id)
63
- Download.delete user, repo, id, options[:params]
63
+ Download.delete user, repo, id, options[:params], options[:format]
64
64
  end
65
65
 
66
66
  end # Downloads
@@ -22,7 +22,7 @@ module GithubCLI
22
22
  if options[:sort]
23
23
  options[:params]['sort'] = options[:sort]
24
24
  end
25
- Fork.all user, repo, options[:params]
25
+ Fork.all user, repo, options[:params], options[:format]
26
26
  end
27
27
 
28
28
  desc 'create <user> <repo>', 'Create a new fork'
@@ -34,7 +34,7 @@ module GithubCLI
34
34
  if options[:org]
35
35
  options[:params]['org'] = options[:org]
36
36
  end
37
- Fork.create user, repo, options[:params]
37
+ Fork.create user, repo, options[:params], options[:format]
38
38
  end
39
39
 
40
40
  end # Forks
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ class Commands::Gists < Command
5
+
6
+ namespace :gist
7
+
8
+ desc 'list', 'List all gists'
9
+ method_option :user, :type => :string, :aliases => ["-u"],
10
+ :desc => 'List a <user> gists',
11
+ :banner => '<user>'
12
+ method_option :starred, :type => :boolean, :aliases => ["-s"],
13
+ :default => false,
14
+ :desc => 'List the authenticated users starred gists'
15
+ method_option :params, :type => :hash, :default => {},
16
+ :desc => 'Additonal request parameters e.i per_page:100'
17
+ def list
18
+ Gist.starred if options[:starred]
19
+
20
+ if options[:user]
21
+ options[:params]['user'] = options[:user]
22
+ end
23
+ Gist.all options[:params], options[:format]
24
+ end
25
+
26
+ desc 'get <id>', 'Get a single gist'
27
+ method_option :params, :type => :hash, :default => {},
28
+ :desc => 'Additonal request parameters e.i per_page:100'
29
+ def get(id)
30
+ Gist.get id, options[:params], options[:format]
31
+ end
32
+
33
+ desc 'create', 'Create a gist'
34
+ method_option :params, :type => :hash, :default => {},
35
+ :desc => 'Additonal request parameters e.i per_page:100'
36
+ long_desc <<-DESC
37
+ Create a gist
38
+
39
+ Parameters
40
+
41
+ description - Optional string\n
42
+ public - Required boolean\n
43
+ files - Required hash - Files that make up this gist. The key of which should be a required string filename and the value another required hash with parameters: \n
44
+ content - Required string - File contents.
45
+ DESC
46
+ def create
47
+ Gist.create options[:params], options[:format]
48
+ end
49
+
50
+ desc 'edit <id>', 'Edit a gist'
51
+ method_option :params, :type => :hash, :default => {},
52
+ :desc => 'Additonal request parameters e.i per_page:100'
53
+ long_desc <<-DESC
54
+ Edit a gist
55
+
56
+ Parameters
57
+
58
+ description - Optional string\n
59
+ files - Optional hash - Files that make up this gist. The key of which should be a optional string filename and the value another optional hash with parameters: \n
60
+ content - Updated string - Update file contents.\n
61
+ filename - Optional string - New name for this file.\n
62
+ DESC
63
+ def edit(id)
64
+ Gist.edit id, options[:params], options[:format]
65
+ end
66
+
67
+ desc 'star <id>', 'Star a gist'
68
+ method_option :params, :type => :hash, :default => {},
69
+ :desc => 'Additonal request parameters e.i per_page:100'
70
+ def star(id)
71
+ Gist.star id, options[:params], options[:format]
72
+ end
73
+
74
+ desc 'unstar <id>', 'Unstar a gist'
75
+ method_option :params, :type => :hash, :default => {},
76
+ :desc => 'Additonal request parameters e.i per_page:100'
77
+ def unstar(id)
78
+ Gist.unstar id, options[:params], options[:format]
79
+ end
80
+
81
+ desc 'starred <id>', 'Check if a gist is starred'
82
+ method_option :params, :type => :hash, :default => {},
83
+ :desc => 'Additonal request parameters e.i per_page:100'
84
+ def starred(id)
85
+ Gist.starred? id, options[:params], options[:format]
86
+ end
87
+
88
+ desc 'fork <id>', 'Fork a gist'
89
+ method_option :params, :type => :hash, :default => {},
90
+ :desc => 'Additonal request parameters e.i per_page:100'
91
+ def fork(id)
92
+ Gist.fork id, options[:params], options[:format]
93
+ end
94
+
95
+ desc 'delete <id>', 'Delete a gist'
96
+ method_option :params, :type => :hash, :default => {},
97
+ :desc => 'Additonal request parameters e.i per_page:100'
98
+ def delete(id)
99
+ Gist.delete id, options[:params], options[:format]
100
+ end
101
+
102
+ end # Gists
103
+ end # GithubCLI
@@ -9,14 +9,14 @@ module GithubCLI
9
9
  method_option :params, :type => :hash, :default => {},
10
10
  :desc => 'Additional request parameters e.i per_page:100'
11
11
  def list(user, repo)
12
- Hook.all user, repo, options[:params]
12
+ Hook.all user, repo, options[:params], options[:format]
13
13
  end
14
14
 
15
15
  desc 'get <user> <repo> <id>', 'Get a hook'
16
16
  method_option :params, :type => :hash, :default => {},
17
17
  :desc => 'Additional request parameters e.i per_page:100'
18
18
  def get(user, repo, id)
19
- Hook.get user, repo, id, options[:params]
19
+ Hook.get user, repo, id, options[:params], options[:format]
20
20
  end
21
21
 
22
22
  desc 'create <user> <repo>', 'Create a hook'
@@ -31,7 +31,7 @@ module GithubCLI
31
31
  method_option :params, :type => :hash, :default => {},
32
32
  :desc => 'Additonal request parameters e.i per_page:100'
33
33
  def create(user, repo)
34
- Hook.create user, repo, options[:params]
34
+ Hook.create user, repo, options[:params], options[:format]
35
35
  end
36
36
 
37
37
  desc 'edit <user> <repo> <id>', 'Edit a hook'
@@ -46,21 +46,21 @@ module GithubCLI
46
46
  active - Optional boolean - Determines whether the hook is actually triggered on pushes. \n
47
47
  DESC
48
48
  def edit(user, repo, id)
49
- Hook.edit user, repo, id, options[:params]
49
+ Hook.edit user, repo, id, options[:params], options[:format]
50
50
  end
51
51
 
52
52
  desc 'test <user> <repo> <id>', 'Test a hook'
53
53
  method_option :params, :type => :hash, :default => {},
54
54
  :desc => 'Additonal request parameters e.i per_page:100'
55
55
  def test(user, repo, id)
56
- Hook.test user, repo, id, options[:params]
56
+ Hook.test user, repo, id, options[:params], options[:format]
57
57
  end
58
58
 
59
59
  desc 'delete <user> <repo> <id>', 'Delete a hook'
60
60
  method_option :params, :type => :hash, :default => {},
61
61
  :desc => 'Additonal request parameters e.i per_page:100'
62
62
  def delete(user, repo, id)
63
- Hook.delete user, repo, id, options[:params]
63
+ Hook.delete user, repo, id, options[:params], options[:format]
64
64
  end
65
65
 
66
66
  end # Hooks
@@ -5,13 +5,13 @@ module GithubCLI
5
5
 
6
6
  namespace :issue
7
7
 
8
- method_option :params, :type => :hash
9
- desc 'list', 'Listing all issues'
10
- long_desc <<-TEXT
8
+ desc 'list', 'List all issues'
9
+ long_desc <<-DESC
11
10
  ghc issue list --params filter:'assigned', state:'open'
12
11
 
13
- Parameters\n
14
- filter\n
12
+ Parameters
13
+
14
+ filter\n
15
15
  * assigned: Issues assigned to you (default) \n
16
16
  * created: Issues assigned to you (default) \n
17
17
  * mentioned: Issues assigned to you (default)\n
@@ -21,27 +21,76 @@ module GithubCLI
21
21
  sort - created, updated, comments, default: created \n
22
22
  direction - asc, desc, default: desc \n
23
23
  since - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ \n
24
- TEXT
24
+ DESC
25
+ method_option :params, :type => :hash, :default => {}, :aliases => '-p',
26
+ :desc => 'Additonal request parameters e.i per_page:100'
25
27
  def list
26
- say "listing #{options[:params]}"
28
+ Issue.all options[:params], options[:format]
27
29
  end
28
30
 
29
- desc 'get <user>,<repo>', 'Get a single issue'
30
- method_option :number, :type => :numeric, :required => true
31
- def get(user, repo)
32
- say "#{user}"
31
+ desc 'repo <user> <repo>', 'List all issues for a repository'
32
+ long_desc <<-DESC
33
+ Parameters
34
+
35
+ milestone:\n
36
+ * Integer Milestone number\n
37
+ * none for Issues with no Milestone.\n
38
+ * * for Issues with any Milestone\n
39
+ state - open, closed, default: open \n
40
+ assignee:\n
41
+ * String User login\n
42
+ * none for Issues with no assigned User.\n
43
+ * * for Issues with any assigned User.\n
44
+ mentioned - String User login\n
45
+ labels - String list of comma separated Label names. Example: bug,ui,@high\n
46
+ sort - created, updated, comments, default: created\n
47
+ direction - asc, desc, default: desc\n
48
+ since - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ\n
49
+ DESC
50
+ method_option :params, :type => :hash, :default => {}, :aliases => '-p',
51
+ :desc => 'Additonal request parameters e.i per_page:100'
52
+ def repo(user, repo)
53
+ Issue.all user, repo, options[:params], options[:format]
33
54
  end
34
55
 
35
- desc 'create <user>,<repo>', 'Create an issue.'
36
- method_option :params, :type => :hash
56
+ desc 'get <user> <repo> <id>', 'Get a single issue'
57
+ method_option :params, :type => :hash, :default => {}, :aliases => '-p',
58
+ :desc => 'Additonal request parameters e.i per_page:100'
59
+ def get(user, repo, id)
60
+ Issue.get user, repo, id, options[:params], options[:format]
61
+ end
62
+
63
+ desc 'create <user> <repo>', 'Create an issue.'
64
+ long_desc <<-DESC
65
+ Parameters
66
+
67
+ title - Required string\n
68
+ body - Optional string\n
69
+ assignee - Optional string - Login for the user that this issue should be assigned to.\n
70
+ milestone - Optional number - Milestone to associate this issue with\n
71
+ labels - Optional array of strings - Labels to associate with this issue
72
+ DESC
73
+ method_option :params, :type => :hash, :default => {}, :aliases => '-p',
74
+ :desc => 'Additonal request parameters e.i per_page:100'
37
75
  def create(user, repo)
38
- say 'creating...'
76
+ Issue.create user, repo, options[:params], options[:format]
39
77
  end
40
78
 
41
- desc 'edit <user>,<repo>', 'Edit an issue.'
42
- method_option :params, :type => :hash
43
- def edit(user, repo)
44
- say 'editing...'
79
+ desc 'edit <user> <repo> <id>', 'Edit an issue.'
80
+ long_desc <<-DESC
81
+ Parameters
82
+
83
+ title - Required string\n
84
+ body - Optional string\n
85
+ assignee - Optional string - Login for the user that this issue should be assigned to.\n
86
+ state - Optional string - State of the issue: open or closed.
87
+ milestone - Optional number - Milestone to associate this issue with\n
88
+ labels - Optional array of strings - Labels to associate with this issue
89
+ DESC
90
+ method_option :params, :type => :hash, :default => {}, :aliases => '-p',
91
+ :desc => 'Additonal request parameters e.i per_page:100'
92
+ def edit(user, repo, id)
93
+ Issue.edit user, repo, id, options[:params], options[:format]
45
94
  end
46
95
 
47
96
  end # Issues