Commit 49bda3f9 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'add-lfs-blob-ids-to-tree-type' into 'master'

Add LFS blob IDs to GraphQL tree type

See merge request gitlab-org/gitlab-ce!28666
parents 9749a25f 522c0197
...@@ -135,6 +135,7 @@ export default { ...@@ -135,6 +135,7 @@ export default {
:path="entry.flatPath" :path="entry.flatPath"
:type="entry.type" :type="entry.type"
:url="entry.webUrl" :url="entry.webUrl"
:lfs-oid="entry.lfsOid"
/> />
</template> </template>
</tbody> </tbody>
......
<script> <script>
import { GlBadge } from '@gitlab/ui';
import { getIconName } from '../../utils/icon'; import { getIconName } from '../../utils/icon';
import getRefMixin from '../../mixins/get_ref'; import getRefMixin from '../../mixins/get_ref';
export default { export default {
components: {
GlBadge,
},
mixins: [getRefMixin], mixins: [getRefMixin],
props: { props: {
id: { id: {
...@@ -26,6 +30,11 @@ export default { ...@@ -26,6 +30,11 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
lfsOid: {
type: String,
required: false,
default: null,
},
}, },
computed: { computed: {
routerLinkTo() { routerLinkTo() {
...@@ -67,6 +76,9 @@ export default { ...@@ -67,6 +76,9 @@ export default {
<component :is="linkComponent" :to="routerLinkTo" :href="url" class="str-truncated"> <component :is="linkComponent" :to="routerLinkTo" :href="url" class="str-truncated">
{{ fullPath }} {{ fullPath }}
</component> </component>
<gl-badge v-if="lfsOid" variant="default" class="label-lfs ml-1">
LFS
</gl-badge>
<template v-if="isSubmodule"> <template v-if="isSubmodule">
@ <a href="#" class="commit-sha">{{ shortSha }}</a> @ <a href="#" class="commit-sha">{{ shortSha }}</a>
</template> </template>
......
...@@ -45,6 +45,7 @@ query getFiles( ...@@ -45,6 +45,7 @@ query getFiles(
node { node {
...TreeEntry ...TreeEntry
webUrl webUrl
lfsOid
} }
} }
pageInfo { pageInfo {
......
...@@ -9,6 +9,9 @@ module Types ...@@ -9,6 +9,9 @@ module Types
graphql_name 'Blob' graphql_name 'Blob'
field :web_url, GraphQL::STRING_TYPE, null: true field :web_url, GraphQL::STRING_TYPE, null: true
field :lfs_oid, GraphQL::STRING_TYPE, null: true, resolve: -> (blob, args, ctx) do
Gitlab::Graphql::Loaders::BatchCommitLoader.new(blob.repository, blob.id).find
end
end end
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class BlobPresenter < Gitlab::View::Presenter::Simple class BlobPresenter < Gitlab::View::Presenter::Delegated
presents :blob presents :blob
def highlight(plain: nil) def highlight(plain: nil)
......
---
title: Add LFS oid to GraphQL blob type
merge_request: 28666
author:
type: added
# frozen_string_literal: true
module Gitlab
module Graphql
module Loaders
class BatchCommitLoader
def initialize(repository, blob_id)
@repository, @blob_id = repository, blob_id
end
def find
BatchLoader.for(blob_id).batch(key: repository) do |blob_ids, loader, batch_args|
Gitlab::Git::Blob.batch_lfs_pointers(batch_args[:key], blob_ids).each do |loaded_blob|
loader.call(loaded_blob.id, loaded_blob.lfs_oid)
end
end
end
private
attr_reader :repository, :blob_id
end
end
end
end
...@@ -22,6 +22,8 @@ exports[`Repository table row component renders table row 1`] = ` ...@@ -22,6 +22,8 @@ exports[`Repository table row component renders table row 1`] = `
</a> </a>
<!----> <!---->
<!---->
</td> </td>
<td <td
......
import { shallowMount, RouterLinkStub } from '@vue/test-utils'; import { shallowMount, RouterLinkStub } from '@vue/test-utils';
import { GlBadge } from '@gitlab/ui';
import TableRow from '~/repository/components/table/row.vue'; import TableRow from '~/repository/components/table/row.vue';
let vm; let vm;
...@@ -98,4 +99,16 @@ describe('Repository table row component', () => { ...@@ -98,4 +99,16 @@ describe('Repository table row component', () => {
expect(vm.find('a').attributes('href')).toEqual('https://test.com'); expect(vm.find('a').attributes('href')).toEqual('https://test.com');
}); });
it('renders LFS badge', () => {
factory({
id: '1',
path: 'test',
type: 'commit',
currentPath: '/',
lfsOid: '1',
});
expect(vm.find(GlBadge).exists()).toBe(true);
});
}); });
...@@ -5,5 +5,5 @@ require 'spec_helper' ...@@ -5,5 +5,5 @@ require 'spec_helper'
describe Types::Tree::BlobType do describe Types::Tree::BlobType do
it { expect(described_class.graphql_name).to eq('Blob') } it { expect(described_class.graphql_name).to eq('Blob') }
it { expect(described_class).to have_graphql_fields(:id, :name, :type, :path, :flat_path, :web_url) } it { expect(described_class).to have_graphql_fields(:id, :name, :type, :path, :flat_path, :web_url, :lfs_oid) }
end end
require 'spec_helper'
describe Gitlab::Graphql::Loaders::BatchCommitLoader do
include GraphqlHelpers
set(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:blob) { Gitlab::Graphql::Representation::TreeEntry.new(repository.blob_at('master', 'files/lfs/lfs_object.iso'), repository) }
let(:otherblob) { Gitlab::Graphql::Representation::TreeEntry.new(repository.blob_at('master', 'README'), repository) }
describe '#find' do
it 'batch-resolves LFS blob IDs' do
expect(Gitlab::Git::Blob).to receive(:batch_lfs_pointers).once.and_call_original
result = batch do
[blob, otherblob].map { |b| described_class.new(repository, b.id).find }
end
expect(result.first).to eq(blob.lfs_oid)
expect(result.last).to eq(nil)
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