dude-cli 2.0.7 → 2.1.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f193ac190cdcd95628911cd674828269e6dfbbc7cc1e5fc0a60d5369ba6dd00e
4
- data.tar.gz: 9b0ee32f4a20cbc7016fe7b6db792b2af4d9447ebc0356e124a97d0c1b8fee16
3
+ metadata.gz: 54ecc96e52485347713cfd2f36d30a29706c778026ddad4d555b8dbca0bf649c
4
+ data.tar.gz: 07b9024cf6411779c9f7890513fb2bde075139df2d618cac8eb740b3899591a4
5
5
  SHA512:
6
- metadata.gz: e7153c965ca0222b34f7cc5dc14ee1e21d77303932b0c27f224a935ea3940ef088f5c907e60871f256080e31771914ab69b883b0bb6549c6731dc10a1d50237d
7
- data.tar.gz: 1c42491aca9dd9d44d80ee46a08b0babf816bac4dd6c129de45975e0b9923939ae5b3f852a4aeccbb2263b7e1bd7d87817fe3502fda998ff17ccbd19456d6616
6
+ metadata.gz: 9bcef41c12911bac2e4afac38909e56bf23dc1abc4c1b6e9a0222819f2e434c0e466e26a563a8846c46747c8a4393444f8184b18003aea5d3848572ede6189a4
7
+ data.tar.gz: 58b615eb893266f7b96b9425e8cfbad19d92e0bfe1717f43443124d1ff131eb17151ef9134efeaad059919c8d7ac2653458005d8747340802979fdf57c402bdf
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -2,8 +2,12 @@ Style/Documentation:
2
2
  Enabled: false
3
3
 
4
4
  AllCops:
5
+ NewCops: enable
5
6
  SuggestExtensions: false
6
7
  TargetRubyVersion: 2.5
7
8
 
8
9
  Metrics/BlockLength:
9
10
  IgnoredMethods: ['describe', 'context']
11
+
12
+ Layout/FirstHashElementIndentation:
13
+ EnforcedStyle: consistent
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dude-cli (2.0.6)
4
+ dude-cli (2.1.0.alpha1)
5
5
  colorize (~> 0.8.1)
6
6
  dry-cli (~> 0.6)
7
7
  faraday (~> 1.1)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (6.1.3)
13
+ activesupport (6.1.3.2)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
@@ -24,14 +24,21 @@ GEM
24
24
  concurrent-ruby (1.1.8)
25
25
  diff-lcs (1.4.4)
26
26
  docile (1.3.5)
27
- dry-cli (0.6.0)
28
- concurrent-ruby (~> 1.0)
29
- faraday (1.3.0)
27
+ dry-cli (0.7.0)
28
+ faraday (1.4.2)
29
+ faraday-em_http (~> 1.0)
30
+ faraday-em_synchrony (~> 1.0)
31
+ faraday-excon (~> 1.1)
30
32
  faraday-net_http (~> 1.0)
33
+ faraday-net_http_persistent (~> 1.1)
31
34
  multipart-post (>= 1.2, < 3)
32
- ruby2_keywords
35
+ ruby2_keywords (>= 0.0.4)
36
+ faraday-em_http (1.0.0)
37
+ faraday-em_synchrony (1.0.0)
38
+ faraday-excon (1.1.0)
33
39
  faraday-net_http (1.0.1)
34
- i18n (1.8.9)
40
+ faraday-net_http_persistent (1.1.0)
41
+ i18n (1.8.10)
35
42
  concurrent-ruby (~> 1.0)
36
43
  jira-ruby (2.1.5)
37
44
  activesupport
@@ -42,17 +49,17 @@ GEM
42
49
  method_source (1.0.0)
43
50
  minitest (5.14.4)
44
51
  multipart-post (2.1.1)
45
- oauth (0.5.5)
52
+ oauth (0.5.6)
46
53
  parallel (1.20.1)
47
- parser (3.0.0.0)
54
+ parser (3.0.1.1)
48
55
  ast (~> 2.4.1)
49
- pry (0.14.0)
56
+ pry (0.14.1)
50
57
  coderay (~> 1.1)
51
58
  method_source (~> 1.0)
52
59
  rainbow (3.0.0)
53
60
  rake (13.0.3)
54
61
  regexp_parser (2.1.1)
55
- rexml (3.2.4)
62
+ rexml (3.2.5)
56
63
  rspec (3.10.0)
57
64
  rspec-core (~> 3.10.0)
58
65
  rspec-expectations (~> 3.10.0)
@@ -66,17 +73,17 @@ GEM
66
73
  diff-lcs (>= 1.2.0, < 2.0)
67
74
  rspec-support (~> 3.10.0)
68
75
  rspec-support (3.10.2)
69
- rubocop (1.12.0)
76
+ rubocop (1.15.0)
70
77
  parallel (~> 1.10)
71
78
  parser (>= 3.0.0.0)
72
79
  rainbow (>= 2.2.2, < 4.0)
73
80
  regexp_parser (>= 1.8, < 3.0)
74
81
  rexml
75
- rubocop-ast (>= 1.2.0, < 2.0)
82
+ rubocop-ast (>= 1.5.0, < 2.0)
76
83
  ruby-progressbar (~> 1.7)
77
84
  unicode-display_width (>= 1.4.0, < 3.0)
78
- rubocop-ast (1.4.1)
79
- parser (>= 2.7.1.5)
85
+ rubocop-ast (1.5.0)
86
+ parser (>= 3.0.1.1)
80
87
  ruby-progressbar (1.11.0)
81
88
  ruby2_keywords (0.0.4)
82
89
  simplecov (0.21.2)
data/README.md CHANGED
@@ -32,7 +32,10 @@ After that create .duderc file in your HOME directory by command:
32
32
 
33
33
  And configure all variables in this file
34
34
 
35
- `PROJECT_MANAGEMENT_TOOL=jira` - Project management (Now only Jira supported)
35
+ `PROJECT_MANAGEMENT_TOOL=jira|trello` - Project management (Now only Jira and Trello supported)
36
+
37
+ ##### Jira setup
38
+
36
39
  `ATLASSIAN_EMAIL` - Your Jira email
37
40
 
38
41
  `ATLASSIAN_TOKEN` - How to create Atlassian token: https://support.siteimprove.com/hc/en-gb/articles/360004317332-How-to-create-an-API-token-from-your-Atlassian-account
@@ -46,6 +49,12 @@ Just open your atlassian main board and copy id from the url after rapidView=*ID
46
49
 
47
50
  Example: https://dealmakerns.atlassian.net/secure/RapidBoard.jspa?rapidView=23&projectKey=DT - 23 is the id
48
51
 
52
+ ##### Trello setup
53
+ You could generate your key and token here: https://trello.com/app-key
54
+
55
+ `TRELLO_KEY`
56
+
57
+ `TRELLO_TOKEN`
49
58
 
50
59
  #### Replace it with your project list names. Skip for empty lists
51
60
 
@@ -63,7 +72,7 @@ DONE_LIST_NAME=Done
63
72
 
64
73
  `TOGGL_WORKSPACE_ID` - Can be copied from url here: https://toggl.com/app/projects/. Example: 123456
65
74
 
66
- #### Use the *id* and *title* and specify format for the task titles in Trello or keep it as it is
75
+ #### Use the *id* and *title* and specify format for the task titles in Toggl or keep it as it is
67
76
  `TOGGL_TASK_FORMAT=[id] title`
68
77
 
69
78
  ## Usage
data/lib/dude.rb CHANGED
@@ -6,9 +6,10 @@ require_relative './dude/settings'
6
6
  require_relative './dude/version'
7
7
  require_relative './dude/commands'
8
8
  require_relative './dude/git'
9
+ require_relative './dude/code_management'
9
10
 
10
11
  module Dude
11
12
  class ToBeImplementedError < StandardError; end
12
13
 
13
- LIST_OF_AVAILABLE_PROJECT_MANAGEMENT_TOOLS = %w[jira].freeze
14
+ LIST_OF_AVAILABLE_PROJECT_MANAGEMENT_TOOLS = %w[jira trello].freeze
14
15
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './code_management/github/client'
4
+
5
+ module Dude
6
+ module CodeManagement
7
+ module Github
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './create_pull_request'
4
+
5
+ module Dude
6
+ module CodeManagement
7
+ module Github
8
+ class Client
9
+ include Settings
10
+
11
+ def client
12
+ @client ||= Faraday.new('https://api.github.com/', {
13
+ headers: { Authorization: "token #{settings['GITHUB_TOKEN']}" }
14
+ })
15
+ end
16
+
17
+ def create_pull_request(issue:, owner:, repo:, params:)
18
+ CreatePullRequest.new.call(issue: issue, owner: owner, repo: repo, params: params)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Dude
6
+ module CodeManagement
7
+ module Github
8
+ class CreatePullRequest
9
+ include Settings
10
+
11
+ def call(issue:, owner:, repo:, params:)
12
+ @issue = issue
13
+ @owner = owner
14
+ @repo = repo
15
+ @params = params
16
+
17
+ response = client.post("https://api.github.com/repos/#{owner}/#{repo}/pulls", body.to_json)
18
+ res = JSON.parse(response.body)
19
+ url = res['html_url']
20
+ puts "Pull request has been created: #{url}"
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :issue, :owner, :repo, :params
26
+
27
+ def body
28
+ {
29
+ title: params[:title] || template['title'],
30
+ body: params[:body] || template['body'],
31
+ head: params[:head],
32
+ base: params[:base]
33
+ }
34
+ end
35
+
36
+ def template
37
+ file = YAML.load_file(File.join(File.dirname(__FILE__), '../../templates/pull_request_template'))
38
+ file.tap do |template|
39
+ template['title'] = fill_variables(template['title'])
40
+ template['body'] = fill_variables(template['body'])
41
+ end
42
+ end
43
+
44
+ def fill_variables(text)
45
+ text
46
+ .then { _1.gsub('{issue_id}', issue.id) }.chomp
47
+ .then { _1.gsub('{issue_url}', issue.url) }
48
+ .then { _1.gsub('{issue_title}', issue.title) }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/dude/commands.rb CHANGED
@@ -9,6 +9,7 @@ require_relative './commands/start'
9
9
  require_relative './commands/track'
10
10
  require_relative './commands/stop'
11
11
  require_relative './commands/install'
12
+ require_relative './commands/pr'
12
13
 
13
14
  module Dude
14
15
  module Commands
@@ -22,5 +23,9 @@ module Dude
22
23
  register 'track', Dude::Commands::Track, aliases: ['tr']
23
24
  register 'stop', Dude::Commands::Stop
24
25
  register 'start', Dude::Commands::Start, aliases: ['st']
26
+
27
+ register 'pr' do |prefix|
28
+ prefix.register 'create', Dude::Commands::PR::Create
29
+ end
25
30
  end
26
31
  end
@@ -23,19 +23,6 @@ module Dude
23
23
  <<~HEREDOC
24
24
  # Please, don't use quotes and spaces.
25
25
  # Write all variables using following format: NAME=VALUE
26
- #
27
- # Now jira only (Github, Gitlab, Trello later)
28
- PROJECT_MANAGEMENT_TOOL=jira
29
- ATLASSIAN_EMAIL=
30
- # How to create Atlassian token: https://support.siteimprove.com/hc/en-gb/articles/360004317332-How-to-create-an-API-token-from-your-Atlassian-account
31
- ATLASSIAN_TOKEN=
32
- # URL of your project. Example: https://example.atlassian.net
33
- ATLASSIAN_URL=
34
- # KEY of your project. If your issues have id BT-123 - BT is the key
35
- ATLASSIAN_PROJECT_KEY=
36
- # Just open your atlassian main board and copy id from the url after rapidView=*ID* part.
37
- # Example: https://dealmakerns.atlassian.net/secure/RapidBoard.jspa?rapidView=23&projectKey=DT - 23 is the id
38
- ATLASSIAN_BOARD_ID=
39
26
 
40
27
  # Replace it with your project list names. Skip for empty lists
41
28
  TODO_LIST_NAME=To Do
@@ -52,6 +39,31 @@ module Dude
52
39
  TOGGL_WORKSPACE_ID=
53
40
  # Use the *id* and *title* and specify format for the task titles in Trello or keep it as it is
54
41
  TOGGL_TASK_FORMAT=[id] title
42
+
43
+ # Now jira/trello only (Github, Gitlab)
44
+ # Choose one and uncomment section for Jira or Trello
45
+
46
+ # [TRELLO setup start]
47
+ # # https://trello.com/app-key
48
+ # PROJECT_MANAGEMENT_TOOL=trello
49
+ # TRELLO_KEY=
50
+ # TRELLO_TOKEN=
51
+ # [TRELLO setup end]
52
+
53
+ # [JIRA setup start]
54
+ PROJECT_MANAGEMENT_TOOL=jira
55
+ ATLASSIAN_EMAIL=
56
+ # How to create Atlassian token: https://support.siteimprove.com/hc/en-gb/articles/360004317332-How-to-create-an-API-token-from-your-Atlassian-account
57
+ ATLASSIAN_TOKEN=
58
+ # URL of your project. Example: https://example.atlassian.net
59
+ ATLASSIAN_URL=
60
+ # KEY of your project. If your issues have id BT-123 - BT is the key
61
+ ATLASSIAN_PROJECT_KEY=
62
+ # Just open your atlassian main board and copy id from the url after rapidView=*ID* part.
63
+ # Example: https://dealmakerns.atlassian.net/secure/RapidBoard.jspa?rapidView=23&projectKey=DT - 23 is the id
64
+ ATLASSIAN_BOARD_ID=
65
+ # [JIRA setup end]
66
+
55
67
  HEREDOC
56
68
  end
57
69
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './pr/create'
4
+ require_relative './pr/remove'
5
+
6
+ module Dude
7
+ module Commands
8
+ module PR
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dude
4
+ module Commands
5
+ module PR
6
+ BASE_BRANCH = 'master'
7
+
8
+ class Create < Dry::CLI::Command
9
+ desc 'Create PR with custom template description'
10
+
11
+ argument :id, required: true, desc: 'The card short ID'
12
+
13
+ def call(id:)
14
+ @id = id
15
+ client = CodeManagement::Github::Client.new
16
+ client.create_pull_request(issue: issue, owner: owner, repo: repo, params: params)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :id
22
+
23
+ def owner
24
+ repository_name.split('/')[0]
25
+ end
26
+
27
+ def issue
28
+ client = ProjectManagement::Client.new
29
+ client.fetch_current_task(id)
30
+ end
31
+
32
+ def repo
33
+ repository_name.split('/')[1]
34
+ end
35
+
36
+ def params
37
+ {
38
+ head: Git::CurrentBranchName.new.call,
39
+ base: BASE_BRANCH
40
+ }
41
+ end
42
+
43
+ def repository_name
44
+ @repository_name ||= Git::RemoteName.new.call
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dude
4
+ module Commands
5
+ module PR
6
+ class Remove < Dry::CLI::Command
7
+ desc 'Remove'
8
+
9
+ def call(*)
10
+ puts '123'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -12,7 +12,7 @@ module Dude
12
12
  def call(id:)
13
13
  Commands::Move.new.call(id: id, list: selected_list('in_progress'))
14
14
  Commands::Checkout.new.call(id: id)
15
- Commands::Track.new.call(id: id)
15
+ Commands::Track.new.call(id: id) if time_tracking_enabled?
16
16
  end
17
17
 
18
18
  private
@@ -26,6 +26,10 @@ module Dude
26
26
  when 'done' then settings['DONE_LIST_NAME']
27
27
  end
28
28
  end
29
+
30
+ def time_tracking_enabled?
31
+ !settings['TOGGL_TOKEN'].nil?
32
+ end
29
33
  end
30
34
  end
31
35
  end
data/lib/dude/git.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative './git/checkout'
4
4
  require_relative './git/current_branch_name'
5
+ require_relative './git/remote_name'
5
6
 
6
7
  module Git
7
8
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dude
4
+ module Git
5
+ class RemoteName
6
+ def call
7
+ extract_name push_url
8
+ end
9
+
10
+ private
11
+
12
+ def push_url
13
+ `git remote show origin`.split("\n")[1]
14
+ end
15
+
16
+ def extract_name(url)
17
+ url.scan(%r{(?<=github\.com[/:])(.*)(?=\.git)})[0][0]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './jira/client'
4
+ require_relative './trello/client'
4
5
 
5
6
  module Dude
6
7
  module ProjectManagement
@@ -10,9 +11,10 @@ module Dude
10
11
  attr_reader :client
11
12
 
12
13
  def initialize
13
- return unless LIST_OF_AVAILABLE_PROJECT_MANAGEMENT_TOOLS.include? settings['PROJECT_MANAGEMENT_TOOL']
14
+ tool = settings['PROJECT_MANAGEMENT_TOOL']
15
+ return unless LIST_OF_AVAILABLE_PROJECT_MANAGEMENT_TOOLS.include? tool
14
16
 
15
- @client = Dude::ProjectManagement::Jira::Client.new
17
+ @client = setup_client(tool)
16
18
  end
17
19
 
18
20
  def respond_to_missing?(method_name, include_private = false)
@@ -22,6 +24,10 @@ module Dude
22
24
  def method_missing(method, *args, &block)
23
25
  client.send(method, *args, &block)
24
26
  end
27
+
28
+ def setup_client(tool)
29
+ Object.const_get("Dude::ProjectManagement::#{tool.capitalize}::Client").new
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -4,14 +4,15 @@ module Dude
4
4
  module ProjectManagement
5
5
  module Entities
6
6
  class Issue
7
- attr_accessor :id, :title, :description, :status, :assignee
7
+ attr_accessor :id, :title, :description, :status, :assignee, :url
8
8
 
9
- def initialize(id:, title:, description:, status:, assignee: nil)
10
- @id = id
11
- @title = title
12
- @description = description
13
- @status = status
14
- @assignee = assignee
9
+ def initialize(params)
10
+ @id = params[:id]
11
+ @title = params[:title]
12
+ @description = params[:description]
13
+ @status = params[:status]
14
+ @assignee = params[:assignee]
15
+ @url = params[:url]
15
16
  end
16
17
 
17
18
  def todo?
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'jira-ruby'
4
4
  require_relative './fetch_current_tasks'
5
+ require_relative './fetch_current_task'
5
6
  require_relative './move_task_to_list'
6
7
  require_relative './get_task_name_by_id'
7
8
 
@@ -38,6 +39,10 @@ module Dude
38
39
  FetchCurrentTasks.new(client).call
39
40
  end
40
41
 
42
+ def fetch_current_task(id)
43
+ FetchCurrentTask.new(client, id: id).call
44
+ end
45
+
41
46
  def move_task_to_list(id, list)
42
47
  MoveTaskToList.new(client, id: id, list_name: list).call
43
48
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../entities/issue'
4
+
5
+ module Dude
6
+ module ProjectManagement
7
+ module Jira
8
+ class FetchCurrentTask
9
+ include Settings
10
+
11
+ def initialize(client, id:)
12
+ @client = client
13
+ @id = id
14
+ end
15
+
16
+ def call
17
+ create_issue(client.Issue.find(id))
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :client, :id
23
+
24
+ def create_issue(issue)
25
+ Entities::Issue.new(
26
+ id: issue.key,
27
+ title: issue.summary,
28
+ description: issue.description,
29
+ status: issue.status.name,
30
+ assignee: issue&.assignee&.displayName,
31
+ url: "#{settings['ATLASSIAN_URL']}/browse/#{issue.key}"
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -38,7 +38,8 @@ module Dude
38
38
  title: issue.summary,
39
39
  description: issue.description,
40
40
  status: issue.status.name,
41
- assignee: issue&.assignee&.displayName
41
+ assignee: issue&.assignee&.displayName,
42
+ url: "#{settings['ATLASSIAN_URL']}/browse/#{issue.key}"
42
43
  )
43
44
  end
44
45
  end
@@ -2,9 +2,7 @@
2
2
 
3
3
  module Dude
4
4
  module ProjectManagement
5
- module Entities
6
- class Issue
7
- end
5
+ module Trello
8
6
  end
9
7
  end
10
8
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './fetch_current_tasks'
4
+ require_relative './fetch_current_task'
5
+ require_relative './move_task_to_list'
6
+ require_relative './get_task_name_by_id'
7
+
8
+ require 'faraday'
9
+ require 'json'
10
+
11
+ module Dude
12
+ module ProjectManagement
13
+ module Trello
14
+ class Client
15
+ include Settings
16
+
17
+ def client
18
+ @client ||= Faraday.new('https://api.trello.com/', {
19
+ params: {
20
+ key: settings['TRELLO_KEY'],
21
+ token: settings['TRELLO_TOKEN']
22
+ }
23
+ })
24
+ end
25
+
26
+ def method_missing(method, *args, &block)
27
+ faraday_client.send(method, *args, &block)
28
+ end
29
+
30
+ def respond_to_missing?(method_name, include_private = false)
31
+ client.respond_to_missing?(method_name, include_private)
32
+ end
33
+
34
+ def fetch_current_tasks
35
+ FetchCurrentTasks.new(client).call
36
+ end
37
+
38
+ def fetch_current_task(id)
39
+ FetchCurrentTask.new(client, id: id).call
40
+ end
41
+
42
+ def move_task_to_list(id, list)
43
+ MoveTaskToList.new(client, id: id, list_name: list).call
44
+ end
45
+
46
+ def get_task_name_by_id(id)
47
+ GetTaskNameById.new(client, id: id).call
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dude
4
+ module ProjectManagement
5
+ module Trello
6
+ class FetchCurrentTask
7
+ include Settings
8
+
9
+ def initialize(client, id:)
10
+ @client = client
11
+ @id = id
12
+ end
13
+
14
+ def call
15
+ response = client.get("/1/boards/#{settings['ATLASSIAN_BOARD_ID']}/cards/#{id}")
16
+ create_issue JSON.parse(response.body)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :client, :id
22
+
23
+ def create_issue(issue)
24
+ Entities::Issue.new(
25
+ id: issue['idShort'],
26
+ title: issue['name'],
27
+ description: issue['desc'],
28
+ status: settings['IN_PROGRESS_LIST_NAME'], # OMG, let's fix this later
29
+ assignee: members(issue),
30
+ url: issue['shortUrl']
31
+ )
32
+ end
33
+
34
+ def members(issue)
35
+ people = issue['idMembers'].map do |person|
36
+ JSON.parse(client.get("/1/members/#{person}", fields: 'fullName').body)['fullName']
37
+ end
38
+ people.empty? ? nil : people.join(', ')
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './fetch_lists'
4
+
5
+ module Dude
6
+ module ProjectManagement
7
+ module Trello
8
+ class FetchCurrentTasks
9
+ include Settings
10
+
11
+ attr_reader :fetch_lists
12
+
13
+ def initialize(client, fetch_lists: nil)
14
+ @client = client
15
+
16
+ @fetch_lists = fetch_lists || FetchLists.new(client)
17
+ end
18
+
19
+ def call
20
+ lists = fetch_lists.call
21
+ lists.map { |list| retrieve_list_issues(list) }.flatten
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :client
27
+
28
+ def retrieve_list_issues(list)
29
+ response = client.get("/1/lists/#{list['id']}/cards")
30
+ body = JSON.parse(response.body)
31
+ body.map { |issue| create_issue(issue, list) }
32
+ end
33
+
34
+ def create_issue(issue, current_list)
35
+ Entities::Issue.new(
36
+ id: issue['idShort'],
37
+ title: issue['name'],
38
+ description: issue['desc'],
39
+ status: current_list['name'],
40
+ assignee: members(issue)
41
+ )
42
+ end
43
+
44
+ def members(issue)
45
+ people = issue['idMembers'].map do |person|
46
+ JSON.parse(client.get("/1/members/#{person}", fields: 'fullName').body)['fullName']
47
+ end
48
+ people.empty? ? nil : people.join(', ')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dude
4
+ module ProjectManagement
5
+ module Trello
6
+ class FetchLists
7
+ include Settings
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ def call
14
+ response = client.get("/1/board/#{settings['ATLASSIAN_BOARD_ID']}/lists", { fields: 'name' })
15
+ JSON.parse(response.body)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :client
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dude
4
+ module ProjectManagement
5
+ module Trello
6
+ class GetTaskNameById
7
+ include Settings
8
+
9
+ def initialize(client, id:)
10
+ @client = client
11
+ @id = id
12
+ end
13
+
14
+ def call
15
+ response = client.get("/1/boards/#{settings['ATLASSIAN_BOARD_ID']}/cards/#{id}")
16
+ JSON.parse(response.body)['name']
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :client, :id
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './fetch_lists'
4
+
5
+ module Dude
6
+ module ProjectManagement
7
+ module Trello
8
+ class MoveTaskToList
9
+ include Settings
10
+
11
+ def initialize(client, id:, list_name:)
12
+ @client = client
13
+ @id = id
14
+ @list_name = list_name
15
+ end
16
+
17
+ def call
18
+ response = client.get("/1/boards/#{settings['ATLASSIAN_BOARD_ID']}/cards/#{id}", { fields: 'id' })
19
+ card_id = JSON.parse(response.body)['id']
20
+ client.put("/1/cards/#{card_id}", { idList: list_id })
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :client, :id, :list_name
26
+
27
+ def list_id
28
+ if list_name
29
+ lists.find { |list| list['name'] == list_name }['id']
30
+ else
31
+ select_list_for_moving['id']
32
+ end
33
+ end
34
+
35
+ def select_list_for_moving
36
+ puts 'Please, select list for moving:'.green.bold
37
+
38
+ print_lists
39
+
40
+ print "\nList index: ".bold
41
+ list_index = $stdin.gets.chomp
42
+ lists[list_index.to_i - 1]
43
+ end
44
+
45
+ def print_lists
46
+ lists.map { |list| list['name'] }.each_with_index { |name, index| puts "#{index + 1}: #{name.bold}" }
47
+ end
48
+
49
+ def lists
50
+ @lists ||= FetchLists.new(client).call
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ title: >
2
+ [{issue_id}] {issue_title}
3
+ body: |
4
+ ## Story
5
+ [**\[{issue_id}\] {issue_title}**]({issue_url})
6
+ ## Description
7
+ Example description of the issue
data/lib/dude/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dude
4
- VERSION = '2.0.7'
4
+ VERSION = '2.1.0.alpha1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dude-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.1.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Pupko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -178,10 +178,16 @@ files:
178
178
  - bin/setup
179
179
  - dude.gemspec
180
180
  - lib/dude.rb
181
+ - lib/dude/code_management.rb
182
+ - lib/dude/code_management/github/client.rb
183
+ - lib/dude/code_management/github/create_pull_request.rb
181
184
  - lib/dude/commands.rb
182
185
  - lib/dude/commands/checkout.rb
183
186
  - lib/dude/commands/install.rb
184
187
  - lib/dude/commands/move.rb
188
+ - lib/dude/commands/pr.rb
189
+ - lib/dude/commands/pr/create.rb
190
+ - lib/dude/commands/pr/remove.rb
185
191
  - lib/dude/commands/start.rb
186
192
  - lib/dude/commands/stop.rb
187
193
  - lib/dude/commands/tasks.rb
@@ -190,15 +196,24 @@ files:
190
196
  - lib/dude/git.rb
191
197
  - lib/dude/git/checkout.rb
192
198
  - lib/dude/git/current_branch_name.rb
199
+ - lib/dude/git/remote_name.rb
193
200
  - lib/dude/project_management/client.rb
194
- - lib/dude/project_management/entities/board.rb
195
201
  - lib/dude/project_management/entities/issue.rb
196
202
  - lib/dude/project_management/jira.rb
197
203
  - lib/dude/project_management/jira/client.rb
204
+ - lib/dude/project_management/jira/fetch_current_task.rb
198
205
  - lib/dude/project_management/jira/fetch_current_tasks.rb
199
206
  - lib/dude/project_management/jira/get_task_name_by_id.rb
200
207
  - lib/dude/project_management/jira/move_task_to_list.rb
208
+ - lib/dude/project_management/trello.rb
209
+ - lib/dude/project_management/trello/client.rb
210
+ - lib/dude/project_management/trello/fetch_current_task.rb
211
+ - lib/dude/project_management/trello/fetch_current_tasks.rb
212
+ - lib/dude/project_management/trello/fetch_lists.rb
213
+ - lib/dude/project_management/trello/get_task_name_by_id.rb
214
+ - lib/dude/project_management/trello/move_task_to_list.rb
201
215
  - lib/dude/settings.rb
216
+ - lib/dude/templates/pull_request_template
202
217
  - lib/dude/time_trackers/toggl.rb
203
218
  - lib/dude/time_trackers/toggl/base.rb
204
219
  - lib/dude/time_trackers/toggl/start_time_entry.rb
@@ -222,9 +237,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
237
  version: 2.5.0
223
238
  required_rubygems_version: !ruby/object:Gem::Requirement
224
239
  requirements:
225
- - - ">="
240
+ - - ">"
226
241
  - !ruby/object:Gem::Version
227
- version: '0'
242
+ version: 1.3.1
228
243
  requirements: []
229
244
  rubygems_version: 3.1.4
230
245
  signing_key: