Commit 706b9e77 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '214547_expose_web_url' into 'master'

Add `web_url` to branch endpoint response

See merge request gitlab-org/gitlab!30147
parents bba1620f 8abf0db0
---
title: Add `web_url` to branch API response
merge_request: 30147
author:
type: added
......@@ -41,6 +41,7 @@ Example response:
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"web_url": "http://gitlab.example.com/my-group/my-project/-/tree/master",
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
......@@ -96,6 +97,7 @@ Example response:
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"web_url": "http://gitlab.example.com/my-group/my-project/-/tree/master",
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
......@@ -171,7 +173,8 @@ Example response:
"default": false,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true
"can_push": true,
"web_url": "http://gitlab.example.com/my-group/my-project/-/tree/newbranch"
}
```
......
......@@ -3,6 +3,8 @@
module API
module Entities
class Branch < Grape::Entity
include Gitlab::Routing
expose :name
expose :commit, using: Entities::Commit do |repo_branch, options|
......@@ -36,6 +38,10 @@ module API
expose :default do |repo_branch, options|
options[:project].default_branch == repo_branch.name
end
expose :web_url do |repo_branch|
project_tree_url(options[:project], repo_branch.name)
end
end
end
end
......@@ -7,7 +7,8 @@
"protected",
"default",
"developers_can_push",
"developers_can_merge"
"developers_can_merge",
"web_url"
],
"properties" : {
"name": { "type": "string" },
......@@ -17,7 +18,8 @@
"default": { "type": "boolean" },
"developers_can_push": { "type": "boolean" },
"developers_can_merge": { "type": "boolean" },
"can_push": { "type": "boolean" }
"can_push": { "type": "boolean" },
"web_url": { "type": "uri" }
},
"additionalProperties": false
}
# frozen_string_literal: true
require 'spec_helper'
describe API::Entities::Branch do
describe '#as_json' do
subject { entity.as_json }
let(:project) { create(:project, :public, :repository) }
let(:repository) { project.repository }
let(:branch) { repository.find_branch('master') }
let(:entity) { described_class.new(branch, project: project) }
it 'includes basic fields', :aggregate_failures do
is_expected.to include(
name: 'master',
commit: a_kind_of(Hash),
merged: false,
protected: false,
developers_can_push: false,
developers_can_merge: false,
can_push: false,
default: true,
web_url: Gitlab::Routing.url_helpers.project_tree_url(project, 'master')
)
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