Commit 414d695d authored by Robert Speicher's avatar Robert Speicher Committed by Robert Speicher

Merge branch 'fix-github-import-MR-wrong-project' into 'security'

Fix labels being applied to wrong merge requests on GitHub import

See https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2064
parent dd944bf1
---
title: Prevent the GitHub importer from assigning labels and comments to merge requests or issues belonging to other projects.
merge_request:
author:
...@@ -115,7 +115,7 @@ module Gitlab ...@@ -115,7 +115,7 @@ module Gitlab
begin begin
issuable = issuable =
if gh_issue.pull_request? if gh_issue.pull_request?
MergeRequest.find_by_iid(gh_issue.number) MergeRequest.find_by(target_project_id: project.id, iid: gh_issue.number)
else else
gh_issue.create! gh_issue.create!
end end
...@@ -212,8 +212,12 @@ module Gitlab ...@@ -212,8 +212,12 @@ module Gitlab
comment = CommentFormatter.new(project, raw) comment = CommentFormatter.new(project, raw)
# GH does not return info about comment's parent, so we guess it by checking its URL! # GH does not return info about comment's parent, so we guess it by checking its URL!
*_, parent, iid = URI(raw.html_url).path.split('/') *_, parent, iid = URI(raw.html_url).path.split('/')
issuable_class = parent == 'issues' ? Issue : MergeRequest if parent == 'issues'
issuable = issuable_class.find_by_iid(iid) issuable = Issue.find_by(project_id: project.id, iid: iid)
else
issuable = MergeRequest.find_by(target_project_id: project.id, iid: iid)
end
next unless issuable next unless issuable
issuable.notes.create!(comment.attributes) issuable.notes.create!(comment.attributes)
......
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