geet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simple_scripting/argv'
4
+
5
+ module Geet
6
+ module Helpers
7
+ class ConfigurationHelper
8
+ # Commands
9
+
10
+ ISSUE_CREATE_COMMAND = 'issue.create'
11
+ ISSUE_LIST_COMMAND = 'issue.list'
12
+ PR_CREATE_COMMAND = 'pr.create'
13
+
14
+ # Command options
15
+
16
+ ISSUE_CREATE_OPTIONS = [
17
+ ['-n', '--no-open-issue', "Don't open the issue link in the browser after creation"],
18
+ ['-l', '--label-patterns "bug,help wanted"', 'Label patterns'],
19
+ ['-a', '--assignee-patterns john,tom,adrian,kevin', 'Assignee login patterns. Defaults to authenticated user'],
20
+ 'title',
21
+ 'description'
22
+ ].freeze
23
+
24
+ ISSUE_LIST_OPTIONS = [
25
+ ].freeze
26
+
27
+ PR_CREATE_OPTIONS = [
28
+ ['-n', '--no-open-pr', "Don't open the PR link in the browser after creation"],
29
+ ['-l', '--label-patterns "legacy,code review"', 'Label patterns'],
30
+ ['-r', '--reviewer-patterns john,tom,adrian,kevin', 'Reviewer login patterns'],
31
+ 'title',
32
+ 'description'
33
+ ].freeze
34
+
35
+ # Public interface
36
+
37
+ def decode_argv
38
+ SimpleScripting::Argv.decode(
39
+ 'issue' => {
40
+ 'create' => ISSUE_CREATE_OPTIONS,
41
+ 'list' => ISSUE_LIST_OPTIONS,
42
+ },
43
+ 'pr' => {
44
+ 'create' => PR_CREATE_OPTIONS,
45
+ },
46
+ )
47
+ end
48
+
49
+ def api_token
50
+ ENV['GITHUB_API_TOKEN'] || raise('Missing $GITHUB_API_TOKEN')
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shellwords'
4
+
5
+ module Geet
6
+ module Helpers
7
+ module OsHelper
8
+ def os_open(file_or_url)
9
+ if `uname`.strip == 'Darwin'
10
+ exec "open #{file_or_url.shellescape}"
11
+ else
12
+ exec "xdg-open #{file_or_url.shellescape}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../helpers/os_helper.rb'
4
+ require_relative '../git/repository.rb'
5
+
6
+ module Geet
7
+ module Services
8
+ class CreateIssue
9
+ include Geet::Helpers::OsHelper
10
+
11
+ # options:
12
+ # :label_patterns
13
+ # :assignee_patterns
14
+ # :no_open_issue
15
+ #
16
+ def execute(repository, title, description, options = {})
17
+ if options[:label_patterns]
18
+ puts 'Finding labels...'
19
+
20
+ all_labels = repository.labels
21
+ selected_labels = select_entries(all_labels, options[:label_patterns], type: 'labels')
22
+ end
23
+
24
+ if options[:assignee_patterns]
25
+ puts 'Finding collaborators...'
26
+
27
+ all_collaborators = repository.collaborators
28
+ assignees = select_entries(all_collaborators, options[:assignee_patterns], type: 'collaborators')
29
+ end
30
+
31
+ puts 'Creating the issue...'
32
+
33
+ issue = repository.create_issue(title, description)
34
+
35
+ if selected_labels
36
+ puts 'Adding labels...'
37
+
38
+ issue.add_labels(selected_labels)
39
+
40
+ puts '- labels added: ' + selected_labels.join(', ')
41
+ end
42
+
43
+ if assignees
44
+ puts 'Assigning users...'
45
+
46
+ issue.assign_user(assignees)
47
+
48
+ puts '- assigned: ' + assignees.join(', ')
49
+ else
50
+ issue.assign_user(repository.authenticated_user)
51
+ end
52
+
53
+ if options[:no_open_pr]
54
+ puts "Issue address: #{issue.link}"
55
+ else
56
+ os_open(issue.link)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def select_entries(entries, raw_patterns, type: 'entries')
63
+ patterns = raw_patterns.split(',')
64
+
65
+ patterns.map do |pattern|
66
+ entries_found = entries.select { |label| label =~ /#{pattern}/i }
67
+
68
+ case entries_found.size
69
+ when 1
70
+ entries_found.first
71
+ when 0
72
+ raise "No #{type} found for pattern: #{pattern.inspect}"
73
+ else
74
+ raise "Multiple #{type} found for pattern #{pattern.inspect}: #{labels_found}"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../helpers/os_helper.rb'
4
+ require_relative '../git/repository.rb'
5
+
6
+ module Geet
7
+ module Services
8
+ class CreatePr
9
+ include Geet::Helpers::OsHelper
10
+
11
+ # options:
12
+ # :label_patterns
13
+ # :reviewer_patterns
14
+ # :no_open_pr
15
+ #
16
+ def execute(repository, title, description, options = {})
17
+ if options[:label_patterns]
18
+ puts 'Finding labels...'
19
+
20
+ all_labels = repository.labels
21
+ selected_labels = select_entries(all_labels, options[:label_patterns], type: 'labels')
22
+ end
23
+
24
+ if options[:reviewer_patterns]
25
+ puts 'Finding collaborators...'
26
+
27
+ all_collaborators = repository.collaborators
28
+ reviewers = select_entries(all_collaborators, options[:reviewer_patterns], type: 'collaborators')
29
+ end
30
+
31
+ puts 'Creating PR...'
32
+
33
+ pr = repository.create_pr(title, description)
34
+
35
+ puts 'Assigning authenticated user...'
36
+
37
+ pr.assign_user(repository.authenticated_user)
38
+
39
+ if selected_labels
40
+ puts 'Adding labels...'
41
+
42
+ pr.add_labels(selected_labels)
43
+
44
+ puts '- labels added: ' + selected_labels.join(', ')
45
+ end
46
+
47
+ if reviewers
48
+ puts 'Requesting review...'
49
+
50
+ pr.request_review(reviewers)
51
+
52
+ puts '- review requested to: ' + reviewers.join(', ')
53
+ end
54
+
55
+ if options[:no_open_pr]
56
+ puts "PR address: #{pr.link}"
57
+ else
58
+ os_open(pr.link)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def select_entries(entries, raw_patterns, type: 'entries')
65
+ patterns = raw_patterns.split(',')
66
+
67
+ patterns.map do |pattern|
68
+ entries_found = entries.select { |label| label =~ /#{pattern}/i }
69
+
70
+ case entries_found.size
71
+ when 1
72
+ entries_found.first
73
+ when 0
74
+ raise "No #{type} found for pattern: #{pattern.inspect}"
75
+ else
76
+ raise "Multiple #{type} found for pattern #{pattern.inspect}: #{labels_found}"
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require_relative '../helpers/os_helper.rb'
4
+ # require_relative '../git/repository.rb'
5
+
6
+ module Geet
7
+ module Services
8
+ class ListIssues
9
+ def execute(repository)
10
+ issues = repository.list_issues
11
+
12
+ issues.each do |issue|
13
+ puts "#{issue.number}. #{issue.title} (#{issue.link})"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Geet
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Saverio Miroddi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simple_scripting
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.3
27
+ description: Commandline interface for performing SCM (eg. GitHub) operations (eg.
28
+ PR creation).
29
+ email:
30
+ - saverio.pub2@gmail.com
31
+ executables:
32
+ - geet
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".rubocop.yml"
37
+ - ".rubocop_todo.yml"
38
+ - ".ruby-version"
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.md
42
+ - README.md
43
+ - bin/geet
44
+ - geet.gemspec
45
+ - lib/geet/git/repository.rb
46
+ - lib/geet/git_hub/abstract_issue.rb
47
+ - lib/geet/git_hub/account.rb
48
+ - lib/geet/git_hub/api_helper.rb
49
+ - lib/geet/git_hub/issue.rb
50
+ - lib/geet/git_hub/pr.rb
51
+ - lib/geet/git_hub/remote_repository.rb
52
+ - lib/geet/helpers/configuration_helper.rb
53
+ - lib/geet/helpers/os_helper.rb
54
+ - lib/geet/services/create_issue.rb
55
+ - lib/geet/services/create_pr.rb
56
+ - lib/geet/services/list_issues.rb
57
+ - lib/geet/version.rb
58
+ homepage: https://github.com/saveriomiroddi/geet
59
+ licenses:
60
+ - GPL-3.0
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.13
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Commandline interface for performing SCM (eg. GitHub) operations (eg. PR
82
+ creation).
83
+ test_files: []