Commit 7b0c9020 authored by Markus Koller's avatar Markus Koller

Merge branch 'mc/backstage/graphql-list-available-branches' into 'master'

Add branch names field to repository type

See merge request gitlab-org/gitlab!55074
parents 9f843a82 f02101b8
# frozen_string_literal: true
module Resolvers
class RepositoryBranchNamesResolver < BaseResolver
type ::GraphQL::STRING_TYPE, null: false
calls_gitaly!
argument :search_pattern, GraphQL::STRING_TYPE,
required: true,
description: 'The pattern to search for branch names by.'
def resolve(search_pattern:)
Repositories::BranchNamesFinder.new(object, search: search_pattern).execute
end
end
end
...@@ -16,5 +16,8 @@ module Types ...@@ -16,5 +16,8 @@ module Types
description: 'Tree of the repository.' description: 'Tree of the repository.'
field :blobs, Types::Tree::BlobType.connection_type, null: true, resolver: Resolvers::BlobsResolver, calls_gitaly: true, field :blobs, Types::Tree::BlobType.connection_type, null: true, resolver: Resolvers::BlobsResolver, calls_gitaly: true,
description: 'Blobs contained within the repository' description: 'Blobs contained within the repository'
field :branch_names, [GraphQL::STRING_TYPE], null: true, calls_gitaly: true,
complexity: 170, description: 'Names of branches available in this repository that match the search pattern.',
resolver: Resolvers::RepositoryBranchNamesResolver
end end
end end
---
title: Add branch names field to repository GraphQL type.
merge_request: 55074
author:
type: changed
...@@ -5444,6 +5444,7 @@ Autogenerated return type of RepositionImageDiffNote. ...@@ -5444,6 +5444,7 @@ Autogenerated return type of RepositionImageDiffNote.
| Field | Type | Description | | Field | Type | Description |
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `blobs` | [`BlobConnection`](#blobconnection) | Blobs contained within the repository. | | `blobs` | [`BlobConnection`](#blobconnection) | Blobs contained within the repository. |
| `branchNames` | [`[String!]`](#string) | Names of branches available in this repository that match the search pattern. |
| `empty` | [`Boolean!`](#boolean) | Indicates repository has no visible content. | | `empty` | [`Boolean!`](#boolean) | Indicates repository has no visible content. |
| `exists` | [`Boolean!`](#boolean) | Indicates a corresponding Git repository exists on disk. | | `exists` | [`Boolean!`](#boolean) | Indicates a corresponding Git repository exists on disk. |
| `rootRef` | [`String`](#string) | Default branch of the repository. | | `rootRef` | [`String`](#string) | Default branch of the repository. |
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::RepositoryBranchNamesResolver do
include GraphqlHelpers
let(:project) { create(:project, :repository) }
describe '#resolve' do
subject(:resolve_branch_names) do
resolve(
described_class,
obj: project.repository,
args: { search_pattern: pattern },
ctx: { current_user: project.creator }
)
end
context 'with empty search pattern' do
let(:pattern) { '' }
it 'returns nil' do
expect(resolve_branch_names).to eq(nil)
end
end
context 'with a valid search pattern' do
let(:pattern) { 'mas*' }
it 'returns matching branches' do
expect(resolve_branch_names).to match_array(['master'])
end
end
end
end
...@@ -14,4 +14,6 @@ RSpec.describe GitlabSchema.types['Repository'] do ...@@ -14,4 +14,6 @@ RSpec.describe GitlabSchema.types['Repository'] do
specify { expect(described_class).to have_graphql_field(:exists, calls_gitaly?: true, complexity: 2) } specify { expect(described_class).to have_graphql_field(:exists, calls_gitaly?: true, complexity: 2) }
specify { expect(described_class).to have_graphql_field(:blobs) } specify { expect(described_class).to have_graphql_field(:blobs) }
specify { expect(described_class).to have_graphql_field(:branch_names, calls_gitaly?: true, complexity: 170) }
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