From 79cb541b8cc00f170ed43e360d1accc7178ccc4e Mon Sep 17 00:00:00 2001
From: Lee Tickett <lee@tickett.net>
Date: Tue, 6 Sep 2022 11:11:17 +0100
Subject: [PATCH] Add id, size and expiry to GraphQL Job Artifact

Changelog: added
---
 .../table/graphql/queries/get_jobs.query.graphql         | 1 +
 .../graphql/queries/get_pipeline_jobs.query.graphql      | 1 +
 ...ity_report_merge_request_download_paths.query.graphql | 1 +
 ...security_report_pipeline_download_paths.query.graphql | 1 +
 app/graphql/types/ci/job_artifact_type.rb                | 9 +++++++++
 doc/api/graphql/reference/index.md                       | 3 +++
 .../pipeline_security_report_summary.query.graphql       | 1 +
 spec/graphql/types/ci/job_artifact_type_spec.rb          | 2 +-
 8 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/app/assets/javascripts/jobs/components/table/graphql/queries/get_jobs.query.graphql b/app/assets/javascripts/jobs/components/table/graphql/queries/get_jobs.query.graphql
index 98b51e8c2c406..851be211b255e 100644
--- a/app/assets/javascripts/jobs/components/table/graphql/queries/get_jobs.query.graphql
+++ b/app/assets/javascripts/jobs/components/table/graphql/queries/get_jobs.query.graphql
@@ -11,6 +11,7 @@ query getJobs($fullPath: ID!, $after: String, $first: Int = 30, $statuses: [CiJo
       }
       nodes {
         artifacts {
+          # eslint-disable-next-line @graphql-eslint/require-id-when-available
           nodes {
             downloadPath
             fileType
diff --git a/app/assets/javascripts/pipelines/graphql/queries/get_pipeline_jobs.query.graphql b/app/assets/javascripts/pipelines/graphql/queries/get_pipeline_jobs.query.graphql
index 641ec7a3cf6a3..b0f875160d483 100644
--- a/app/assets/javascripts/pipelines/graphql/queries/get_pipeline_jobs.query.graphql
+++ b/app/assets/javascripts/pipelines/graphql/queries/get_pipeline_jobs.query.graphql
@@ -11,6 +11,7 @@ query getPipelineJobs($fullPath: ID!, $iid: ID!, $after: String) {
         }
         nodes {
           artifacts {
+            # eslint-disable-next-line @graphql-eslint/require-id-when-available
             nodes {
               downloadPath
               fileType
diff --git a/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_merge_request_download_paths.query.graphql b/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_merge_request_download_paths.query.graphql
index 2e80db30e9a40..6a83669d20641 100644
--- a/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_merge_request_download_paths.query.graphql
+++ b/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_merge_request_download_paths.query.graphql
@@ -14,6 +14,7 @@ query securityReportDownloadPaths(
             id
             name
             artifacts {
+              # eslint-disable-next-line @graphql-eslint/require-id-when-available
               nodes {
                 downloadPath
                 fileType
diff --git a/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_pipeline_download_paths.query.graphql b/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_pipeline_download_paths.query.graphql
index e4f0c392b9158..1f1e56a587660 100644
--- a/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_pipeline_download_paths.query.graphql
+++ b/app/assets/javascripts/vue_shared/security_reports/graphql/queries/security_report_pipeline_download_paths.query.graphql
@@ -4,6 +4,7 @@ query getPipelineCorpuses($projectPath: ID!, $iid: ID, $reportTypes: [SecurityRe
   project(fullPath: $projectPath) {
     id
     pipeline(iid: $iid) {
+      # eslint-disable-next-line @graphql-eslint/require-id-when-available
       ...JobArtifacts
     }
   }
diff --git a/app/graphql/types/ci/job_artifact_type.rb b/app/graphql/types/ci/job_artifact_type.rb
index a6ab445702ced..6346d50de3a9c 100644
--- a/app/graphql/types/ci/job_artifact_type.rb
+++ b/app/graphql/types/ci/job_artifact_type.rb
@@ -6,6 +6,9 @@ module Ci
     class JobArtifactType < BaseObject
       graphql_name 'CiJobArtifact'
 
+      field :id, Types::GlobalIDType[::Ci::JobArtifact], null: false,
+                                                         description: 'ID of the artifact.'
+
       field :download_path, GraphQL::Types::String, null: true,
                                                     description: "URL for downloading the artifact's file."
 
@@ -16,6 +19,12 @@ class JobArtifactType < BaseObject
                                            description: 'File name of the artifact.',
                                            method: :filename
 
+      field :size, GraphQL::Types::Int, null: false,
+                                        description: 'Size of the artifact in bytes.'
+
+      field :expire_at, Types::TimeType, null: true,
+                                         description: 'Expiry date of the artifact.'
+
       def download_path
         ::Gitlab::Routing.url_helpers.download_project_job_artifacts_path(
           object.project,
diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md
index eecdcf8b69ab5..bcffccf7140e6 100644
--- a/doc/api/graphql/reference/index.md
+++ b/doc/api/graphql/reference/index.md
@@ -10288,8 +10288,11 @@ CI/CD variables for a GitLab instance.
 | Name | Type | Description |
 | ---- | ---- | ----------- |
 | <a id="cijobartifactdownloadpath"></a>`downloadPath` | [`String`](#string) | URL for downloading the artifact's file. |
+| <a id="cijobartifactexpireat"></a>`expireAt` | [`Time`](#time) | Expiry date of the artifact. |
 | <a id="cijobartifactfiletype"></a>`fileType` | [`JobArtifactFileType`](#jobartifactfiletype) | File type of the artifact. |
+| <a id="cijobartifactid"></a>`id` | [`CiJobArtifactID!`](#cijobartifactid) | ID of the artifact. |
 | <a id="cijobartifactname"></a>`name` | [`String`](#string) | File name of the artifact. |
+| <a id="cijobartifactsize"></a>`size` | [`Int!`](#int) | Size of the artifact in bytes. |
 
 ### `CiJobTokenScopeType`
 
diff --git a/ee/app/assets/javascripts/security_dashboard/graphql/queries/pipeline_security_report_summary.query.graphql b/ee/app/assets/javascripts/security_dashboard/graphql/queries/pipeline_security_report_summary.query.graphql
index 3a03c1efeef3e..bd0cf43dfa1c7 100644
--- a/ee/app/assets/javascripts/security_dashboard/graphql/queries/pipeline_security_report_summary.query.graphql
+++ b/ee/app/assets/javascripts/security_dashboard/graphql/queries/pipeline_security_report_summary.query.graphql
@@ -10,6 +10,7 @@ query pipelineSecuritySummary(
     id
     pipeline(iid: $pipelineIid) {
       id
+      # eslint-disable-next-line @graphql-eslint/require-id-when-available
       ...JobArtifacts
       securityReportSummary {
         dast {
diff --git a/spec/graphql/types/ci/job_artifact_type_spec.rb b/spec/graphql/types/ci/job_artifact_type_spec.rb
index 58b5f9cfcb7d1..3e054faf0c9b2 100644
--- a/spec/graphql/types/ci/job_artifact_type_spec.rb
+++ b/spec/graphql/types/ci/job_artifact_type_spec.rb
@@ -4,7 +4,7 @@
 
 RSpec.describe GitlabSchema.types['CiJobArtifact'] do
   it 'has the correct fields' do
-    expected_fields = [:download_path, :file_type, :name]
+    expected_fields = [:id, :download_path, :file_type, :name, :size, :expire_at]
 
     expect(described_class).to have_graphql_fields(*expected_fields)
   end
-- 
GitLab