Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d78f7cea
Commit
d78f7cea
authored
Jun 28, 2019
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added commit type to tree GraphQL type
parent
80735a2d
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
139 additions
and
3 deletions
+139
-3
app/graphql/types/commit_type.rb
app/graphql/types/commit_type.rb
+30
-0
app/graphql/types/tree/tree_type.rb
app/graphql/types/tree/tree_type.rb
+5
-0
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+5
-0
app/presenters/commit_presenter.rb
app/presenters/commit_presenter.rb
+7
-1
changelogs/unreleased/graphql-tree-last-commit.yml
changelogs/unreleased/graphql-tree-last-commit.yml
+5
-0
lib/gitlab/graphql/loaders/pipeline_for_sha_loader.rb
lib/gitlab/graphql/loaders/pipeline_for_sha_loader.rb
+25
-0
spec/graphql/gitlab_schema_spec.rb
spec/graphql/gitlab_schema_spec.rb
+1
-1
spec/graphql/types/commit_type_spec.rb
spec/graphql/types/commit_type_spec.rb
+11
-0
spec/graphql/types/tree/tree_type_spec.rb
spec/graphql/types/tree/tree_type_spec.rb
+1
-1
spec/lib/gitlab/graphql/loaders/pipeline_for_sha_loader_spec.rb
...ib/gitlab/graphql/loaders/pipeline_for_sha_loader_spec.rb
+20
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+11
-0
spec/requests/api/graphql/project/tree/tree_spec.rb
spec/requests/api/graphql/project/tree/tree_spec.rb
+18
-0
No files found.
app/graphql/types/commit_type.rb
0 → 100644
View file @
d78f7cea
# frozen_string_literal: true
module
Types
class
CommitType
<
BaseObject
graphql_name
'Commit'
authorize
:download_code
present_using
CommitPresenter
field
:id
,
type:
GraphQL
::
ID_TYPE
,
null:
false
field
:sha
,
type:
GraphQL
::
STRING_TYPE
,
null:
false
field
:title
,
type:
GraphQL
::
STRING_TYPE
,
null:
true
field
:description
,
type:
GraphQL
::
STRING_TYPE
,
null:
true
field
:message
,
type:
GraphQL
::
STRING_TYPE
,
null:
true
field
:authored_date
,
type:
Types
::
TimeType
,
null:
true
field
:web_url
,
type:
GraphQL
::
STRING_TYPE
,
null:
false
# models/commit lazy loads the author by email
field
:author
,
type:
Types
::
UserType
,
null:
true
field
:latest_pipeline
,
type:
Types
::
Ci
::
PipelineType
,
null:
true
,
description:
"Latest pipeline for this commit"
,
resolve:
->
(
obj
,
ctx
,
args
)
do
Gitlab
::
Graphql
::
Loaders
::
PipelineForShaLoader
.
new
(
obj
.
project
,
obj
.
sha
).
find_last
end
end
end
app/graphql/types/tree/tree_type.rb
View file @
d78f7cea
...
...
@@ -4,6 +4,11 @@ module Types
class
TreeType
<
BaseObject
graphql_name
'Tree'
# Complexity 10 as it triggers a Gitaly call on each render
field
:last_commit
,
Types
::
CommitType
,
null:
true
,
complexity:
10
,
resolve:
->
(
tree
,
args
,
ctx
)
do
tree
.
repository
.
last_commit_for_path
(
tree
.
sha
,
tree
.
path
)
end
field
:trees
,
Types
::
Tree
::
TreeEntryType
.
connection_type
,
null:
false
,
resolve:
->
(
obj
,
args
,
ctx
)
do
Gitlab
::
Graphql
::
Representation
::
TreeEntry
.
decorate
(
obj
.
trees
,
obj
.
repository
)
end
...
...
app/models/ci/pipeline.rb
View file @
d78f7cea
...
...
@@ -295,6 +295,11 @@ module Ci
end
end
def
self
.
latest_for_shas
(
shas
)
max_id_per_sha
=
for_sha
(
shas
).
group
(
:sha
).
select
(
"max(id)"
)
where
(
id:
max_id_per_sha
)
end
def
self
.
latest_successful_ids_per_project
success
.
group
(
:project_id
).
select
(
'max(id) as id'
)
end
...
...
app/presenters/commit_presenter.rb
View file @
d78f7cea
# frozen_string_literal: true
class
CommitPresenter
<
Gitlab
::
View
::
Presenter
::
Simple
class
CommitPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
include
GlobalID
::
Identification
presents
:commit
def
status_for
(
ref
)
...
...
@@ -10,4 +12,8 @@ class CommitPresenter < Gitlab::View::Presenter::Simple
def
any_pipelines?
can?
(
current_user
,
:read_pipeline
,
commit
.
project
)
&&
commit
.
pipelines
.
any?
end
def
web_url
Gitlab
::
UrlBuilder
.
new
(
commit
).
url
end
end
changelogs/unreleased/graphql-tree-last-commit.yml
0 → 100644
View file @
d78f7cea
---
title
:
Added commit type to tree GraphQL response
merge_request
:
29412
author
:
type
:
added
lib/gitlab/graphql/loaders/pipeline_for_sha_loader.rb
0 → 100644
View file @
d78f7cea
# frozen_string_literal: true
module
Gitlab
module
Graphql
module
Loaders
class
PipelineForShaLoader
attr_accessor
:project
,
:sha
def
initialize
(
project
,
sha
)
@project
,
@sha
=
project
,
sha
end
def
find_last
BatchLoader
.
for
(
sha
).
batch
(
key:
project
)
do
|
shas
,
loader
,
args
|
pipelines
=
args
[
:key
].
ci_pipelines
.
latest_for_shas
(
shas
)
pipelines
.
each
do
|
pipeline
|
loader
.
call
(
pipeline
.
sha
,
pipeline
)
end
end
end
end
end
end
end
spec/graphql/gitlab_schema_spec.rb
View file @
d78f7cea
...
...
@@ -113,7 +113,7 @@ describe GitlabSchema do
end
it
"raises a meaningful error if a global id couldn't be generated"
do
expect
{
described_class
.
id_from_object
(
build
(
:
commit
))
}
expect
{
described_class
.
id_from_object
(
build
(
:
wiki_directory
))
}
.
to
raise_error
(
RuntimeError
,
/include `GlobalID::Identification` into/i
)
end
end
...
...
spec/graphql/types/commit_type_spec.rb
0 → 100644
View file @
d78f7cea
# frozen_string_literal: true
require
'spec_helper'
describe
GitlabSchema
.
types
[
'Commit'
]
do
it
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'Commit'
)
}
it
{
expect
(
described_class
).
to
require_graphql_authorizations
(
:download_code
)
}
it
{
expect
(
described_class
).
to
have_graphql_fields
(
:id
,
:sha
,
:title
,
:description
,
:message
,
:authored_date
,
:author
,
:web_url
,
:latest_pipeline
)
}
end
spec/graphql/types/tree/tree_type_spec.rb
View file @
d78f7cea
...
...
@@ -5,5 +5,5 @@ require 'spec_helper'
describe
Types
::
Tree
::
TreeType
do
it
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'Tree'
)
}
it
{
expect
(
described_class
).
to
have_graphql_fields
(
:trees
,
:submodules
,
:blobs
)
}
it
{
expect
(
described_class
).
to
have_graphql_fields
(
:trees
,
:submodules
,
:blobs
,
:last_commit
)
}
end
spec/lib/gitlab/graphql/loaders/pipeline_for_sha_loader_spec.rb
0 → 100644
View file @
d78f7cea
require
'spec_helper'
describe
Gitlab
::
Graphql
::
Loaders
::
PipelineForShaLoader
do
include
GraphqlHelpers
describe
'#find_last'
do
it
'batch-resolves latest pipeline'
do
project
=
create
(
:project
,
:repository
)
pipeline1
=
create
(
:ci_pipeline
,
project:
project
,
ref:
project
.
default_branch
,
sha:
project
.
commit
.
sha
)
pipeline2
=
create
(
:ci_pipeline
,
project:
project
,
ref:
project
.
default_branch
,
sha:
project
.
commit
.
sha
)
pipeline3
=
create
(
:ci_pipeline
,
project:
project
,
ref:
'improve/awesome'
,
sha:
project
.
commit
(
'improve/awesome'
).
sha
)
result
=
batch
(
max_queries:
1
)
do
[
pipeline1
.
sha
,
pipeline3
.
sha
].
map
{
|
sha
|
described_class
.
new
(
project
,
sha
).
find_last
}
end
expect
(
result
).
to
contain_exactly
(
pipeline2
,
pipeline3
)
end
end
end
spec/models/ci/pipeline_spec.rb
View file @
d78f7cea
...
...
@@ -1886,6 +1886,17 @@ describe Ci::Pipeline, :mailer do
end
end
describe
'.latest_for_shas'
do
let
(
:sha
)
{
'abc'
}
it
'returns latest pipeline for sha'
do
create
(
:ci_pipeline
,
sha:
sha
)
pipeline2
=
create
(
:ci_pipeline
,
sha:
sha
)
expect
(
described_class
.
latest_for_shas
(
sha
)).
to
contain_exactly
(
pipeline2
)
end
end
describe
'.latest_successful_ids_per_project'
do
let
(
:projects
)
{
create_list
(
:project
,
2
)
}
let!
(
:pipeline1
)
{
create
(
:ci_pipeline
,
:success
,
project:
projects
[
0
])
}
...
...
spec/requests/api/graphql/project/tree/tree_spec.rb
View file @
d78f7cea
...
...
@@ -33,6 +33,12 @@ describe 'getting a tree in a project' do
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'submodules'
][
'edges'
]).
to
eq
([])
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'blobs'
][
'edges'
]).
to
eq
([])
end
it
'returns null commit'
do
post_graphql
(
query
,
current_user:
current_user
)
expect
(
graphql_data
[
'project'
][
'repository'
][
'last_commit'
]).
to
be_nil
end
end
context
'when ref does not exist'
do
...
...
@@ -45,6 +51,12 @@ describe 'getting a tree in a project' do
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'submodules'
][
'edges'
]).
to
eq
([])
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'blobs'
][
'edges'
]).
to
eq
([])
end
it
'returns null commit'
do
post_graphql
(
query
,
current_user:
current_user
)
expect
(
graphql_data
[
'project'
][
'repository'
][
'last_commit'
]).
to
be_nil
end
end
context
'when ref and path exist'
do
...
...
@@ -61,6 +73,12 @@ describe 'getting a tree in a project' do
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'blobs'
][
'edges'
].
size
).
to
be
>
0
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'submodules'
][
'edges'
].
size
).
to
be
>
0
end
it
'returns tree latest commit'
do
post_graphql
(
query
,
current_user:
current_user
)
expect
(
graphql_data
[
'project'
][
'repository'
][
'tree'
][
'lastCommit'
]).
to
be_present
end
end
context
'when current user is nil'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment