Commit df85905f authored by Patrick Derichs's avatar Patrick Derichs Committed by Kamil Trzciński

Add endpoint for Jira to request user information

Also reduced a bit of duplication and
created a user.json schema file which
is referenced by pull_request.json and
pull_requests.json references
pull_request.json now.
Moved content of "url" field to "html_url"

According to https://developer.github.com/v3/users the "url" field
should contain an api url - not the html url.

Additionally Jira Pull Requests are now showing an avatar of the PR
author.

Add changelog entry

Add missing mr number

Add specs

Expose url of user in url and html_url

I decided against returning an empty string for url (which is,
according to api documentation, supposed to return an api endpoint
instead of a user profile page) but make it return the profile page
as before so the changes won't break any existing code.

Remove extra blank line
parent 3c6b8f8d
---
title: Add missing endpoint for user information to GitHub API
merge_request: 10482
author:
type: fixed
......@@ -115,8 +115,14 @@ module API
class User < Grape::Entity
expose :id
expose :username, as: :login
expose :url do |user|
Gitlab::Routing.url_helpers.user_url(user)
expose :user_url, as: :url
expose :user_url, as: :html_url
expose :avatar_url
private
def user_url
Gitlab::Routing.url_helpers.user_url(object)
end
end
......
......@@ -118,6 +118,13 @@ module API
present paginate(projects), with: ::API::Github::Entities::Repository
end
get ':username' do
forbidden! unless can?(current_user, :read_users_list)
user = UsersFinder.new(current_user, { username: params[:username] }).execute.first
not_found! unless user
present user, with: ::API::Github::Entities::User
end
end
# Jira dev panel integration weirdly requests for "/-/jira/pulls" instead
......
......@@ -44,44 +44,10 @@
"type": "date"
},
"assignee": {
"type": "object",
"required": [
"id",
"login",
"url"
],
"properties": {
"id": {
"type": "integer"
},
"login": {
"type": "string"
},
"url": {
"type": "string"
}
},
"additionalProperties": false
"$ref": "user.json"
},
"author": {
"type": "object",
"required": [
"id",
"login",
"url"
],
"properties": {
"id": {
"type": "integer"
},
"login": {
"type": "string"
},
"url": {
"type": "string"
}
},
"additionalProperties": false
"$ref": "user.json"
},
"head": {
"type": "object",
......
{
"type": "array",
"items": {
"type": "object",
"properties" : {
"title": { "type": "string" },
"created_at": { "type": "string" },
"body": { "type": ["string", "null"] },
"id": { "type": "integer" },
"number": { "type": "integer" },
"state": { "type": "string" },
"html_url": { "type": "string" },
"merged": { "type": "boolean" },
"merged_at": { "type": ["date", "null"] },
"closed_at": { "type": ["date", "null"] },
"updated_at": { "type": "date" },
"assignee": {
"type": "object",
"required": ["id", "login", "url"],
"properties" : {
"id": { "type": "integer" },
"login": { "type": "string" },
"url": { "type": "string" }
},
"additionalProperties": false
},
"author": {
"type": "object",
"required": ["id", "login", "url"],
"properties" : {
"id": { "type": "integer" },
"login": { "type": "string" },
"url": { "type": "string" }
},
"additionalProperties": false
},
"head": {
"type": "object",
"required": ["label", "ref", "repo"],
"properties" : {
"label": { "type": "string" },
"ref": { "type": "string" },
"repo": {
"oneOf": [
{ "type": "null" },
{ "$ref": "repository.json" }
]
}
},
"additionalProperties": false
},
"base": {
"type": "object",
"required": ["label", "ref", "repo"],
"properties" : {
"label": { "type": "string" },
"ref": { "type": "string" },
"repo": {
"oneOf": [
{ "type": "null" },
{ "$ref": "repository.json" }
]
}
},
"additionalProperties": false
},
"additionalProperties": false
}
"$ref": "pull_request.json"
}
}
{
"type": "object",
"required": ["id", "login", "url", "avatar_url"],
"properties" : {
"id": { "type": "integer" },
"login": { "type": "string" },
"url": { "type": "string" },
"avatar_url": { "type": "string" },
"html_url": { "type": "string" }
},
"additionalProperties": false
}
......@@ -121,6 +121,46 @@ describe API::V3::Github do
let(:path) { "#{project.namespace.path}/#{project.path}" }
end
describe 'GET /users/:username' do
let!(:user1) { create(:user, username: 'jane') }
before do
stub_licensed_features(jira_dev_panel_integration: true)
end
context 'user exists' do
it 'responds with the expected user' do
jira_get v3_api('/users/jane', user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('entities/github/user', dir: 'ee')
end
end
context 'user does not exist' do
it 'responds with the expected status' do
jira_get v3_api('/users/unknown_user_name', user)
expect(response).to have_gitlab_http_status(404)
end
end
context 'no rights to request user lists' do
let(:unauthorized_user) { create(:user) }
before do
expect(Ability).to receive(:allowed?).with(unauthorized_user, :read_users_list, :global).and_return(false)
expect(Ability).to receive(:allowed?).at_least(:once).and_call_original
end
it 'responds with forbidden' do
jira_get v3_api('/users/jane', unauthorized_user)
expect(response).to have_gitlab_http_status(403)
end
end
end
describe 'GET events' do
let(:group) { create(:group) }
let(:project) { create(:project, :empty_repo, group: group) }
......
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