Commit 3c2d6b48 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add a class that represents a git push operation

parent ba66e0cc
...@@ -57,10 +57,10 @@ module MergeRequests ...@@ -57,10 +57,10 @@ module MergeRequests
# Returns all origin and fork merge requests from `@project` satisfying passed arguments. # Returns all origin and fork merge requests from `@project` satisfying passed arguments.
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def merge_requests_for(source_branch, mr_states: [:opened]) def merge_requests_for(source_branch, mr_states: [:opened])
MergeRequest @project.source_of_merge_requests
.with_state(mr_states) .with_state(mr_states)
.where(source_branch: source_branch, source_project_id: @project.id) .where(source_branch: source_branch)
.preload(:source_project) # we don't need a #includes since we're just preloading for the #select .preload(:source_project) # we don't need #includes since we're just preloading for the #select
.select(&:source_project) .select(&:source_project)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
# frozen_string_literal: true
module Gitlab
module Git
class Push
def initialize(project, oldrev, newrev, ref)
@project, @oldrev, @newrev = project, oldrev, newrev
@repository = project.repository
@branch_name = Gitlab::Git.ref_name(ref)
end
def branch_added?
Gitlab::Git.blank_ref?(@oldrev)
end
def branch_removed?
Gitlab::Git.blank_ref?(@newrev)
end
def force_push?
Gitlab::Checks::ForcePush.force_push?(@project, @oldrev, @newrev)
end
end
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