Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d78f7cea
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d78f7cea
编写于
6月 28, 2019
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added commit type to tree GraphQL type
上级
80735a2d
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
139 addition
and
3 deletion
+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
未找到文件。
app/graphql/types/commit_type.rb
0 → 100644
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录