From 354ce75009a40c822c12c06b0ced30ce1aa5138c Mon Sep 17 00:00:00 2001
From: Pedro Pombeiro <noreply@pedro.pombei.ro>
Date: Wed, 15 May 2024 22:19:50 +0000
Subject: [PATCH] GraphQL: Expose CiRunnerType.registration_type

---
 .../types/ci/runner_creation_method_enum.rb      | 16 ++++++++++++++++
 app/graphql/types/ci/runner_type.rb              |  4 ++++
 doc/api/graphql/reference/index.md               |  8 ++++++++
 spec/graphql/types/ci/runner_type_spec.rb        |  2 +-
 spec/requests/api/graphql/ci/runner_spec.rb      |  7 ++++---
 5 files changed, 33 insertions(+), 4 deletions(-)
 create mode 100644 app/graphql/types/ci/runner_creation_method_enum.rb

diff --git a/app/graphql/types/ci/runner_creation_method_enum.rb b/app/graphql/types/ci/runner_creation_method_enum.rb
new file mode 100644
index 000000000000..265acc24643a
--- /dev/null
+++ b/app/graphql/types/ci/runner_creation_method_enum.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module Types
+  module Ci
+    class RunnerCreationMethodEnum < BaseEnum
+      graphql_name 'CiRunnerCreationMethod'
+
+      value 'REGISTRATION_TOKEN',
+        description: 'Applies to a runner that was created by a runner registration token.',
+        value: 'registration_token'
+      value 'AUTHENTICATED_USER',
+        description: 'Applies to a runner that was created by an authenticated user.',
+        value: 'authenticated_user'
+    end
+  end
+end
diff --git a/app/graphql/types/ci/runner_type.rb b/app/graphql/types/ci/runner_type.rb
index ba4cf1be19b5..8cae308b5d02 100644
--- a/app/graphql/types/ci/runner_type.rb
+++ b/app/graphql/types/ci/runner_type.rb
@@ -31,6 +31,10 @@ class RunnerType < BaseObject
       field :created_by, Types::UserType, null: true,
         description: 'User that created this runner.',
         method: :creator
+      field :creation_method, Types::Ci::RunnerCreationMethodEnum, null: true,
+        method: :registration_type,
+        description: 'Type of runner registration.',
+        alpha: { milestone: '17.0' }
       field :description, GraphQL::Types::String, null: true,
         description: 'Description of the runner.'
       field :edit_admin_url, GraphQL::Types::String, null: true,
diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md
index b8b8a0114e67..2ec458b623e8 100644
--- a/doc/api/graphql/reference/index.md
+++ b/doc/api/graphql/reference/index.md
@@ -17588,6 +17588,7 @@ CI/CD variables for a project.
 | <a id="cirunnercontactedat"></a>`contactedAt` | [`Time`](#time) | Timestamp of last contact from this runner. |
 | <a id="cirunnercreatedat"></a>`createdAt` | [`Time`](#time) | Timestamp of creation of this runner. |
 | <a id="cirunnercreatedby"></a>`createdBy` | [`UserCore`](#usercore) | User that created this runner. |
+| <a id="cirunnercreationmethod"></a>`creationMethod` **{warning-solid}** | [`CiRunnerCreationMethod`](#cirunnercreationmethod) | **Introduced** in GitLab 17.0. **Status**: Experiment. Type of runner registration. |
 | <a id="cirunnerdescription"></a>`description` | [`String`](#string) | Description of the runner. |
 | <a id="cirunnereditadminurl"></a>`editAdminUrl` | [`String`](#string) | Admin form URL of the runner. Only available for administrators. |
 | <a id="cirunnerephemeralauthenticationtoken"></a>`ephemeralAuthenticationToken` **{warning-solid}** | [`String`](#string) | **Introduced** in GitLab 15.9. **Status**: Experiment. Ephemeral authentication token used for runner manager registration. Only available for the creator of the runner for a limited time during registration. |
@@ -32670,6 +32671,13 @@ Runner cloud provider.
 | ----- | ----------- |
 | <a id="cirunnercloudprovidergoogle_cloud"></a>`GOOGLE_CLOUD` | Google Cloud. |
 
+### `CiRunnerCreationMethod`
+
+| Value | Description |
+| ----- | ----------- |
+| <a id="cirunnercreationmethodauthenticated_user"></a>`AUTHENTICATED_USER` | Applies to a runner that was created by an authenticated user. |
+| <a id="cirunnercreationmethodregistration_token"></a>`REGISTRATION_TOKEN` | Applies to a runner that was created by a runner registration token. |
+
 ### `CiRunnerJobExecutionStatus`
 
 | Value | Description |
diff --git a/spec/graphql/types/ci/runner_type_spec.rb b/spec/graphql/types/ci/runner_type_spec.rb
index cbfea04e71dc..6ca4edf4d71f 100644
--- a/spec/graphql/types/ci/runner_type_spec.rb
+++ b/spec/graphql/types/ci/runner_type_spec.rb
@@ -13,7 +13,7 @@
       short_sha locked run_untagged runner_type tag_list
       project_count job_count admin_url edit_admin_url register_admin_url user_permissions
       maintenance_note maintenance_note_html groups projects jobs token_expires_at
-      owner_project job_execution_status ephemeral_authentication_token ephemeral_register_url
+      owner_project job_execution_status ephemeral_authentication_token ephemeral_register_url creation_method
     ]
 
     expect(described_class).to include_graphql_fields(*expected_fields)
diff --git a/spec/requests/api/graphql/ci/runner_spec.rb b/spec/requests/api/graphql/ci/runner_spec.rb
index 8117b7430519..fc5aa59b731c 100644
--- a/spec/requests/api/graphql/ci/runner_spec.rb
+++ b/spec/requests/api/graphql/ci/runner_spec.rb
@@ -88,6 +88,7 @@
         access_level: runner.access_level.to_s.upcase,
         run_untagged: runner.run_untagged,
         runner_type: runner.instance_type? ? 'INSTANCE_TYPE' : 'PROJECT_TYPE',
+        creation_method: runner.authenticated_user_registration_type? ? 'AUTHENTICATED_USER' : 'REGISTRATION_TOKEN',
         ephemeral_authentication_token: nil,
         maintenance_note: runner.maintenance_note,
         maintenance_note_html:
@@ -542,8 +543,8 @@
     it_behaves_like 'runner details fetch'
   end
 
-  describe 'for registration type' do
-    context 'when registered with registration token' do
+  describe 'for creation method' do
+    context 'when created with registration token' do
       let(:runner) do
         create(:ci_runner, registration_type: :registration_token)
       end
@@ -551,7 +552,7 @@
       it_behaves_like 'runner details fetch'
     end
 
-    context 'when registered with authenticated user' do
+    context 'when created by authenticated user' do
       let(:runner) do
         create(:ci_runner, registration_type: :authenticated_user)
       end
-- 
GitLab