forked from Gitlink/forgeplus
36 lines
978 B
Ruby
36 lines
978 B
Ruby
class Branches::ListService < ApplicationService
|
|
|
|
attr_reader :user, :project, :name
|
|
|
|
def initialize(user, project, name=nil)
|
|
@user = user
|
|
@project = project
|
|
@name = name
|
|
end
|
|
|
|
def call
|
|
all_branches = []
|
|
user_name = user.try(:show_real_name)
|
|
identifier = project.repository.try(:identifier)
|
|
get_all_branches = Gitea::Repository::Branches::ListService.new(user, identifier, name).call
|
|
all_branches = branch_lists(user_name,user.try(:login), identifier, get_all_branches) if get_all_branches && get_all_branches.size > 0
|
|
return all_branches
|
|
end
|
|
|
|
def branch_lists(user_name,user_login, identifier, branches)
|
|
branches_array = []
|
|
branches.each do |b|
|
|
branch_params = {
|
|
user_name: user_name,
|
|
user_login: user_login,
|
|
identifier: identifier,
|
|
name: b["name"],
|
|
can_merge: b["user_can_merge"],
|
|
}
|
|
branches_array.push(branch_params)
|
|
end
|
|
return branches_array
|
|
end
|
|
|
|
end
|