sync_issues 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/sync_issues/comparison.rb +19 -8
- data/lib/sync_issues/github.rb +7 -3
- data/lib/sync_issues/issue.rb +13 -12
- data/lib/sync_issues/synchronizer.rb +1 -1
- data/lib/sync_issues/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79925614f29788d3b54461146e6b224d5563b341
|
4
|
+
data.tar.gz: 5e47b0f0f9425ac917c31117442a3449757c8c13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
66
|
-
|
67
|
-
|
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 :
|
6
|
+
attr_reader :assignees, :changed, :content, :labels, :title
|
7
7
|
|
8
8
|
def initialize(issue, github_issue, reset_labels: false,
|
9
|
-
|
9
|
+
sync_assignees: true, sync_labels: true)
|
10
10
|
@changed = []
|
11
|
-
@
|
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,
|
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,
|
25
|
-
if
|
26
|
-
@changed << '
|
27
|
-
@
|
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)
|
data/lib/sync_issues/github.rb
CHANGED
@@ -12,9 +12,9 @@ module SyncIssues
|
|
12
12
|
@client.auto_paginate = true
|
13
13
|
end
|
14
14
|
|
15
|
-
def create_issue(repository, issue,
|
15
|
+
def create_issue(repository, issue, add_assignees, add_labels)
|
16
16
|
kwargs = {}
|
17
|
-
kwargs[:assignee] = issue.
|
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.
|
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
|
data/lib/sync_issues/issue.rb
CHANGED
@@ -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 :
|
9
|
+
attr_reader :assignees, :content, :labels, :new_title, :title
|
10
10
|
|
11
|
-
def initialize(content, title:,
|
12
|
-
@
|
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 =
|
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
|
22
|
-
return nil if
|
23
|
-
if
|
24
|
-
[verify_string(
|
25
|
-
elsif !
|
26
|
-
raise IssueError, "'
|
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
|
-
|
29
|
-
verify_string("
|
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
|
-
|
99
|
+
sync_assignees: @sync_assignees,
|
100
100
|
sync_labels: @sync_labels)
|
101
101
|
return unless comparison.changed?
|
102
102
|
|
data/lib/sync_issues/version.rb
CHANGED
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.
|
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.
|
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.
|
40
|
+
version: '4.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: safe_yaml
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|