Commit d9959427 authored by Izaak Alpert's avatar Izaak Alpert

Style changes from review with @randx

-Some changes around calling origional methods for !for_fork? merge requests. Other changes to follow

Change-Id: I009c716ce2475b9efa3fd07aee9215fca7a1c150
parent 128f2845
......@@ -124,7 +124,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@target_branches
end
def ci_status
status = project.gitlab_ci_service.commit_status(merge_request.last_commit.sha)
response = {status: status}
......@@ -134,12 +133,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
protected
def selected_target_project
((@project.id.to_s == params[:target_project_id]) || @project.forked_project_link.nil?) ? @project : @project.forked_project_link.forked_from_project
end
def merge_request
@merge_request ||= MergeRequest.find_by_id(params[:id])
end
......
......@@ -13,7 +13,6 @@ module MergeRequestsHelper
)
end
def new_mr_from_push_event(event, target_project)
return :merge_request => {
source_project_id: event.project.id,
......
......@@ -2,7 +2,7 @@ module Emails
module MergeRequests
def new_merge_request_email(recipient_id, merge_request_id)
@merge_request = MergeRequest.find(merge_request_id)
mail(to: @merge_request.assignee_email, subject: subject("new merge request !#{@merge_request.id}", @merge_request.title))
mail(to: recipient(recipient_id), subject: subject("new merge request !#{@merge_request.id}", @merge_request.title))
end
def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id)
......
......@@ -26,8 +26,8 @@ class MergeRequest < ActiveRecord::Base
include Issuable
belongs_to :target_project, :foreign_key => :target_project_id, class_name: "Project"
belongs_to :source_project, :foreign_key => :source_project_id, class_name: "Project"
belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project"
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
attr_accessible :title, :assignee_id, :source_project_id, :source_branch, :target_project_id, :target_branch, :milestone_id, :author_id_of_changes, :state_event
......@@ -149,7 +149,11 @@ class MergeRequest < ActiveRecord::Base
end
def unmerged_diffs
if for_fork?
diffs = Gitlab::Satellite::MergeAction.new(author, self).diffs_between_satellite
else
diffs = target_project.repository.diffs_between(source_branch, target_branch)
end
diffs ||= []
diffs
end
......@@ -185,7 +189,11 @@ class MergeRequest < ActiveRecord::Base
end
def unmerged_commits
if for_fork?
commits = Gitlab::Satellite::MergeAction.new(self.author, self).commits_between
else
commits = target_project.repository.commits_between(self.target_branch, self.source_branch)
end
if commits.present?
commits = Commit.decorate(commits).
sort_by(&:created_at).
......
......@@ -32,8 +32,8 @@ class Note < ActiveRecord::Base
delegate :name, :email, to: :author, prefix: true
validates :note, :project, presence: true
validates :line_code, format: {with: /\A[a-z0-9]+_\d+_\d+\Z/}, allow_blank: true
validates :attachment, file_size: {maximum: 10.megabytes.to_i}
validates :line_code, format: { with: /\A[a-z0-9]+_\d+_\d+\Z/ }, allow_blank: true
validates :attachment, file_size: { maximum: 10.megabytes.to_i }
validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' }
validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' }
......@@ -42,13 +42,13 @@ class Note < ActiveRecord::Base
# Scopes
scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) }
scope :inline, -> { where("line_code IS NOT NULL") }
scope :not_inline, -> { where(line_code: [nil, '']) }
scope :inline, ->{ where("line_code IS NOT NULL") }
scope :not_inline, ->{ where(line_code: [nil, '']) }
scope :common, -> { where(noteable_type: ["", nil]) }
scope :fresh, -> { order("created_at ASC, id ASC") }
scope :inc_author_project, -> { includes(:project, :author) }
scope :inc_author, -> { includes(:author) }
scope :common, ->{ where(noteable_type: ["", nil]) }
scope :fresh, ->{ order("created_at ASC, id ASC") }
scope :inc_author_project, ->{ includes(:project, :author) }
scope :inc_author, ->{ includes(:author) }
def self.create_status_change_note(noteable, project, author, status)
create({
......
......@@ -2,8 +2,7 @@ class MergeRequestObserver < ActivityObserver
observe :merge_request
def after_create(merge_request)
event_author_id = merge_request.author_id
if event_author_id
if merge_request.author_id
create_event(merge_request, Event.determine_action(merge_request))
end
......@@ -41,7 +40,6 @@ class MergeRequestObserver < ActivityObserver
notification.reassigned_merge_request(merge_request, current_user) if merge_request.is_being_reassigned?
end
def create_event(record, status)
Event.create(
project: record.target_project,
......
......@@ -80,9 +80,7 @@ class NotificationService
# * project team members with notification level higher then Participating
#
def merge_mr(merge_request)
recipients = reject_muted_users([merge_request.author, merge_request.assignee], merge_request.source_project)
recipients = recipients.concat(reject_muted_users([merge_request.author, merge_request.assignee], merge_request.target_project))
recipients = recipients.concat(project_watchers(merge_request.source_project))
recipients = reject_muted_users([merge_request.author, merge_request.assignee], merge_request.target_project)
recipients = recipients.concat(project_watchers(merge_request.target_project)).uniq
recipients.each do |recipient|
......@@ -104,7 +102,7 @@ class NotificationService
# ignore wall messages
return true unless note.noteable_type.present?
opts = {noteable_type: note.noteable_type, project_id: note.project_id}
opts = { noteable_type: note.noteable_type, project_id: note.project_id }
if note.commit_id.present?
opts.merge!(commit_id: note.commit_id)
......
......@@ -5,4 +5,4 @@
%span= day.stamp("28 Aug, 2010")
.pull-right
%small= pluralize(commits.count, 'commit')
%ul.well-list= render commits, :project => @project
%ul.well-list= render commits, project: @project
= form_for [@source_project, @merge_request], html: { class: "#{controller.action_name}-merge-request form-horizontal" } do |form_helper|
= form_for [@source_project, @merge_request], html: { class: "#{controller.action_name}-merge-request form-horizontal" } do |f|
-if @merge_request.errors.any?
.alert.alert-error
%ul
......@@ -51,9 +51,9 @@
.form-actions
- if @merge_request.new_record?
= form_helper.submit 'Submit merge request', class: "btn btn-create"
= f.submit 'Submit merge request', class: "btn btn-create"
-else
= form_helper.submit 'Save changes', class: "btn btn-save"
= f.submit 'Save changes', class: "btn btn-save"
- if @merge_request.new_record?
= link_to project_merge_requests_path(@source_project), class: "btn btn-cancel" do
Cancel
......
......@@ -8,9 +8,14 @@
= "MERGED"
- else
%span.pull-right
- if merge_request.for_fork?
= "#{merge_request.source_project.path_with_namespace}/#{merge_request.source_branch}"
%i.icon-angle-right
= "#{merge_request.target_project.path_with_namespace}/#{merge_request.target_branch}"
- else
= "#{merge_request.source_branch}"
%i.icon-angle-right
= "#{merge_request.target_branch}"
.merge-request-info
- if merge_request.author
authored by #{link_to_member(merge_request.source_project, merge_request.author)}
......
%h3.page-title
= "Merge Request ##{@merge_request.id}:"
&nbsp;
-if @merge_request.for_fork?
%span.label-project= @merge_request.source_project.path_with_namespace
%span.label-branch= @merge_request.source_branch
&rarr;
%span.label-project= @merge_request.target_project.path_with_namespace
%span.label-branch= @merge_request.target_branch
- else
%span.label-branch= @merge_request.source_branch
&rarr;
%span.label-branch= @merge_request.target_branch
%span.pull-right
- if can?(current_user, :modify_merge_request, @merge_request)
......
......@@ -26,7 +26,10 @@
%span ##{merge_request.id}
%strong.term
= truncate merge_request.title, length: 50
- if merge_request.for_fork?
%span.light (#{merge_request.source_project.name_with_namespace}:#{merge_request.source_branch} &rarr; #{merge_request.target_project.name_with_namespace}:#{merge_request.target_branch})
- else
%span.light (#{merge_request.source_branch} &rarr; #{merge_request.target_branch})
- @issues.each do |issue|
%li
issue:
......
......@@ -2,7 +2,7 @@ class AllowMergesForForks < ActiveRecord::Migration
def self.up
add_column :merge_requests, :target_project_id, :integer, :null => false
MergeRequest.connection.execute("update merge_requests set target_project_id=project_id")
MergeRequest.update_all("target_project_id = project_id")
rename_column :merge_requests, :project_id, :source_project_id
end
......
......@@ -20,7 +20,6 @@ Feature: Project Forked Merge Requests
And I submit the merge request
Then I should see merge request "Merge Request On Forked Project"
@javascript
Scenario: I should see a push widget for forked merge requests
Given project "Forked Shop" has push event
......@@ -39,7 +38,6 @@ Feature: Project Forked Merge Requests
And I click link edit "Merge Request On Forked Project"
Then I see the edit page prefilled for "Merge Request On Forked Project"
@javascript
Scenario: I cannot submit an invalid merge request
Given I visit project "Forked Shop" merge requests page
......
module Gitlab
module Satellite
class Action
DEFAULT_OPTIONS = {git_timeout: 30.seconds}
DEFAULT_OPTIONS = { git_timeout: 30.seconds }
attr_accessor :options, :project, :user
......@@ -39,8 +39,8 @@ module Gitlab
def prepare_satellite!(repo)
project.satellite.clear_and_update!
repo.config['user.name']=user.name
repo.config['user.email']=user.email
repo.config['user.name'] = user.name
repo.config['user.email'] = user.email
end
def default_options(options = {})
......
module Gitlab
class SatelliteNotExistError < StandardError;
end
class SatelliteNotExistError < StandardError; end
module Satellite
class Satellite
......@@ -22,9 +21,9 @@ module Gitlab
raise SatelliteNotExistError.new("Satellite doesn't exist")
end
def clear_and_update!
raise_no_satellite unless exists?
File.exists? path
@repo = nil
clear_working_dir!
......@@ -68,7 +67,6 @@ module Gitlab
end
end
def lock_file
create_locks_dir unless File.exists?(lock_files_dir)
File.join(lock_files_dir, "satellite_#{project.id}.lock")
......
......@@ -7,7 +7,6 @@ INVALID_FACTORIES = [
FactoryGirl.factories.map(&:name).each do |factory_name|
next if INVALID_FACTORIES.include?(factory_name)
describe "#{factory_name} factory" do
it 'should be valid' do
build(factory_name).should be_valid
......
......@@ -21,7 +21,6 @@ describe "Application access" do
let(:reporter) { create(:user) }
before do
# full access
project.team << [master, :master]
......
require 'spec_helper'
describe 'Gitlab::Satellite::Action' do
let(:project) { create(:project_with_code) }
let(:user) { create(:user) }
describe '#prepare_satellite!' do
it 'create a repository with a parking branch and one remote: origin' do
......@@ -50,11 +47,8 @@ describe 'Gitlab::Satellite::Action' do
repo.config['user.name'].should ==user.name
repo.config['user.email'].should ==user.email
end
end
describe '#in_locked_and_timed_satellite' do
it 'should make use of a lockfile' do
......
......@@ -11,7 +11,6 @@ describe 'Gitlab::Satellite::MergeAction' do
#these commits are quite close together, itended to make string diffs/format patches small
@close_commit1 = ['2_3_notes_fix', '8470d70da67355c9c009e4401746b1d5410af2e3']
@close_commit2 = ['scss_refactoring', 'f0f14c8eaba69ebddd766498a9d0b0e79becd633']
end
let(:project) { create(:project_with_code) }
......@@ -53,7 +52,6 @@ describe 'Gitlab::Satellite::MergeAction' do
end
end
describe '#format_patch' do
context 'on fork' do
it 'should build a format patch' do
......@@ -76,7 +74,6 @@ describe 'Gitlab::Satellite::MergeAction' do
end
end
describe '#diffs_between_satellite tested against diff_in_satellite' do
def is_a_matching_diff(diff, diffs)
......@@ -109,7 +106,6 @@ describe 'Gitlab::Satellite::MergeAction' do
merge_request.source_branch = @master[0]
diffs = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diffs_between_satellite
merge_request.target_branch = @close_commit1[0]
merge_request.source_branch = @master[0]
diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diff_in_satellite
......@@ -119,7 +115,6 @@ describe 'Gitlab::Satellite::MergeAction' do
end
end
describe '#can_be_merged?' do
context 'on fork' do
it 'return true or false depending on if something is mergable' do
......@@ -145,5 +140,4 @@ describe 'Gitlab::Satellite::MergeAction' do
end
end
end
end
\ No newline at end of file
......@@ -90,7 +90,6 @@ describe MergeRequestObserver do
end
end
describe "Merge Request created" do
def self.it_should_be_valid_event
it { @event.should_not be_nil }
......
......@@ -15,8 +15,7 @@ describe API::API do
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
before {
project.team << [user, :reporter] }
before { project.team << [user, :reporter] }
describe "GET /projects" do
context "when unauthenticated" do
......@@ -48,16 +47,16 @@ describe API::API do
it "should not create new project" do
expect {
post api("/projects", user2), name: 'foo'
}.to change { Project.count }.by(0)
}.to change {Project.count}.by(0)
end
end
it "should create new project without path" do
expect { post api("/projects", user), name: 'foo' }.to change { Project.count }.by(1)
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
end
it "should not create new project without name" do
expect { post api("/projects", user) }.to_not change { Project.count }
expect { post api("/projects", user) }.to_not change {Project.count}
end
it "should return a 400 error if name not given" do
......@@ -101,7 +100,7 @@ describe API::API do
post api("/projects", user), project
project.each_pair do |k, v|
project.each_pair do |k,v|
next if k == :path
json_response[k.to_s].should == v
end
......@@ -127,11 +126,11 @@ describe API::API do
before { admin }
it "should create new project without path" do
expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change { Project.count }.by(1)
expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change {Project.count}.by(1)
end
it "should not create new project without name" do
expect { post api("/projects/user/#{user.id}", admin) }.to_not change { Project.count }
expect { post api("/projects/user/#{user.id}", admin) }.to_not change {Project.count}
end
it "should respond with 201 on success" do
......@@ -156,7 +155,7 @@ describe API::API do
post api("/projects/user/#{user.id}", admin), project
project.each_pair do |k, v|
project.each_pair do |k,v|
next if k == :path
json_response[k.to_s].should == v
end
......@@ -414,7 +413,7 @@ describe API::API do
expect {
post api("/projects/#{project.id}/hooks", user),
url: "http://example.com"
}.to change { project.hooks.count }.by(1)
}.to change {project.hooks.count}.by(1)
response.status.should == 201
end
......@@ -457,7 +456,7 @@ describe API::API do
it "should delete hook from project" do
expect {
delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
}.to change { project.hooks.count }.by(-1)
}.to change {project.hooks.count}.by(-1)
response.status.should == 200
end
......@@ -477,7 +476,6 @@ describe API::API do
end
end
describe "GET /projects/:id/snippets" do
it "should return an array of project snippets" do
get api("/projects/#{project.id}/snippets", user)
......@@ -600,7 +598,7 @@ describe API::API do
describe "POST /projects/:id/keys" do
it "should not create an invalid ssh key" do
post api("/projects/#{project.id}/keys", user), {title: "invalid key"}
post api("/projects/#{project.id}/keys", user), { title: "invalid key" }
response.status.should == 404
end
......@@ -608,7 +606,7 @@ describe API::API do
key_attrs = attributes_for :key
expect {
post api("/projects/#{project.id}/keys", user), key_attrs
}.to change { project.deploy_keys.count }.by(1)
}.to change{ project.deploy_keys.count }.by(1)
end
end
......@@ -618,7 +616,7 @@ describe API::API do
it "should delete existing key" do
expect {
delete api("/projects/#{project.id}/keys/#{deploy_key.id}", user)
}.to change { project.deploy_keys.count }.by(-1)
}.to change{ project.deploy_keys.count }.by(-1)
end
it "should return 404 Not Found with invalid ID" do
......
......@@ -170,6 +170,4 @@ module TestEnv
command = "git init --quiet --bare #{path};"
system(command)
end
end
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