Commit 9bbe4076 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ph/repoBrowserWebPathDescriptionFields' into 'master'

Added webPath fields to repository entries

See merge request gitlab-org/gitlab!37416
parents 43288d8f 711db9cf
......@@ -17,12 +17,15 @@ module Types
markdown_field :title_html, null: true
field :description, type: GraphQL::STRING_TYPE, null: true,
description: 'Description of the commit message'
markdown_field :description_html, null: true
field :message, type: GraphQL::STRING_TYPE, null: true,
description: 'Raw commit message'
field :authored_date, type: Types::TimeType, null: true,
description: 'Timestamp of when the commit was authored'
field :web_url, type: GraphQL::STRING_TYPE, null: false,
description: 'Web URL of the commit'
field :web_path, type: GraphQL::STRING_TYPE, null: false,
description: 'Web path of the commit'
field :signature_html, type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true,
description: 'Rendered HTML of the commit signature'
field :author_name, type: GraphQL::STRING_TYPE, null: true,
......
......@@ -12,6 +12,8 @@ module Types
field :web_url, GraphQL::STRING_TYPE, null: true,
description: 'Web URL of the blob'
field :web_path, GraphQL::STRING_TYPE, null: true,
description: 'Web path of the blob'
field :lfs_oid, GraphQL::STRING_TYPE, null: true,
description: 'LFS ID of the blob',
resolve: -> (blob, args, ctx) do
......
......@@ -13,6 +13,8 @@ module Types
field :web_url, GraphQL::STRING_TYPE, null: true,
description: 'Web URL for the tree entry (directory)'
field :web_path, GraphQL::STRING_TYPE, null: true,
description: 'Web path for the tree entry (directory)'
end
# rubocop: enable Graphql/AuthorizeTypes
end
......
......@@ -22,6 +22,8 @@ module Types
description: "URL of the user's avatar"
field :web_url, GraphQL::STRING_TYPE, null: false,
description: 'Web URL of the user'
field :web_path, GraphQL::STRING_TYPE, null: false,
description: 'Web path of the user'
field :todos, Types::TodoType.connection_type, null: false,
resolver: Resolvers::TodoResolver,
description: 'Todos of the user'
......
......@@ -18,6 +18,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
Gitlab::Routing.url_helpers.project_blob_url(blob.repository.project, File.join(blob.commit_id, blob.path))
end
def web_path
Gitlab::Routing.url_helpers.project_blob_path(blob.repository.project, File.join(blob.commit_id, blob.path))
end
private
def load_all_blob_data
......
......@@ -21,6 +21,10 @@ class CommitPresenter < Gitlab::View::Presenter::Delegated
url_builder.build(commit)
end
def web_path
url_builder.build(commit, only_path: true)
end
def signature_html
return unless commit.has_signature?
......
......@@ -6,4 +6,8 @@ class TreeEntryPresenter < Gitlab::View::Presenter::Delegated
def web_url
Gitlab::Routing.url_helpers.project_tree_url(tree.repository.project, File.join(tree.commit_id, tree.path))
end
def web_path
Gitlab::Routing.url_helpers.project_tree_path(tree.repository.project, File.join(tree.commit_id, tree.path))
end
end
......@@ -6,4 +6,8 @@ class UserPresenter < Gitlab::View::Presenter::Delegated
def web_url
Gitlab::Routing.url_helpers.user_url(user)
end
def web_path
Gitlab::Routing.url_helpers.user_path(user)
end
end
---
title: Added webPath and descriptionHtml types to the repository GraphQL entities
merge_request: 37416
author:
type: added
......@@ -873,6 +873,11 @@ type Blob implements Entry {
"""
type: EntryType!
"""
Web path of the blob
"""
webPath: String
"""
Web URL of the blob
"""
......@@ -1186,6 +1191,11 @@ type Commit {
"""
description: String
"""
The GitLab Flavored Markdown rendering of `description`
"""
descriptionHtml: String
"""
ID (global ID) of the commit
"""
......@@ -1276,6 +1286,11 @@ type Commit {
"""
titleHtml: String
"""
Web path of the commit
"""
webPath: String!
"""
Web URL of the commit
"""
......@@ -13689,6 +13704,11 @@ type TreeEntry implements Entry {
"""
type: EntryType!
"""
Web path for the tree entry (directory)
"""
webPath: String
"""
Web URL for the tree entry (directory)
"""
......@@ -14595,6 +14615,11 @@ type User {
"""
username: String!
"""
Web path of the user
"""
webPath: String!
"""
Web URL of the user
"""
......
......@@ -2300,6 +2300,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webPath",
"description": "Web path of the blob",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webUrl",
"description": "Web URL of the blob",
......@@ -3244,6 +3258,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "descriptionHtml",
"description": "The GitLab Flavored Markdown rendering of `description`",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": "ID (global ID) of the commit",
......@@ -3462,6 +3490,24 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webPath",
"description": "Web path of the commit",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webUrl",
"description": "Web URL of the commit",
......@@ -40523,6 +40569,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webPath",
"description": "Web path for the tree entry (directory)",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webUrl",
"description": "Web URL for the tree entry (directory)",
......@@ -42954,6 +43014,24 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webPath",
"description": "Web path of the user",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webUrl",
"description": "Web URL of the user",
......@@ -178,6 +178,7 @@ Autogenerated return type of AwardEmojiToggle
| `path` | String! | Path of the entry |
| `sha` | String! | Last commit sha for the entry |
| `type` | EntryType! | Type of tree entry |
| `webPath` | String | Web path of the blob |
| `webUrl` | String | Web URL of the blob |
## Board
......@@ -234,6 +235,7 @@ Autogenerated return type of BoardListUpdateLimitMetrics
| `authorName` | String | Commit authors name |
| `authoredDate` | Time | Timestamp of when the commit was authored |
| `description` | String | Description of the commit message |
| `descriptionHtml` | String | The GitLab Flavored Markdown rendering of `description` |
| `id` | ID! | ID (global ID) of the commit |
| `latestPipeline` **{warning-solid}** | Pipeline | **Deprecated:** Use `pipelines`. Deprecated in 12.5 |
| `message` | String | Raw commit message |
......@@ -241,6 +243,7 @@ Autogenerated return type of BoardListUpdateLimitMetrics
| `signatureHtml` | String | Rendered HTML of the commit signature |
| `title` | String | Title of the commit message |
| `titleHtml` | String | The GitLab Flavored Markdown rendering of `title` |
| `webPath` | String! | Web path of the commit |
| `webUrl` | String! | Web URL of the commit |
## CommitCreatePayload
......@@ -2076,6 +2079,7 @@ Represents a directory
| `path` | String! | Path of the entry |
| `sha` | String! | Last commit sha for the entry |
| `type` | EntryType! | Type of tree entry |
| `webPath` | String | Web path for the tree entry (directory) |
| `webUrl` | String | Web URL for the tree entry (directory) |
## UpdateAlertStatusPayload
......@@ -2180,6 +2184,7 @@ Autogenerated return type of UpdateSnippet
| `state` | UserState! | State of the user |
| `userPermissions` | UserPermissions! | Permissions for the current user on the resource |
| `username` | String! | Username of the user. Unique within this instance of GitLab |
| `webPath` | String! | Web path of the user |
| `webUrl` | String! | Web URL of the user |
## UserPermissions
......
......@@ -9,8 +9,8 @@ RSpec.describe GitlabSchema.types['Commit'] do
it 'contains attributes related to commit' do
expect(described_class).to have_graphql_fields(
:id, :sha, :title, :description, :message, :title_html, :authored_date,
:author_name, :author_gravatar, :author, :web_url, :latest_pipeline,
:id, :sha, :title, :description, :description_html, :message, :title_html, :authored_date,
:author_name, :author_gravatar, :author, :web_url, :web_path, :latest_pipeline,
:pipelines, :signature_html
)
end
......
......@@ -5,5 +5,5 @@ require 'spec_helper'
RSpec.describe Types::Tree::BlobType do
specify { expect(described_class.graphql_name).to eq('Blob') }
specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url, :lfs_oid, :mode) }
specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url, :web_path, :lfs_oid, :mode) }
end
......@@ -5,5 +5,5 @@ require 'spec_helper'
RSpec.describe Types::Tree::TreeEntryType do
specify { expect(described_class.graphql_name).to eq('TreeEntry') }
specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url) }
specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url, :web_path) }
end
......@@ -16,6 +16,7 @@ RSpec.describe GitlabSchema.types['User'] do
username
avatarUrl
webUrl
webPath
todos
state
authoredMergeRequests
......
......@@ -24,6 +24,16 @@ RSpec.describe BlobPresenter, :seed_helper do
it { expect(subject.web_url).to eq("http://localhost/#{project.full_path}/-/blob/#{blob.commit_id}/#{blob.path}") }
end
describe '#web_path' do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:blob) { Gitlab::Graphql::Representation::TreeEntry.new(repository.tree.blobs.first, repository) }
subject { described_class.new(blob) }
it { expect(subject.web_path).to eq("/#{project.full_path}/-/blob/#{blob.commit_id}/#{blob.path}") }
end
describe '#highlight' do
subject { described_class.new(blob) }
......
......@@ -8,6 +8,10 @@ RSpec.describe CommitPresenter do
let(:user) { create(:user) }
let(:presenter) { described_class.new(commit, current_user: user) }
describe '#web_path' do
it { expect(presenter.web_path).to eq("/#{project.full_path}/-/commit/#{commit.sha}") }
end
describe '#status_for' do
subject { presenter.status_for('ref') }
......
......@@ -13,4 +13,8 @@ RSpec.describe TreeEntryPresenter do
describe '.web_url' do
it { expect(presenter.web_url).to eq("http://localhost/#{project.full_path}/-/tree/#{tree.commit_id}/#{tree.path}") }
end
describe '#web_path' do
it { expect(presenter.web_path).to eq("/#{project.full_path}/-/tree/#{tree.commit_id}/#{tree.path}") }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe UserPresenter do
let_it_be(:user) { create(:user) }
subject(:presenter) { described_class.new(user) }
describe '#web_path' do
it { expect(presenter.web_path).to eq("/#{user.username}") }
end
describe '#web_url' do
it { expect(presenter.web_url).to eq("http://localhost/#{user.username}") }
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