sync_issues 0.7.0 → 0.8.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
  SHA1:
3
- metadata.gz: 99ef37bc236b9d418bc2026635fd15cb0257e668
4
- data.tar.gz: 6fdfee2a75ffff873f3071892b9f6bcc09121333
3
+ metadata.gz: 79925614f29788d3b54461146e6b224d5563b341
4
+ data.tar.gz: 5e47b0f0f9425ac917c31117442a3449757c8c13
5
5
  SHA512:
6
- metadata.gz: a0f5d617d4924d1c239090b6b6776bc8a4f3ed9c44fb292724ea4c180f502447d5358ff34003b28629d80711b86af8abb892ac6ac726a3474c0f853780a278bb
7
- data.tar.gz: 1059944a2820a11895d67771c11619f642a1aba981d1d902c3bb871584056fcaf4d668892a7777c78053549187eadc6413cd47538d4599b8371831c16581dd0a
6
+ metadata.gz: 10dda1d05a6f9fd0d6da1bb867cf6a096568bdbefcf557247a8c3c0eca6e958f28ea1d0c7943c802329f616571536074201c770a2e10247315c3a5cf33c59998
7
+ data.tar.gz: 3e7eb16a7d7fba78b80c1ae666520205d0a103ffc89b64748185624426b826e94d0066d8a0bce857de69089c69d721cd307d0edd46a1ea5cf1cf5449f825410a
data/README.md CHANGED
@@ -62,9 +62,11 @@ The frontmatter of an issue file can contain the following attributes:
62
62
 
63
63
  * __title__: (required) Used as the title of the issue on GitHub. The title is
64
64
  used as the unique key when syncing updated tasks with existing issues.
65
- * __assignee__: (optional) Assign or reassign the issue to the github username
66
- specified. Existing assignee will not be removed on sync if the field is not
67
- provided.
65
+
66
+ * __assignees__: (optional) Assign or reassign the issue to the github
67
+ usernames specified. Existing assignees will not be removed on sync if the
68
+ field is not provided.
69
+
68
70
  * __labels__: (optional) When provided and the issue does not have any labels
69
71
  this list of labels will be added to the issue. Labels will be dynamically
70
72
  created with the default grey color if they don't already exist on the
@@ -3,16 +3,18 @@ require_relative 'error'
3
3
  module SyncIssues
4
4
  # Comparison represents differences between Issues (local and GitHub)
5
5
  class Comparison
6
- attr_reader :assignee, :changed, :content, :labels, :title
6
+ attr_reader :assignees, :changed, :content, :labels, :title
7
7
 
8
8
  def initialize(issue, github_issue, reset_labels: false,
9
- sync_assignee: true, sync_labels: true)
9
+ sync_assignees: true, sync_labels: true)
10
10
  @changed = []
11
- @assignee = github_issue.assignee && github_issue.assignee.login
11
+ @assignees = github_issue.assignees.map do |assignee|
12
+ assignee.login
13
+ end.sort
12
14
  @content = github_issue.body
13
15
  @labels = github_issue.labels.map { |label| label[:name] }
14
16
  @title = github_issue.title
15
- compare(issue, reset_labels, sync_assignee, sync_labels)
17
+ compare(issue, reset_labels, sync_assignees, sync_labels)
16
18
  end
17
19
 
18
20
  def changed?
@@ -21,10 +23,10 @@ module SyncIssues
21
23
 
22
24
  private
23
25
 
24
- def compare(issue, reset_labels, sync_assignee, sync_labels)
25
- if sync_assignee && issue.assignee != @assignee
26
- @changed << 'assignee'
27
- @assignee = issue.assignee
26
+ def compare(issue, reset_labels, sync_assignees, sync_labels)
27
+ if sync_assignees && update_assignees?(issue)
28
+ @changed << 'assignees'
29
+ @assignees = issue.assignees
28
30
  end
29
31
  if sync_labels && update_label?(issue, reset_labels)
30
32
  @changed << 'labels'
@@ -44,11 +46,20 @@ module SyncIssues
44
46
  first.gsub(/\[x\]/, '[ ]') == second.gsub(/\[x\]/, '[ ]')
45
47
  end
46
48
 
49
+ def assignees_match?(new_assignees)
50
+ # Assignee uniqueness is not case-sensitive.
51
+ new_assignees.map(&:downcase) == @assignees.map(&:downcase)
52
+ end
53
+
47
54
  def labels_match?(new_labels)
48
55
  # Label uniqueness is not case-sensitive.
49
56
  new_labels.map(&:downcase) == @labels.map(&:downcase)
50
57
  end
51
58
 
59
+ def update_assignees?(issue)
60
+ !issue.assignees.nil? && !assignees_match?(issue.assignees)
61
+ end
62
+
52
63
  def update_label?(issue, reset_labels)
53
64
  !issue.labels.nil? && (reset_labels && !labels_match?(issue.labels) ||
54
65
  @labels.size == 0)
@@ -12,9 +12,9 @@ module SyncIssues
12
12
  @client.auto_paginate = true
13
13
  end
14
14
 
15
- def create_issue(repository, issue, add_assignee, add_labels)
15
+ def create_issue(repository, issue, add_assignees, add_labels)
16
16
  kwargs = {}
17
- kwargs[:assignee] = issue.assignee if add_assignee
17
+ kwargs[:assignee] = issue.assignees[0] if add_assignees
18
18
  kwargs[:labels] = issue.labels if add_labels
19
19
  @client.create_issue(repository.full_name, issue.title, issue.content,
20
20
  **kwargs)
@@ -39,8 +39,12 @@ module SyncIssues
39
39
  def update_issue(repository, issue_number, comparison)
40
40
  @client.update_issue(repository.full_name, issue_number,
41
41
  comparison.title, comparison.content,
42
- assignee: comparison.assignee,
42
+ assignee: comparison.assignees[0],
43
43
  labels: comparison.labels)
44
+ if comparison.assignees.size > 1
45
+ @client.add_assignees(repository.full_name, issue_number,
46
+ comparison.assignees[1..-1])
47
+ end
44
48
  end
45
49
 
46
50
  private
@@ -6,27 +6,28 @@ module SyncIssues
6
6
  # new_title is only used when an issue should be renamed. Issues with
7
7
  # new_title set will never be created
8
8
  class Issue
9
- attr_reader :assignee, :content, :labels, :new_title, :title
9
+ attr_reader :assignees, :content, :labels, :new_title, :title
10
10
 
11
- def initialize(content, title:, assignee: nil, labels: nil, new_title: nil)
12
- @assignee = verify_string 'assignee', assignee
11
+ def initialize(content, title:, assignees: nil, labels: nil, new_title: nil)
12
+ @assignees = verify_array_or_string 'assignees', assignees
13
+ @assignees.sort! unless @assignees.nil?
13
14
  @content = content
14
- @labels = verify_labels(labels)
15
+ @labels = verify_array_or_string 'labels', labels
15
16
  @new_title = verify_string 'new_title', new_title, allow_nil: true
16
17
  @title = verify_string 'title', title, allow_nil: false
17
18
  end
18
19
 
19
20
  private
20
21
 
21
- def verify_labels(labels)
22
- return nil if labels.nil?
23
- if labels.is_a?(String)
24
- [verify_string('labels', labels, allow_nil: false)]
25
- elsif !labels.is_a?(Array)
26
- raise IssueError, "'labels' must be an Array or a String"
22
+ def verify_array_or_string(field, items)
23
+ return nil if items.nil?
24
+ if items.is_a?(String)
25
+ [verify_string(field, items, allow_nil: false)]
26
+ elsif !items.is_a?(Array)
27
+ raise IssueError, "'#{field}' must be an Array or a String"
27
28
  else
28
- labels.each_with_index.map do |label, i|
29
- verify_string("labels[#{i}]", label, allow_nil: false)
29
+ items.each_with_index.map do |item, i|
30
+ verify_string("#{field}[#{i}]", item, allow_nil: false)
30
31
  end
31
32
  end
32
33
  end
@@ -96,7 +96,7 @@ module SyncIssues
96
96
  def update_issue(repository, issue, github_issue)
97
97
  comparison = Comparison.new(issue, github_issue,
98
98
  reset_labels: @reset_labels,
99
- sync_assignee: @sync_assignees,
99
+ sync_assignees: @sync_assignees,
100
100
  sync_labels: @sync_labels)
101
101
  return unless comparison.changed?
102
102
 
@@ -1,4 +1,4 @@
1
1
  # SyncIssues
2
2
  module SyncIssues
3
- VERSION = '0.7.0'.freeze
3
+ VERSION = '0.8.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_issues
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce Boe
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
33
+ version: '4.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.2'
40
+ version: '4.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: safe_yaml
43
43
  requirement: !ruby/object:Gem::Requirement