redmine_remotes 0.8.2 → 0.11.0

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: bd846a3cc1a788360a4b120472ea5fe1d8f8d55835a95a3af3e842fe77e1d898
4
- data.tar.gz: d4c1a544d79c5cedd5db4030df30d61cb021813a2b96457d039c77e1c35d5821
3
+ metadata.gz: 7fe74fdd135a685b96165bd9ed58d166cfb9ba5b28535eca5bc25f12a730e656
4
+ data.tar.gz: ceb58f6cebd35a0db510929df86cac7465be85f1de0f79717e2fda174fe69b90
5
5
  SHA512:
6
- metadata.gz: 429c14c070e2c1d8fe18aa45d08eeb2561fc144397811e45c6f0b6571fc85e8fce06dd3c01798c47aa78b9b7ecef313e43d6352c2dd4615dd1d87e588085a2b0
7
- data.tar.gz: 87dbdb0ddf2fb97b7db523512c5687e38c8982abf08cc1d4013c3bcd708162a9b240b93a2b39b002b078c9db883068367df158e646cf8bb5bfafecd2323b697f
6
+ metadata.gz: 77dbf10449d5d38021cf698ab65ce4225cf33377e6e5a3b4cf25ca52bba04f9216959c83a26b8cfacd25a703f887d0cb597fe0b4b28b56737c3f9baa2b89effb
7
+ data.tar.gz: 61dcddd64c24be40ed2dfacf389f535c1c56beab448b17cd817bce2e3164000b2ea190cdb195a7cfedd0f7bf59890ccdd5bc6f566870608c362a9c1e4962e633
@@ -48,24 +48,14 @@ module RedmineRemotes
48
48
 
49
49
  ::RemoteUser.find_local_user(
50
50
  provider_issue.author_login,
51
- remote_tracker
52
- )
53
- end
54
-
55
- def local_issue_status
56
- local_issue_status_from_remote_tracker || local_issue_status_from_local_tracker
57
- end
58
-
59
- def local_issue_status_from_remote_tracker
60
- ::RemoteIssueStatus.find_local_issue_status(
61
- provider_issue.status_name,
62
51
  remote_tracker,
63
- local_tracker
52
+ true
64
53
  )
65
54
  end
66
55
 
67
- def local_issue_status_from_local_tracker
68
- local_tracker.default_status
56
+ def local_issue_status
57
+ remote_tracker.try(:find_local_issue_status, local_tracker, provider_issue.status_name,
58
+ true)
69
59
  end
70
60
 
71
61
  def local_issue_description
@@ -13,15 +13,4 @@ class RemoteIssueStatus < ActiveRecord::Base
13
13
  validates :remote_tracker, presence: true
14
14
  validates :local_tracker, presence: true
15
15
  validates :local_issue_status, presence: true
16
-
17
- class << self
18
- def find_local_issue_status(remote_name, remote_tracker, local_tracker)
19
- record = ::RemoteIssueStatus.where(
20
- remote_name: remote_name_sanitize(remote_name),
21
- remote_tracker: remote_tracker,
22
- local_tracker: local_tracker
23
- ).first
24
- record ? record.local_issue_status : nil
25
- end
26
- end
27
16
  end
@@ -6,14 +6,14 @@ require 'validate_url'
6
6
 
7
7
  class RemoteTracker < ActiveRecord::Base
8
8
  include ::EacRubyUtils::Listable
9
- include ::RemoteTracker::Jira
9
+ include ::RemoteTracker::Remote
10
10
 
11
11
  has_many :issues, class_name: 'RemoteIssue', inverse_of: :remote_tracker,
12
12
  dependent: :restrict_with_error
13
13
  has_many :settings, class_name: 'RemoteTrackerSetting', inverse_of: :remote_tracker,
14
14
  dependent: :destroy
15
15
 
16
- lists.add_string :profile, :jira
16
+ lists.add_string :profile, :esosti, :jira
17
17
 
18
18
  has_many :issue_statuses, class_name: 'RemoteIssueStatus', inverse_of: :remote_tracker,
19
19
  dependent: :destroy
@@ -27,14 +27,13 @@ class RemoteTracker < ActiveRecord::Base
27
27
  validates :password, presence: true
28
28
  validates :default_local_user, presence: true
29
29
 
30
- def to_s
31
- "#{root_url} [#{profile_label}, #{username}]"
30
+ def find_local_issue_status(local_tracker, remote_status_name, register_not_found = false)
31
+ ::RemoteTracker::FindIssueLocalStatus.new(self, local_tracker, remote_status_name,
32
+ register_not_found).result
32
33
  end
33
34
 
34
- def find_remote_issue(issue_id)
35
- raise 'Profile blank' if profile.blank?
36
-
37
- send("#{profile}_find_remote_issue", issue_id)
35
+ def to_s
36
+ "#{root_url} [#{profile_label}, #{username}]"
38
37
  end
39
38
 
40
39
  def setting_value(name)
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ class RemoteTracker < ActiveRecord::Base
6
+ class FindIssueLocalStatus
7
+ common_constructor :remote_tracker, :local_tracker, :remote_status_name, :register_not_found
8
+
9
+ # @return [Tracker]
10
+ def result
11
+ result_by_remote_issue_status || result_by_register_not_found || result_by_local_issue_status
12
+ end
13
+
14
+ private
15
+
16
+ def result_by_register_not_found
17
+ return nil unless register_not_found
18
+
19
+ ::RemoteIssueStatus.create!(
20
+ remote_issue_status_find_attributes.merge(local_issue_status: result_by_local_issue_status)
21
+ ).local_issue_status
22
+ end
23
+
24
+ def result_by_remote_issue_status
25
+ ::RemoteIssueStatus.where(remote_issue_status_find_attributes).first.try(:local_issue_status)
26
+ end
27
+
28
+ def result_by_local_issue_status
29
+ local_tracker.default_status
30
+ end
31
+
32
+ def remote_issue_status_find_attributes
33
+ {
34
+ remote_name: ::RemoteIssueStatus.remote_name_sanitize(remote_status_name),
35
+ remote_tracker: remote_tracker,
36
+ local_tracker: local_tracker
37
+ }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoteTracker < ActiveRecord::Base
4
+ module Remote
5
+ def find_remote_issue(issue_id)
6
+ remote_instance.find_issue(issue_id)
7
+ end
8
+
9
+ def remote_instance
10
+ remote_instance_class.new(self, root_url, username, password)
11
+ end
12
+
13
+ def remote_instance_class
14
+ raise 'Profile blank' if profile.blank?
15
+
16
+ ::RedmineRemotes.const_get(profile.capitalize).const_get('Instance')
17
+ end
18
+ end
19
+ end
@@ -11,18 +11,7 @@ class RemoteUser < ActiveRecord::Base
11
11
  validates :remote_login, presence: true, uniqueness: { scope: [:remote_tracker] }
12
12
  validates :local_user, presence: true
13
13
 
14
- class << self
15
- def find_local_user(remote_login, remote_tracker = nil)
16
- [remote_tracker, nil].each do |tracker|
17
- remote_user = ::RemoteUser.where(
18
- remote_tracker: tracker,
19
- remote_login: remote_login_sanitize(remote_login)
20
- ).first
21
- return remote_user.local_user if remote_user
22
- end
23
- return remote_tracker.default_local_user if remote_tracker.present?
24
-
25
- nil
26
- end
14
+ def self.find_local_user(remote_login, remote_tracker = nil, register_not_found = false)
15
+ ::RemoteUser::FindLocalUser.new(remote_login, remote_tracker, register_not_found).result
27
16
  end
28
17
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ class RemoteUser < ActiveRecord::Base
6
+ class FindLocalUser
7
+ common_constructor :remote_login, :remote_tracker, :register_not_found do
8
+ self.remote_login = ::RemoteUser.remote_login_sanitize(remote_login)
9
+ end
10
+
11
+ def result
12
+ result_by_local_user || result_by_remote_user || result_by_register_not_found ||
13
+ result_by_remote_tracker_default
14
+ end
15
+
16
+ private
17
+
18
+ def result_by_local_user
19
+ result_by_local_user_login || result_by_local_user_mail_address
20
+ end
21
+
22
+ def result_by_local_user_login
23
+ ::User.find_by(login: remote_login)
24
+ end
25
+
26
+ def result_by_local_user_mail_address
27
+ condition = ::EmailAddress.arel_table[:address].matches("#{remote_login}@%")
28
+ ::EmailAddress.where(condition).first.try(:user)
29
+ end
30
+
31
+ def result_by_register_not_found
32
+ return nil unless register_not_found
33
+ return nil if remote_tracker.blank?
34
+
35
+ ::RemoteUser.create!(remote_login: remote_login, remote_tracker: remote_tracker,
36
+ local_user: remote_tracker.default_local_user).local_user
37
+ end
38
+
39
+ def result_by_remote_user
40
+ remote_trackers_to_search
41
+ .map { |tracker| remote_tracker_result(tracker) }
42
+ .find(&:present?)
43
+ end
44
+
45
+ def result_by_remote_tracker_default
46
+ remote_tracker.try(:default_local_user)
47
+ end
48
+
49
+ def remote_tracker_result(remote_tracker)
50
+ ::RemoteUser.where(
51
+ remote_tracker: remote_tracker,
52
+ remote_login: remote_login
53
+ ).first.try(:local_user)
54
+ end
55
+
56
+ def remote_trackers_to_search
57
+ remote_tracker.if_present([]) { |v| [v] } + [nil]
58
+ end
59
+ end
60
+ end
@@ -3,6 +3,8 @@ en:
3
3
  listable:
4
4
  remote_tracker:
5
5
  profile:
6
+ esosti:
7
+ label: e-Sosti (Control Desk)
6
8
  jira:
7
9
  label: Jira
8
10
  remote_tracker_setting:
@@ -3,6 +3,8 @@ pt-BR:
3
3
  listable:
4
4
  remote_tracker:
5
5
  profile:
6
+ esosti:
7
+ label: e-Sosti (Control Desk)
6
8
  jira:
7
9
  label: Jira
8
10
  remote_tracker_setting:
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedmineRemotes
4
+ module Esosti
5
+ class << self
6
+ RICH_TEXT_COMMENT = /<!--\s*RICH\s+TEXT\s-->/i.freeze
7
+
8
+ def remote_text_to_local(remote_text)
9
+ ::Redmine::WikiFormatting.html_parser.to_text(
10
+ remote_text.gsub(RICH_TEXT_COMMENT, '').each_line.map(&:strip).join(" \n")
11
+ ).each_line.map(&:strip).join("\n").gsub(/\n+/, "\n")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/esosti/entities/issue'
4
+
5
+ module RedmineRemotes
6
+ module Esosti
7
+ module Entities
8
+ class Issue < ::Avmtrf1::Esosti::Entities::Issue
9
+ def author_login
10
+ attributes.fetch('CREATEDBY').if_present { |v| v.gsub(/@[^@]+\z/, '') }
11
+ end
12
+
13
+ def attributes
14
+ data.first.fetch('Attributes')
15
+ end
16
+
17
+ def code
18
+ attributes.fetch('TICKETID')
19
+ end
20
+
21
+ def created_on
22
+ attributes.fetch('CREATIONDATE')
23
+ end
24
+
25
+ def description
26
+ ::RedmineRemotes::Esosti.remote_text_to_local(
27
+ related_mbos.fetch('LONGDESCRIPTION').first.fetch('Attributes').fetch('LDTEXT')
28
+ )
29
+ end
30
+
31
+ def related_mbos
32
+ data.first.fetch('RelatedMbos')
33
+ end
34
+
35
+ def status_name
36
+ attributes.fetch('STATUS')
37
+ end
38
+
39
+ def subject
40
+ attributes.fetch('DESCRIPTION')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedmineRemotes
4
+ module Esosti
5
+ class Instance < ::RedmineRemotes::RestProvider::Instance
6
+ ISSUE_ID_PATTERN = /\A(?:ss|in)[0-9]+\z/i.freeze
7
+
8
+ class << self
9
+ def parse_issue_id(global_issue_id)
10
+ m = ISSUE_ID_PATTERN.match(global_issue_id)
11
+ return nil unless m
12
+
13
+ ::OpenStruct.new(provider_issue_id: m[0], project_id: nil, project_issue_id: nil)
14
+ end
15
+ end
16
+
17
+ def build_service_url(service_url_suffix)
18
+ "#{root_url}/maxrest/rest#{service_url_suffix}"
19
+ end
20
+
21
+ def issue_get_url_suffix(provider_issue_id)
22
+ "/os/MS_RMTICKET/?ticketid=#{provider_issue_id}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,7 @@
3
3
  module RedmineRemotes
4
4
  SLUG = 'redmine_remotes'
5
5
  NAME = 'Redmine Remotes'
6
- VERSION = '0.8.2'
6
+ VERSION = '0.11.0'
7
7
  AUTHOR = 'Eduardo Henrique Bogoni'
8
8
  SUMMARY = 'Integração do Redmine com trackers diversos.'
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_remotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Henrique Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.27'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.27.1
33
+ version: '0.28'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '0.27'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.27.1
40
+ version: '0.28'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: curb
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -145,9 +139,11 @@ files:
145
139
  - app/models/remote_issue.rb
146
140
  - app/models/remote_issue_status.rb
147
141
  - app/models/remote_tracker.rb
148
- - app/models/remote_tracker/jira.rb
142
+ - app/models/remote_tracker/find_issue_local_status.rb
143
+ - app/models/remote_tracker/remote.rb
149
144
  - app/models/remote_tracker_setting.rb
150
145
  - app/models/remote_user.rb
146
+ - app/models/remote_user/find_local_user.rb
151
147
  - app/views/project_remote_issues/_issues.html.erb
152
148
  - app/views/project_remote_issues/_trackers.html.erb
153
149
  - app/views/project_remote_issues/index.html.erb
@@ -170,6 +166,9 @@ files:
170
166
  - db/migrate/20200505161002_add_timestamps_to_remote_users.rb
171
167
  - init.rb
172
168
  - lib/redmine_remotes.rb
169
+ - lib/redmine_remotes/esosti.rb
170
+ - lib/redmine_remotes/esosti/entities/issue.rb
171
+ - lib/redmine_remotes/esosti/instance.rb
173
172
  - lib/redmine_remotes/jira/entities/issue.rb
174
173
  - lib/redmine_remotes/jira/instance.rb
175
174
  - lib/redmine_remotes/patches/issue.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class RemoteTracker < ActiveRecord::Base
4
- module Jira
5
- def jira_find_remote_issue(issue_id)
6
- jira_create_instance.find_issue(issue_id)
7
- end
8
-
9
- def jira_create_instance
10
- ::RedmineRemotes::Jira::Instance.new(self, root_url, username, password)
11
- end
12
- end
13
- end