Commit b6da9707 authored by Patrick Derichs's avatar Patrick Derichs Committed by Sean McGivern

Action can be null

Remove obsolete comment
parent eb3fc14b
---
title: Fix merge requests being added to Jira Development Panel
merge_request: 10342
author:
type: fixed
......@@ -170,6 +170,38 @@ module API
expose :target_project, as: :repo, using: Repository
end
end
class PullRequestPayload < Grape::Entity
expose :action do |merge_request|
case merge_request.state
when 'merged', 'closed'
'closed'
else
'opened'
end
end
expose :id
expose :pull_request, using: PullRequest do |merge_request|
merge_request
end
end
class PullRequestEvent < Grape::Entity
expose :id do |merge_request|
updated_at = merge_request.updated_at.to_i
"#{merge_request.id}-#{updated_at}"
end
expose :type do |_merge_request|
'PullRequestEvent'
end
expose :updated_at, as: :created_at
expose :payload, using: PullRequestPayload do |merge_request|
# The merge request data is used by PullRequestPayload and PullRequest, so we just provide it
# here. Otherwise Grape::Entity would try to access a field "payload" on Merge Request.
merge_request
end
end
end
end
end
......@@ -131,6 +131,10 @@ module API
present find_merge_requests, with: ::API::Github::Entities::PullRequest
end
get '/-/jira/events' do
present []
end
params do
use :project_full_path
end
......@@ -142,6 +146,15 @@ module API
present paginate(merge_requests), with: ::API::Github::Entities::PullRequest
end
params do
use :project_full_path
end
get ':namespace/:project/pulls/:id', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
mr = find_merge_request_with_access(params[:id])
present mr, with: ::API::Github::Entities::PullRequest
end
# In Github, each Merge Request is automatically also an issue.
# Therefore we return its comments here.
# It'll present _just_ the comments counting with a link to GitLab on
......@@ -166,10 +179,12 @@ module API
# Self-hosted Jira (tested on 7.11.1) requests this endpoint right
# after fetching branches.
# We need to respond with a 200 request to avoid breaking the
# integration flow (fetching merge requests).
get ':namespace/:project/events' do
present []
user_project = find_project_with_access(params)
merge_requests = MergeRequestsFinder.new(current_user, authorized_only: true, project_id: user_project.id).execute
present paginate(merge_requests), with: ::API::Github::Entities::PullRequestEvent
end
params do
......
{
"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
}
}
\ No newline at end of file
......@@ -39,15 +39,6 @@ describe API::V3::Github do
end
shared_examples_for 'Jira-specific mimicked GitHub endpoints' do
describe 'GET /repos/.../events' do
it 'returns an empty array' do
jira_get v3_api("/repos/#{path}/events", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
describe 'GET /.../issues/:id/comments' do
context 'when user has access to the merge request' do
let(:merge_request) do
......@@ -116,12 +107,70 @@ describe API::V3::Github do
it_behaves_like 'Jira-specific mimicked GitHub endpoints' do
let(:path) { '-/jira' }
end
it 'returns an empty Array for events' do
jira_get v3_api("/repos/-/jira/events", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
context 'new :namespace/:project jira endpoints' do
it_behaves_like 'Jira-specific mimicked GitHub endpoints' do
let(:path) { "#{project.namespace.path}/#{project.path}" }
end
describe 'GET events' do
let(:group) { create(:group) }
let(:project) { create(:project, :empty_repo, group: group) }
let(:events_path) { "/repos/#{group.path}/#{project.path}/events" }
before do
stub_licensed_features(jira_dev_panel_integration: true)
end
context 'if there are no merge requests' do
it 'returns an empty array' do
jira_get v3_api(events_path, user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
context 'if there is a merge request' do
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) }
it 'returns an event' do
jira_get v3_api(events_path, user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(1)
end
end
context 'if there are more merge requests' do
let!(:merge_request) { create(:merge_request, id: 10000, source_project: project, target_project: project, author: user) }
let!(:merge_request2) { create(:merge_request, id: 10001, source_project: project, source_branch: generate(:branch), target_project: project, author: user) }
it 'returns the expected amount of events' do
jira_get v3_api(events_path, user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(2)
end
it 'ensures each event has a unique id' do
jira_get v3_api(events_path, user)
ids = json_response.map { |event| event['id'] }.uniq
expect(ids.size).to eq(2)
end
end
end
end
describe 'repo pulls' do
......@@ -158,6 +207,17 @@ describe API::V3::Github do
expect(response).to match_response_schema('entities/github/pull_requests', dir: 'ee')
end
end
describe 'GET /repos/:namespace/:project/pulls/:id' do
it 'returns the requested merge request in github format' do
stub_licensed_features(jira_dev_panel_integration: true)
jira_get v3_api("/repos/#{project.namespace.path}/#{project.path}/pulls/#{merge_request.id}", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('entities/github/pull_request', dir: 'ee')
end
end
end
describe 'GET /users/:namespace/repos' do
......
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