debian-mirror-gitlab/lib/api/entities/branch.rb

76 lines
2.3 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module API
module Entities
class Branch < Grape::Entity
2020-05-24 23:13:21 +05:30
include Gitlab::Routing
2023-01-13 00:05:48 +05:30
expose :name, documentation: { type: 'string', example: 'master' }
2020-03-13 15:44:24 +05:30
expose :commit, using: Entities::Commit do |repo_branch, options|
options[:project].repository.commit(repo_branch.dereferenced_target)
end
2023-01-13 00:05:48 +05:30
expose :merged,
documentation: {
type: 'boolean',
example: true
} do |repo_branch, options|
2020-03-13 15:44:24 +05:30
if options[:merged_branch_names]
options[:merged_branch_names].include?(repo_branch.name)
else
options[:project].repository.merged_to_root_ref?(repo_branch)
end
end
2023-01-13 00:05:48 +05:30
expose :protected,
documentation: {
type: 'boolean',
example: true
} do |repo_branch, options|
2020-03-13 15:44:24 +05:30
::ProtectedBranch.protected?(options[:project], repo_branch.name)
end
2023-01-13 00:05:48 +05:30
expose :developers_can_push,
documentation: {
type: 'boolean',
example: true
} do |repo_branch, options|
2020-03-13 15:44:24 +05:30
::ProtectedBranch.developers_can?(:push, repo_branch.name, protected_refs: options[:project].protected_branches)
end
2023-01-13 00:05:48 +05:30
expose :developers_can_merge,
documentation: {
type: 'boolean',
example: true
} do |repo_branch, options|
2020-03-13 15:44:24 +05:30
::ProtectedBranch.developers_can?(:merge, repo_branch.name, protected_refs: options[:project].protected_branches)
end
2023-01-13 00:05:48 +05:30
expose :can_push,
documentation: {
type: 'boolean',
example: true
} do |repo_branch, options|
2020-10-24 23:57:45 +05:30
Gitlab::UserAccess.new(options[:current_user], container: options[:project]).can_push_to_branch?(repo_branch.name)
2020-03-13 15:44:24 +05:30
end
2023-01-13 00:05:48 +05:30
expose :default,
documentation: {
type: 'boolean',
example: true
} do |repo_branch, options|
2020-03-13 15:44:24 +05:30
options[:project].default_branch == repo_branch.name
end
2020-05-24 23:13:21 +05:30
2023-01-13 00:05:48 +05:30
expose :web_url,
documentation: {
type: 'string',
example: 'https://gitlab.example.com/Commit921/the-dude/-/tree/master'
} do |repo_branch|
2020-05-24 23:13:21 +05:30
project_tree_url(options[:project], repo_branch.name)
end
2020-03-13 15:44:24 +05:30
end
end
end