1# frozen_string_literal: true 2 3module Types 4 module Ci 5 class PipelineType < BaseObject 6 graphql_name 'Pipeline' 7 8 connection_type_class(Types::CountableConnectionType) 9 10 authorize :read_pipeline 11 present_using ::Ci::PipelinePresenter 12 13 expose_permissions Types::PermissionTypes::Ci::Pipeline 14 15 field :id, GraphQL::Types::ID, null: false, 16 description: 'ID of the pipeline.' 17 18 field :iid, GraphQL::Types::String, null: false, 19 description: 'Internal ID of the pipeline.' 20 21 field :sha, GraphQL::Types::String, null: false, 22 description: "SHA of the pipeline's commit." 23 24 field :before_sha, GraphQL::Types::String, null: true, 25 description: 'Base SHA of the source branch.' 26 27 field :complete, GraphQL::Types::Boolean, null: false, method: :complete?, 28 description: 'Indicates if a pipeline is complete.' 29 30 field :status, PipelineStatusEnum, null: false, 31 description: "Status of the pipeline (#{::Ci::Pipeline.all_state_names.compact.join(', ').upcase})" 32 33 field :warnings, GraphQL::Types::Boolean, null: false, method: :has_warnings?, 34 description: "Indicates if a pipeline has warnings." 35 36 field :detailed_status, Types::Ci::DetailedStatusType, null: false, 37 description: 'Detailed status of the pipeline.' 38 39 field :config_source, PipelineConfigSourceEnum, null: true, 40 description: "Configuration source of the pipeline (#{::Enums::Ci::Pipeline.config_sources.keys.join(', ').upcase})" 41 42 field :duration, GraphQL::Types::Int, null: true, 43 description: 'Duration of the pipeline in seconds.' 44 45 field :queued_duration, Types::DurationType, null: true, 46 description: 'How long the pipeline was queued before starting.' 47 48 field :coverage, GraphQL::Types::Float, null: true, 49 description: 'Coverage percentage.' 50 51 field :created_at, Types::TimeType, null: false, 52 description: "Timestamp of the pipeline's creation." 53 54 field :updated_at, Types::TimeType, null: false, 55 description: "Timestamp of the pipeline's last activity." 56 57 field :started_at, Types::TimeType, null: true, 58 description: 'Timestamp when the pipeline was started.' 59 60 field :finished_at, Types::TimeType, null: true, 61 description: "Timestamp of the pipeline's completion." 62 63 field :committed_at, Types::TimeType, null: true, 64 description: "Timestamp of the pipeline's commit." 65 66 field :stages, 67 type: Types::Ci::StageType.connection_type, 68 null: true, 69 authorize: :read_build, 70 description: 'Stages of the pipeline.', 71 extras: [:lookahead], 72 resolver: Resolvers::Ci::PipelineStagesResolver 73 74 field :user, 75 type: Types::UserType, 76 null: true, 77 description: 'Pipeline user.' 78 79 field :retryable, GraphQL::Types::Boolean, 80 description: 'Specifies if a pipeline can be retried.', 81 method: :retryable?, 82 null: false 83 84 field :cancelable, GraphQL::Types::Boolean, 85 description: 'Specifies if a pipeline can be canceled.', 86 method: :cancelable?, 87 null: false 88 89 field :jobs, 90 ::Types::Ci::JobType.connection_type, 91 null: true, 92 authorize: :read_build, 93 description: 'Jobs belonging to the pipeline.', 94 resolver: ::Resolvers::Ci::JobsResolver 95 96 field :job, 97 type: ::Types::Ci::JobType, 98 null: true, 99 authorize: :read_build, 100 description: 'Specific job in this pipeline, either by name or ID.' do 101 argument :id, 102 type: ::Types::GlobalIDType[::CommitStatus], 103 required: false, 104 description: 'ID of the job.' 105 argument :name, 106 type: ::GraphQL::Types::String, 107 required: false, 108 description: 'Name of the job.' 109 end 110 111 field :job_artifacts, 112 null: true, 113 description: 'Job artifacts of the pipeline.', 114 resolver: ::Resolvers::Ci::PipelineJobArtifactsResolver 115 116 field :source_job, 117 type: Types::Ci::JobType, 118 null: true, 119 authorize: :read_build, 120 description: 'Job where pipeline was triggered from.' 121 122 field :downstream, Types::Ci::PipelineType.connection_type, null: true, 123 description: 'Pipelines this pipeline will trigger.', 124 method: :triggered_pipelines_with_preloads 125 126 field :upstream, Types::Ci::PipelineType, null: true, 127 description: 'Pipeline that triggered the pipeline.', 128 method: :triggered_by_pipeline 129 130 field :path, GraphQL::Types::String, null: true, 131 description: "Relative path to the pipeline's page." 132 133 field :commit, Types::CommitType, null: true, 134 description: "Git commit of the pipeline.", 135 calls_gitaly: true 136 137 field :commit_path, GraphQL::Types::String, null: true, 138 description: 'Path to the commit that triggered the pipeline.' 139 140 field :project, Types::ProjectType, null: true, 141 description: 'Project the pipeline belongs to.' 142 143 field :active, GraphQL::Types::Boolean, null: false, method: :active?, 144 description: 'Indicates if the pipeline is active.' 145 146 field :uses_needs, GraphQL::Types::Boolean, null: true, 147 method: :uses_needs?, 148 description: 'Indicates if the pipeline has jobs with `needs` dependencies.' 149 150 field :test_report_summary, 151 Types::Ci::TestReportSummaryType, 152 null: false, 153 description: 'Summary of the test report generated by the pipeline.', 154 resolver: Resolvers::Ci::TestReportSummaryResolver 155 156 field :test_suite, 157 Types::Ci::TestSuiteType, 158 null: true, 159 description: 'A specific test suite in a pipeline test report.', 160 resolver: Resolvers::Ci::TestSuiteResolver 161 162 field :ref, GraphQL::Types::String, null: true, 163 description: 'Reference to the branch from which the pipeline was triggered.' 164 165 def detailed_status 166 object.detailed_status(current_user) 167 end 168 169 def user 170 Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.user_id).find 171 end 172 173 def commit_path 174 ::Gitlab::Routing.url_helpers.project_commit_path(object.project, object.sha) 175 end 176 177 def path 178 ::Gitlab::Routing.url_helpers.project_pipeline_path(object.project, object) 179 end 180 181 def job(id: nil, name: nil) 182 raise ::Gitlab::Graphql::Errors::ArgumentError, 'One of id or name is required' unless id || name 183 184 if id 185 id = ::Types::GlobalIDType[::CommitStatus].coerce_isolated_input(id) if id 186 pipeline.statuses.id_in(id.model_id) 187 else 188 pipeline.statuses.by_name(name) 189 end.take # rubocop: disable CodeReuse/ActiveRecord 190 end 191 192 alias_method :pipeline, :object 193 end 194 end 195end 196 197Types::Ci::PipelineType.prepend_mod_with('Types::Ci::PipelineType') 198