mirror of
https://github.com/rickbarrette/redmine_qbo_calendar.git
synced 2026-11-17 21:50:37 -05:00
Relate all issues created from the same estimate, across batches
- New issues from the estimate preview are now related to each other and to every issue created earlier from the same estimate; older batches that weren't related to each other are linked too - Pairs that already have any relation are skipped - New rake task redmine_qbo_calendar:relate_estimate_issues relates issues created before this change (safe to re-run) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
3 files changed
+62
-15
No files matched your search
@@ -16,7 +16,7 @@ module RedmineQboCalendar
|
||||
# - Subject = the line's description; estimated hours = the line's quantity
|
||||
# - Lines already turned into issues are shown but can't be created again
|
||||
# - Creation is all-or-nothing: if any issue fails validation, none are saved
|
||||
# - Issues created together are all related to each other
|
||||
# - All issues created from the same estimate are related to each other, across batches
|
||||
class EstimateIssueBuilder
|
||||
include Redmine::I18n
|
||||
|
||||
@@ -53,6 +53,34 @@ module RedmineQboCalendar
|
||||
codes.map { |c| c.strip.downcase }.any? { |code| name == code || parts.include?(code) }
|
||||
end
|
||||
|
||||
# Relates every issue in the list to every other one ("Related to"), skipping pairs that already
|
||||
# have any relation. Used for issues created from the same estimate, whichever batch they came from.
|
||||
# Issues loaded fresh have no open journal, so this adds no history entries and sends no
|
||||
# "issue updated" emails. A failed relation (e.g. cross-project relations disabled) is logged, not fatal.
|
||||
# Returns the number of relations created.
|
||||
def self.relate_all(issues)
|
||||
issues = issues.compact.uniq(&:id)
|
||||
return 0 if issues.size < 2
|
||||
|
||||
ids = issues.map(&:id)
|
||||
already_related = IssueRelation.where(issue_from_id: ids, issue_to_id: ids)
|
||||
.pluck(:issue_from_id, :issue_to_id)
|
||||
.map(&:minmax)
|
||||
.to_set
|
||||
|
||||
issues.combination(2).count do |issue_from, issue_to|
|
||||
next false if already_related.include?([issue_from.id, issue_to.id].minmax)
|
||||
|
||||
relation = IssueRelation.new(issue_from: issue_from, issue_to: issue_to,
|
||||
relation_type: IssueRelation::TYPE_RELATES)
|
||||
next true if relation.save
|
||||
|
||||
Rails.logger.warn "[EstimateIssueBuilder] Could not relate ##{issue_from.id} and ##{issue_to.id}: " \
|
||||
"#{relation.errors.full_messages.join(', ')}"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :appointment, :errors
|
||||
|
||||
def initialize(appointment)
|
||||
@@ -157,18 +185,13 @@ module RedmineQboCalendar
|
||||
key.to_s
|
||||
end
|
||||
|
||||
# Relates every issue in the batch to every other one ("Related to"), since they're work on the
|
||||
# same estimate done at the same time. New issues have no open journal, so this adds no history
|
||||
# entries and sends no "issue updated" emails. A failed relation is logged, not fatal.
|
||||
def relate_issues(issues)
|
||||
issues.combination(2).each do |issue_from, issue_to|
|
||||
relation = IssueRelation.new(issue_from: issue_from, issue_to: issue_to,
|
||||
relation_type: IssueRelation::TYPE_RELATES)
|
||||
next if relation.save
|
||||
|
||||
Rails.logger.warn "[EstimateIssueBuilder] Could not relate ##{issue_from.id} and ##{issue_to.id}: " \
|
||||
"#{relation.errors.full_messages.join(', ')}"
|
||||
end
|
||||
# Relates the new issues to each other and to every issue created earlier from the same estimate.
|
||||
def relate_issues(new_issues)
|
||||
earlier = AppointmentEstimateIssue.where(estimate_id: estimate.id)
|
||||
.where.not(issue_id: new_issues.map(&:id))
|
||||
.includes(:issue)
|
||||
.filter_map(&:issue)
|
||||
self.class.relate_all(earlier + new_issues)
|
||||
end
|
||||
|
||||
def build_issue(proposal, row, project, author, allowed_trackers, custom_field_values)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
namespace :redmine_qbo_calendar do
|
||||
desc 'Relate all issues created from the same QBO estimate to each other (one-time catch-up; safe to re-run)'
|
||||
task relate_estimate_issues: :environment do
|
||||
total = 0
|
||||
estimates = AppointmentEstimateIssue.distinct.pluck(:estimate_id)
|
||||
|
||||
estimates.each do |estimate_id|
|
||||
issues = AppointmentEstimateIssue.where(estimate_id: estimate_id).includes(:issue).filter_map(&:issue)
|
||||
total += RedmineQboCalendar::EstimateIssueBuilder.relate_all(issues)
|
||||
end
|
||||
|
||||
puts "Checked #{estimates.size} estimate(s), created #{total} relation(s)."
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user