Commit 7d17f9dc authored by GitLab Bot's avatar GitLab Bot

Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-10-26

parents edd6fc97 91765b80
......@@ -9,6 +9,14 @@ export default {
componentUpdated(el) {
$(el).tooltip('_fixTitle');
// update visible tooltips
const tooltipInstance = $(el).data('bs.tooltip');
const tip = tooltipInstance.getTipElement();
tooltipInstance.setElementContent(
$(tip.querySelectorAll('.tooltip-inner')),
tooltipInstance.getTitle(),
);
},
unbind(el) {
......
---
title: Add license data to projects endpoint
merge_request: 21606
author: J.D. Bean (@jdbean)
type: added
......@@ -453,6 +453,7 @@ GET /projects/:id
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) |
| `statistics` | boolean | no | Include project statistics |
| `license` | boolean | no | Include project license data |
| `with_custom_attributes` | boolean | no | Include [custom attributes](custom_attributes.md) in response (admins only) |
```json
......@@ -510,6 +511,14 @@ GET /projects/:id
},
"archived": false,
"avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png",
"license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE",
"license": {
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0",
"nickname": "GNU LGPLv3",
"html_url": "http://choosealicense.com/licenses/lgpl-3.0/",
"source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
},
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
......@@ -576,6 +585,14 @@ If the project is a fork, and you provide a valid token to authenticate, the
"http_url_to_repo":"https://gitlab.com/gitlab-org/gitlab-ce.git",
"web_url":"https://gitlab.com/gitlab-org/gitlab-ce",
"avatar_url":"https://assets.gitlab-static.net/uploads/-/system/project/avatar/13083/logo-extra-whitespace.png",
"license_url": "https://gitlab.com/gitlab-org/gitlab-ce/blob/master/LICENSE",
"license": {
"key": "mit",
"name": "MIT License",
"nickname": null,
"html_url": "http://choosealicense.com/licenses/mit/",
"source_url": "https://opensource.org/licenses/MIT",
},
"star_count":3812,
"forks_count":3561,
"last_activity_at":"2018-01-02T11:40:26.570Z",
......@@ -938,6 +955,14 @@ Example response:
"import_status": "none",
"archived": true,
"avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png",
"license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE",
"license": {
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0",
"nickname": "GNU LGPLv3",
"html_url": "http://choosealicense.com/licenses/lgpl-3.0/",
"source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
},
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 1,
......@@ -1016,6 +1041,14 @@ Example response:
"import_status": "none",
"archived": true,
"avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png",
"license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE",
"license": {
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0",
"nickname": "GNU LGPLv3",
"html_url": "http://choosealicense.com/licenses/lgpl-3.0/",
"source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
},
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
......@@ -1134,6 +1167,14 @@ Example response:
},
"archived": true,
"avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png",
"license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE",
"license": {
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0",
"nickname": "GNU LGPLv3",
"html_url": "http://choosealicense.com/licenses/lgpl-3.0/",
"source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
},
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
......@@ -1230,6 +1271,14 @@ Example response:
},
"archived": false,
"avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png",
"license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE",
"license": {
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0",
"nickname": "GNU LGPLv3",
"html_url": "http://choosealicense.com/licenses/lgpl-3.0/",
"source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
},
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
......
......@@ -160,13 +160,27 @@ module API
# (fixed in https://github.com/rails/rails/pull/25976).
project.tags.map(&:name).sort
end
expose :ssh_url_to_repo, :http_url_to_repo, :web_url, :readme_url
expose :license_url, if: :license do |project|
license = project.repository.license_blob
if license
Gitlab::Routing.url_helpers.project_blob_url(project, File.join(project.default_branch, license.path))
end
end
expose :license, with: 'API::Entities::LicenseBasic', if: :license do |project|
project.repository.license
end
expose :avatar_url do |project, options|
project.avatar_url(only_path: false)
end
expose :star_count, :forks_count
expose :last_activity_at
expose :namespace, using: 'API::Entities::NamespaceBasic'
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
......@@ -1236,11 +1250,14 @@ module API
expose :deployable, using: Entities::Job
end
class License < Grape::Entity
class LicenseBasic < Grape::Entity
expose :key, :name, :nickname
expose :popular?, as: :popular
expose :url, as: :html_url
expose(:source_url) { |license| license.meta['source'] }
end
class License < LicenseBasic
expose :popular?, as: :popular
expose(:description) { |license| license.meta['description'] }
expose(:conditions) { |license| license.meta['conditions'] }
expose(:permissions) { |license| license.meta['permissions'] }
......
......@@ -116,7 +116,8 @@ module API
options = options.reverse_merge(
with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
statistics: params[:statistics],
current_user: current_user
current_user: current_user,
license: false
)
options[:with] = Entities::BasicProjectDetails if params[:simple]
......@@ -232,13 +233,17 @@ module API
params do
use :statistics_params
use :with_custom_attributes
optional :license, type: Boolean, default: false,
desc: 'Include project license data'
end
get ":id" do
options = {
with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
current_user: current_user,
user_can_admin_project: can?(current_user, :admin_project, user_project),
statistics: params[:statistics]
statistics: params[:statistics],
license: params[:license]
}
project, options = with_custom_attributes(user_project, options)
......
......@@ -13,24 +13,45 @@ describe('Tooltip directive', () => {
describe('with a single tooltip', () => {
beforeEach(() => {
const SomeComponent = Vue.extend({
setFixtures('<div id="dummy-element"></div>');
vm = new Vue({
el: '#dummy-element',
directives: {
tooltip,
},
template: `
<div
v-tooltip
title="foo">
</div>
`,
data() {
return {
tooltip: 'some text',
};
},
template: '<div v-tooltip :title="tooltip"></div>',
});
vm = new SomeComponent().$mount();
});
it('should have tooltip plugin applied', () => {
expect($(vm.$el).data('bs.tooltip')).toBeDefined();
});
it('displays the title as tooltip', () => {
$(vm.$el).tooltip('show');
const tooltipElement = document.querySelector('.tooltip-inner');
expect(tooltipElement.innerText).toContain('some text');
});
it('updates a visible tooltip', done => {
$(vm.$el).tooltip('show');
const tooltipElement = document.querySelector('.tooltip-inner');
vm.tooltip = 'other text';
Vue.nextTick()
.then(() => {
expect(tooltipElement).toContainText('other text');
done();
})
.catch(done.fail);
});
});
describe('with multiple tooltips', () => {
......
......@@ -200,6 +200,24 @@ describe API::Projects do
expect(json_response.first).to include 'statistics'
end
it "does not include license by default" do
get api('/projects', user)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.first).not_to include('license', 'license_url')
end
it "does not include license if requested" do
get api('/projects', user), license: true
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.first).not_to include('license', 'license_url')
end
context 'when external issue tracker is enabled' do
let!(:jira_service) { create(:jira_service, project: project) }
......@@ -1044,6 +1062,26 @@ describe API::Projects do
})
end
it "does not include license fields by default" do
get api("/projects/#{project.id}", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).not_to include('license', 'license_url')
end
it 'includes license fields when requested' do
get api("/projects/#{project.id}", user), license: true
expect(response).to have_gitlab_http_status(200)
expect(json_response['license']).to eq({
'key' => project.repository.license.key,
'name' => project.repository.license.name,
'nickname' => project.repository.license.nickname,
'html_url' => project.repository.license.url,
'source_url' => project.repository.license.meta['source']
})
end
it "does not include statistics by default" do
get api("/projects/#{project.id}", user)
......
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