Commit a7eadf96 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '336405-add-runner-edit-url' into 'master'

Return runner editUrl via GraphQL API

See merge request gitlab-org/gitlab!80926
parents 6b3f14a5 4f27ed7c
......@@ -6,6 +6,9 @@ module Types
class RunnerWebUrlEdge < ::Types::BaseEdge
include FindClosest
field :edit_url, GraphQL::Types::String, null: true,
description: 'Web URL of the runner edit page. The value depends on where you put this field in the query. You can use it for projects or groups.',
extras: [:parent]
field :web_url, GraphQL::Types::String, null: true,
description: 'Web URL of the runner. The value depends on where you put this field in the query. You can use it for projects or groups.',
extras: [:parent]
......@@ -16,14 +19,26 @@ module Types
@runner = node.node
end
def edit_url(parent:)
runner_url(parent: parent, url_type: :edit_url)
end
def web_url(parent:)
runner_url(parent: parent, url_type: :default)
end
private
def runner_url(parent:, url_type: :default)
owner = closest_parent([::Types::ProjectType, ::Types::GroupType], parent)
# Only ::Group is supported at the moment, future iterations will include ::Project.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/16338
case owner
when ::Group
return Gitlab::Routing.url_helpers.edit_group_runner_url(owner, @runner) if url_type == :edit_url
Gitlab::Routing.url_helpers.group_runner_url(owner, @runner)
when ::Project
Gitlab::Routing.url_helpers.project_runner_url(owner, @runner)
end
end
end
......
......@@ -5756,6 +5756,7 @@ The edge type for [`CiRunner`](#cirunner).
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="cirunneredgecursor"></a>`cursor` | [`String!`](#string) | A cursor for use in pagination. |
| <a id="cirunneredgeediturl"></a>`editUrl` | [`String`](#string) | Web URL of the runner edit page. The value depends on where you put this field in the query. You can use it for projects or groups. |
| <a id="cirunneredgenode"></a>`node` | [`CiRunner`](#cirunner) | The item at the end of the edge. |
| <a id="cirunneredgeweburl"></a>`webUrl` | [`String`](#string) | Web URL of the runner. The value depends on where you put this field in the query. You can use it for projects or groups. |
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::Ci::RunnerWebUrlEdge do
specify { expect(described_class.graphql_name).to eq('RunnerWebUrlEdge') }
it 'contains URL attributes' do
expected_fields = %w[edit_url web_url]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
......@@ -196,39 +196,6 @@ RSpec.describe 'Query.runner(id)' do
it_behaves_like 'runner details fetch', :inactive_instance_runner
end
describe 'for runner inside group request' do
let(:query) do
%(
query {
group(fullPath: "#{group.full_path}") {
runners {
edges {
webUrl
node {
id
}
}
}
}
}
)
end
it 'retrieves webUrl field with expected value' do
post_graphql(query, current_user: user)
runner_data = graphql_data_at(:group, :runners, :edges)
expect(runner_data).to match_array [
a_hash_including(
'webUrl' => "http://localhost/groups/#{group.full_path}/-/runners/#{active_group_runner.id}",
'node' => {
'id' => active_group_runner.to_global_id.to_s
}
)
]
end
end
describe 'for group runner request' do
let(:query) do
%(
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'RunnerWebUrlEdge' do
include GraphqlHelpers
describe 'inside a Query.group' do
let_it_be(:group) { create(:group) }
let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) }
let(:edges_graphql_data) { graphql_data.dig('group', 'runners', 'edges') }
let(:query) do
<<~GQL
query($path: ID!) {
group(fullPath: $path) {
runners {
edges {
editUrl
webUrl
}
}
}
}
GQL
end
before do
post_graphql(query, current_user: user, variables: { path: group.full_path })
end
context 'with an authorized user' do
let(:user) { create_default(:user, :admin) }
it_behaves_like 'a working graphql query'
it 'returns correct URLs' do
expect(edges_graphql_data).to match_array [
{
'editUrl' => Gitlab::Routing.url_helpers.edit_group_runner_url(group, group_runner),
'webUrl' => Gitlab::Routing.url_helpers.group_runner_url(group, group_runner)
}
]
end
end
context 'with an unauthorized user' do
let(:user) { create(:user) }
it_behaves_like 'a working graphql query'
it 'returns no edges' do
expect(edges_graphql_data).to be_empty
end
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