Commit a55e1501 authored by Rémy Coutable's avatar Rémy Coutable

Set `label_ids` and `assignee_ids` after the initial `save!`.

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent f96b4f41
...@@ -99,7 +99,7 @@ module Github ...@@ -99,7 +99,7 @@ module Github
label.color = representation.color label.color = representation.color
end end
cached[:label_ids][label.title] = label.id cached[:label_ids][representation.title] = label.id
rescue => e rescue => e
error(:label, representation.url, e.message) error(:label, representation.url, e.message)
end end
...@@ -211,11 +211,11 @@ module Github ...@@ -211,11 +211,11 @@ module Github
# for both features, like manipulating assignees, labels # for both features, like manipulating assignees, labels
# and milestones, are provided within the Issues API. # and milestones, are provided within the Issues API.
if representation.pull_request? if representation.pull_request?
return unless representation.has_labels? || representation.has_comments? return unless representation.labels? || representation.has_comments?
merge_request = MergeRequest.find_by!(target_project_id: project.id, iid: representation.iid) merge_request = MergeRequest.find_by!(target_project_id: project.id, iid: representation.iid)
if representation.has_labels? if representation.labels?
merge_request.update_attribute(:label_ids, label_ids(representation.labels)) merge_request.update_attribute(:label_ids, label_ids(representation.labels))
end end
...@@ -230,14 +230,16 @@ module Github ...@@ -230,14 +230,16 @@ module Github
issue.title = representation.title issue.title = representation.title
issue.description = format_description(representation.description, representation.author) issue.description = format_description(representation.description, representation.author)
issue.state = representation.state issue.state = representation.state
issue.label_ids = label_ids(representation.labels)
issue.milestone_id = milestone_id(representation.milestone) issue.milestone_id = milestone_id(representation.milestone)
issue.author_id = author_id issue.author_id = author_id
issue.assignee_ids = [user_id(representation.assignee)]
issue.created_at = representation.created_at issue.created_at = representation.created_at
issue.updated_at = representation.updated_at issue.updated_at = representation.updated_at
issue.save!(validate: false) issue.save!(validate: false)
issue.update(
label_ids: label_ids(representation.labels),
assignee_ids: assignee_ids(representation.assignees))
fetch_comments_conditionally(issue, representation) fetch_comments_conditionally(issue, representation)
end end
rescue => e rescue => e
...@@ -310,7 +312,11 @@ module Github ...@@ -310,7 +312,11 @@ module Github
end end
def label_ids(labels) def label_ids(labels)
labels.map { |attrs| cached[:label_ids][attrs.fetch('name')] }.compact labels.map { |label| cached[:label_ids][label.title] }.compact
end
def assignee_ids(assignees)
assignees.map { |assignee| user_id(assignee) }.compact
end end
def milestone_id(milestone) def milestone_id(milestone)
......
...@@ -23,14 +23,16 @@ module Github ...@@ -23,14 +23,16 @@ module Github
@author ||= Github::Representation::User.new(raw['user'], options) @author ||= Github::Representation::User.new(raw['user'], options)
end end
def assignee def labels?
return unless assigned? raw['labels'].any?
@assignee ||= Github::Representation::User.new(raw['assignee'], options)
end end
def assigned? def labels
raw['assignee'].present? return [] unless labels?
@labels ||= raw['labels'].map do |label|
Github::Representation::Label.new(label, options)
end
end end
end end
end end
......
module Github module Github
module Representation module Representation
class Issue < Representation::Issuable class Issue < Representation::Issuable
def labels
raw['labels']
end
def state def state
raw['state'] == 'closed' ? 'closed' : 'opened' raw['state'] == 'closed' ? 'closed' : 'opened'
end end
...@@ -13,13 +9,21 @@ module Github ...@@ -13,13 +9,21 @@ module Github
raw['comments'] > 0 raw['comments'] > 0
end end
def has_labels?
labels.count > 0
end
def pull_request? def pull_request?
raw['pull_request'].present? raw['pull_request'].present?
end end
def assigned?
raw['assignees'].present?
end
def assignees
return [] unless assigned?
@assignees ||= raw['assignees'].map do |user|
Github::Representation::User.new(user, options)
end
end
end end
end end
end end
...@@ -37,6 +37,16 @@ module Github ...@@ -37,6 +37,16 @@ module Github
source_branch.valid? && target_branch.valid? source_branch.valid? && target_branch.valid?
end end
def assigned?
raw['assignee'].present?
end
def assignee
return unless assigned?
@assignee ||= Github::Representation::User.new(raw['assignee'], options)
end
private private
def project def project
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment