class SyncIssues::Comparison
Comparison
represents differences between Issues (local and GitHub
)
Attributes
assignees[R]
changed[R]
content[R]
labels[R]
title[R]
Public Class Methods
new(issue, github_issue, reset_labels: false, sync_assignees: true, sync_labels: true)
click to toggle source
# File lib/sync_issues/comparison.rb, line 8 def initialize(issue, github_issue, reset_labels: false, sync_assignees: true, sync_labels: true) @changed = [] @assignees = github_issue.assignees.map do |assignee| assignee.login end.sort @content = github_issue.body @labels = github_issue.labels.map { |label| label[:name] } @title = github_issue.title compare(issue, reset_labels, sync_assignees, sync_labels) end
Public Instance Methods
changed?()
click to toggle source
# File lib/sync_issues/comparison.rb, line 20 def changed? !@changed.empty? end
Private Instance Methods
assignees_match?(new_assignees)
click to toggle source
# File lib/sync_issues/comparison.rb, line 49 def assignees_match?(new_assignees) # Assignee uniqueness is not case-sensitive. new_assignees.map(&:downcase) == @assignees.map(&:downcase) end
compare(issue, reset_labels, sync_assignees, sync_labels)
click to toggle source
# File lib/sync_issues/comparison.rb, line 26 def compare(issue, reset_labels, sync_assignees, sync_labels) if sync_assignees && update_assignees?(issue) @changed << 'assignees' @assignees = issue.assignees end if sync_labels && update_label?(issue, reset_labels) @changed << 'labels' @labels = issue.labels end unless issue.new_title.nil? @changed << 'title' @title = issue.new_title end return if content_matches?(issue.content, @content) @changed << 'body' @content = issue.content end
content_matches?(first, second)
click to toggle source
# File lib/sync_issues/comparison.rb, line 44 def content_matches?(first, second) second.delete!("\r") first.gsub(/\[x\]/, '[ ]') == second.gsub(/\[x\]/, '[ ]') end
labels_match?(new_labels)
click to toggle source
# File lib/sync_issues/comparison.rb, line 54 def labels_match?(new_labels) # Label uniqueness is not case-sensitive. new_labels.map(&:downcase) == @labels.map(&:downcase) end
update_assignees?(issue)
click to toggle source
# File lib/sync_issues/comparison.rb, line 59 def update_assignees?(issue) !issue.assignees.nil? && !assignees_match?(issue.assignees) end
update_label?(issue, reset_labels)
click to toggle source
# File lib/sync_issues/comparison.rb, line 63 def update_label?(issue, reset_labels) !issue.labels.nil? && (reset_labels && !labels_match?(issue.labels) || @labels.size == 0) end