redmine_remotes 0.8.1 → 0.10.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: 4b65843d810df106f89cfab8c6da6beef03d5421263f21a7b7730e9dab08ce13
4
- data.tar.gz: ec23913f8340a42f5c69f28e0f24f72baacf3b59b38adb9d8f32dadeca9fc06c
3
+ metadata.gz: 2a0671e339c9e225c9413feb402fed23e0ac5e930a3e72027aa2b183749441d5
4
+ data.tar.gz: eb1245a9f15262922b95bec5574bdbb3dbc84f286d7fed371970b759657f6e2d
5
5
  SHA512:
6
- metadata.gz: 886781f236327ed6e0d30d26f3950e80a07629c3c2905c8bf98a50cb8c9ed10daa9be495c804059d2ac195816894c77ee2af43e87d3c253ccb20a568bcd0bb5d
7
- data.tar.gz: 41578f7e2bfa7a6c97bdad8cc9bff55c1a8e26f8099d5ba824c0b0e420ed746ee46f8058b6d9cfb8069de6fc6dda8c4b16b5ed566bce325abada1043e1b268dd
6
+ metadata.gz: 0af87885a31cc69c7ec0cc8f1bbd7201b189b8c5f260382d990189affb7ab642b5eba050231e3e7c0a78f5d65a134c21490148d5461858c61af9ad92c813e578
7
+ data.tar.gz: 322120abe8ba4dde501c3d6cccc3a3315933d18f585d4c7eb9a86b8c147ec797c0dcb2bff8b08ac29001466eb12e2824cb29a1ef7394b5db1d8f21cbe4c31778
@@ -6,11 +6,36 @@ module RedmineRemotes
6
6
  class Base < ::EacRailsUtils::TablelessModel
7
7
  private
8
8
 
9
+ def save_local_issue
10
+ save_local_issue_except_create_on && save_local_issue_created_on
11
+ end
12
+
13
+ def save_local_issue_created_on
14
+ local_issue_provider_attributes[:created_on].if_present do |created_on|
15
+ if created_on.present? && local_issue.created_on != created_on
16
+ local_issue.update_column( # rubocop:disable Rails/SkipsModelValidations
17
+ :created_on, created_on
18
+ )
19
+ end
20
+ end
21
+
22
+ true
23
+ end
24
+
25
+ def save_local_issue_except_create_on
26
+ local_issue_provider_attributes.except(:created_on)
27
+ .each { |attr, value| local_issue.send("#{attr}=", value) }
28
+ return true if local_issue.save
29
+
30
+ fetch_record_errors(local_issue, default_column: default_error_column)
31
+ false
32
+ end
33
+
9
34
  def local_issue_provider_attributes
10
35
  {
11
36
  subject: local_issue_subject, author: local_issue_author, status: local_issue_status,
12
37
  description: local_issue_description,
13
- created_on: provider_issue.created_on, updated_on: provider_issue.updated_on
38
+ created_on: provider_issue.created_on
14
39
  }
15
40
  end
16
41
 
@@ -23,7 +48,8 @@ module RedmineRemotes
23
48
 
24
49
  ::RemoteUser.find_local_user(
25
50
  provider_issue.author_login,
26
- remote_tracker
51
+ remote_tracker,
52
+ true
27
53
  )
28
54
  end
29
55
 
@@ -22,7 +22,7 @@ module RedmineRemotes
22
22
  def create
23
23
  ::Issue.transaction do
24
24
  return false unless valid?
25
- return false unless create_local_issue
25
+ return false unless save_local_issue
26
26
  return false unless create_remote_issue
27
27
  end
28
28
  true
@@ -6,20 +6,14 @@ module RedmineRemotes
6
6
  class Create < ::RedmineRemotes::Tableless::RemoteIssueFetch::Base
7
7
  private
8
8
 
9
- def create_local_issue
10
- return true if local_issue.save
11
-
12
- fetch_record_errors(local_issue, default_column: default_error_column)
13
- false
9
+ def local_issue_provider_attributes
10
+ super.merge(
11
+ project: project, tracker: local_tracker, priority: local_issue_priority
12
+ )
14
13
  end
15
14
 
16
15
  def local_issue_uncached
17
- remote_issue_by_remote_code.if_present { |v| return v.local_issue }
18
- ::Issue.new(
19
- local_issue_provider_attributes.merge(
20
- project: project, tracker: local_tracker, priority: local_issue_priority
21
- )
22
- )
16
+ remote_issue_by_remote_code.if_present(&:local_issue) || ::Issue.new
23
17
  end
24
18
 
25
19
  def local_issue_priority
@@ -20,7 +20,7 @@ module RedmineRemotes
20
20
 
21
21
  def save
22
22
  return false unless valid?
23
- return false unless update_local_issue_with_remote_data
23
+ return false unless save_local_issue
24
24
 
25
25
  true
26
26
  end
@@ -13,13 +13,6 @@ module RedmineRemotes
13
13
  def local_tracker
14
14
  local_issue.if_present(&:tracker)
15
15
  end
16
-
17
- def update_local_issue_with_remote_data
18
- return true if local_issue.update(local_issue_provider_attributes)
19
-
20
- fetch_record_errors(local_issue, default_column: default_error_column)
21
- false
22
- end
23
16
  end
24
17
  end
25
18
  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
@@ -31,12 +31,6 @@ class RemoteTracker < ActiveRecord::Base
31
31
  "#{root_url} [#{profile_label}, #{username}]"
32
32
  end
33
33
 
34
- def find_remote_issue(issue_id)
35
- raise 'Profile blank' if profile.blank?
36
-
37
- send("#{profile}_find_remote_issue", issue_id)
38
- end
39
-
40
34
  def setting_value(name)
41
35
  ::RemoteTrackerSetting.where(remote_tracker: self, name: name).first.if_present(&:value)
42
36
  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
@@ -30,10 +30,6 @@ module RedmineRemotes
30
30
  fields.fetch('status').fetch('name')
31
31
  end
32
32
 
33
- def updated_on
34
- fields.fetch('updated')
35
- end
36
-
37
33
  def author_login
38
34
  fields.try(:fetch, 'reporter').try(:fetch, 'key')
39
35
  end
@@ -3,7 +3,7 @@
3
3
  module RedmineRemotes
4
4
  SLUG = 'redmine_remotes'
5
5
  NAME = 'Redmine Remotes'
6
- VERSION = '0.8.1'
6
+ VERSION = '0.10.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.1
4
+ version: 0.10.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,10 @@ 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/remote.rb
149
143
  - app/models/remote_tracker_setting.rb
150
144
  - app/models/remote_user.rb
145
+ - app/models/remote_user/find_local_user.rb
151
146
  - app/views/project_remote_issues/_issues.html.erb
152
147
  - app/views/project_remote_issues/_trackers.html.erb
153
148
  - app/views/project_remote_issues/index.html.erb
@@ -170,6 +165,9 @@ files:
170
165
  - db/migrate/20200505161002_add_timestamps_to_remote_users.rb
171
166
  - init.rb
172
167
  - lib/redmine_remotes.rb
168
+ - lib/redmine_remotes/esosti.rb
169
+ - lib/redmine_remotes/esosti/entities/issue.rb
170
+ - lib/redmine_remotes/esosti/instance.rb
173
171
  - lib/redmine_remotes/jira/entities/issue.rb
174
172
  - lib/redmine_remotes/jira/instance.rb
175
173
  - 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