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
a3e72ac4
Commit
a3e72ac4
authored
Aug 05, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move shared fields to concerns
- Update some wording - Add resolver specs
parent
5e107b66
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
136 additions
and
133 deletions
+136
-133
app/graphql/resolvers/concerns/issue_resolver_fields.rb
app/graphql/resolvers/concerns/issue_resolver_fields.rb
+51
-0
app/graphql/resolvers/issue_resolver_fields.rb
app/graphql/resolvers/issue_resolver_fields.rb
+0
-56
app/graphql/resolvers/issue_status_counts_resolver.rb
app/graphql/resolvers/issue_status_counts_resolver.rb
+1
-1
app/graphql/resolvers/issues_resolver.rb
app/graphql/resolvers/issues_resolver.rb
+3
-0
app/graphql/types/issue_status_counts_type.rb
app/graphql/types/issue_status_counts_type.rb
+5
-3
changelogs/unreleased/232580-issue-state-counts-graphql.yml
changelogs/unreleased/232580-issue-state-counts-graphql.yml
+1
-1
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+0
-10
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+30
-54
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+0
-1
lib/gitlab/issuables_count_for_state.rb
lib/gitlab/issuables_count_for_state.rb
+3
-3
spec/graphql/resolvers/issue_status_counts_resolver_spec.rb
spec/graphql/resolvers/issue_status_counts_resolver_spec.rb
+40
-0
spec/graphql/types/issue_status_count_type_spec.rb
spec/graphql/types/issue_status_count_type_spec.rb
+0
-1
spec/requests/api/graphql/issue_status_counts_spec.rb
spec/requests/api/graphql/issue_status_counts_spec.rb
+2
-3
No files found.
app/graphql/resolvers/concerns/issue_resolver_fields.rb
0 → 100644
View file @
a3e72ac4
# frozen_string_literal: true
module
IssueResolverFields
extend
ActiveSupport
::
Concern
prepended
do
argument
:iid
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'IID of the issue. For example, "1"'
argument
:iids
,
[
GraphQL
::
STRING_TYPE
],
required:
false
,
description:
'List of IIDs of issues. For example, [1, 2]'
argument
:label_name
,
GraphQL
::
STRING_TYPE
.
to_list_type
,
required:
false
,
description:
'Labels applied to this issue'
argument
:milestone_title
,
GraphQL
::
STRING_TYPE
.
to_list_type
,
required:
false
,
description:
'Milestones applied to this issue'
argument
:assignee_username
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'Username of a user assigned to the issues'
argument
:assignee_id
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'ID of a user assigned to the issues, "none" and "any" values supported'
argument
:created_before
,
Types
::
TimeType
,
required:
false
,
description:
'Issues created before this date'
argument
:created_after
,
Types
::
TimeType
,
required:
false
,
description:
'Issues created after this date'
argument
:updated_before
,
Types
::
TimeType
,
required:
false
,
description:
'Issues updated before this date'
argument
:updated_after
,
Types
::
TimeType
,
required:
false
,
description:
'Issues updated after this date'
argument
:closed_before
,
Types
::
TimeType
,
required:
false
,
description:
'Issues closed before this date'
argument
:closed_after
,
Types
::
TimeType
,
required:
false
,
description:
'Issues closed after this date'
argument
:search
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'Search query for issue title or description'
argument
:types
,
[
Types
::
IssueTypeEnum
],
as: :issue_types
,
description:
'Filter issues by the given issue types'
,
required:
false
end
end
app/graphql/resolvers/issue_resolver_fields.rb
deleted
100644 → 0
View file @
5e107b66
# frozen_string_literal: true
module
Resolvers
module
IssueResolverFields
extend
ActiveSupport
::
Concern
prepended
do
argument
:iid
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'IID of the issue. For example, "1"'
argument
:iids
,
[
GraphQL
::
STRING_TYPE
],
required:
false
,
description:
'List of IIDs of issues. For example, [1, 2]'
argument
:state
,
Types
::
IssuableStateEnum
,
required:
false
,
description:
'Current state of this issue'
argument
:label_name
,
GraphQL
::
STRING_TYPE
.
to_list_type
,
required:
false
,
description:
'Labels applied to this issue'
argument
:milestone_title
,
GraphQL
::
STRING_TYPE
.
to_list_type
,
required:
false
,
description:
'Milestones applied to this issue'
argument
:assignee_username
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'Username of a user assigned to the issues'
argument
:assignee_id
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'ID of a user assigned to the issues, "none" and "any" values supported'
argument
:created_before
,
Types
::
TimeType
,
required:
false
,
description:
'Issues created before this date'
argument
:created_after
,
Types
::
TimeType
,
required:
false
,
description:
'Issues created after this date'
argument
:updated_before
,
Types
::
TimeType
,
required:
false
,
description:
'Issues updated before this date'
argument
:updated_after
,
Types
::
TimeType
,
required:
false
,
description:
'Issues updated after this date'
argument
:closed_before
,
Types
::
TimeType
,
required:
false
,
description:
'Issues closed before this date'
argument
:closed_after
,
Types
::
TimeType
,
required:
false
,
description:
'Issues closed after this date'
argument
:search
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'Search query for issue title or description'
argument
:types
,
[
Types
::
IssueTypeEnum
],
as: :issue_types
,
description:
'Filter issues by the given issue types'
,
required:
false
end
end
end
app/graphql/resolvers/issue_status_counts_resolver.rb
View file @
a3e72ac4
...
...
@@ -2,7 +2,7 @@
module
Resolvers
class
IssueStatusCountsResolver
<
BaseResolver
prepend
Resolvers
::
IssueResolverFields
prepend
IssueResolverFields
type
Types
::
IssueStatusCountsType
,
null:
true
...
...
app/graphql/resolvers/issues_resolver.rb
View file @
a3e72ac4
...
...
@@ -4,6 +4,9 @@ module Resolvers
class
IssuesResolver
<
BaseResolver
prepend
Resolvers
::
IssueResolverFields
argument
:state
,
Types
::
IssuableStateEnum
,
required:
false
,
description:
'Current state of this issue'
argument
:sort
,
Types
::
IssueSortEnum
,
description:
'Sort issues by this criteria'
,
required:
false
,
...
...
app/graphql/types/issue_status_counts_type.rb
View file @
a3e72ac4
...
...
@@ -7,11 +7,13 @@ module Types
authorize
:read_issue
::
Gitlab
::
IssuablesCountForState
::
STATES
.
each
do
|
status
|
field
status
,
::
Gitlab
::
IssuablesCountForState
::
STATES
.
each
do
|
state
|
next
unless
Issue
.
available_states
.
keys
.
push
(
'all'
).
include?
(
state
)
field
state
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
"Number of issues with status
#{
stat
us
.
upcase
}
for the project"
description:
"Number of issues with status
#{
stat
e
.
upcase
}
for the project"
end
end
end
changelogs/unreleased/232580-issue-state-counts-graphql.yml
View file @
a3e72ac4
---
title
:
Add
status counts to Issue
s in GraphQL
title
:
Add
issue status counts to Project
s in GraphQL
merge_request
:
38263
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
a3e72ac4
...
...
@@ -7266,11 +7266,6 @@ type IssueStatusCountsType {
"""
closed
:
Int
"""
Number
of
issues
with
status
MERGED
for
the
project
"""
merged
:
Int
"""
Number
of
issues
with
status
OPENED
for
the
project
"""
...
...
@@ -10357,11 +10352,6 @@ type Project {
"""
search
:
String
"""
Current
state
of
this
issue
"""
state
:
IssuableState
"""
Filter
issues
by
the
given
issue
types
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
a3e72ac4
...
...
@@ -15599,16 +15599,6 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "labelName",
"description": "Labels applied to this issue",
...
...
@@ -15745,6 +15735,16 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "sort",
"description": "Sort issues by this criteria",
...
...
@@ -20034,20 +20034,6 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "merged",
"description": "Number of issues with status MERGED for the project",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "opened",
"description": "Number of issues with status OPENED for the project",
...
...
@@ -30529,16 +30515,6 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "labelName",
"description": "Labels applied to this issue",
...
...
@@ -30675,6 +30651,16 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "sort",
"description": "Sort issues by this criteria",
...
...
@@ -30740,16 +30726,6 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "labelName",
"description": "Labels applied to this issue",
...
...
@@ -30927,16 +30903,6 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "labelName",
"description": "Labels applied to this issue",
...
...
@@ -31073,6 +31039,16 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "Current state of this issue",
"type": {
"kind": "ENUM",
"name": "IssuableState",
"ofType": null
},
"defaultValue": null
},
{
"name": "sort",
"description": "Sort issues by this criteria",
doc/api/graphql/reference/index.md
View file @
a3e72ac4
...
...
@@ -1112,7 +1112,6 @@ Represents total number of issues for the represented statuses
| --- | ---- | ---------- |
|
`all`
| Int | Number of issues with status ALL for the project |
|
`closed`
| Int | Number of issues with status CLOSED for the project |
|
`merged`
| Int | Number of issues with status MERGED for the project |
|
`opened`
| Int | Number of issues with status OPENED for the project |
## Iteration
...
...
lib/gitlab/issuables_count_for_state.rb
View file @
a3e72ac4
...
...
@@ -26,9 +26,9 @@ module Gitlab
self
[
state
||
:opened
]
end
# Define method for each stat
us
STATES
.
each
do
|
stat
us
|
define_method
(
stat
us
)
{
self
[
status
]
}
# Define method for each stat
e
STATES
.
each
do
|
stat
e
|
define_method
(
stat
e
)
{
self
[
state
]
}
end
# Returns the count for the given state.
...
...
spec/graphql/resolvers/issue_status_counts_resolver_spec.rb
View file @
a3e72ac4
...
...
@@ -8,13 +8,53 @@ RSpec.describe Resolvers::IssueStatusCountsResolver do
describe
'#resolve'
do
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
,
state: :opened
,
created_at:
3
.
hours
.
ago
,
updated_at:
3
.
hours
.
ago
)
}
let_it_be
(
:incident
)
{
create
(
:incident
,
project:
project
,
state: :closed
,
created_at:
1
.
hour
.
ago
,
updated_at:
1
.
hour
.
ago
,
closed_at:
1
.
hour
.
ago
)
}
let
(
:args
)
{
{}
}
before
do
project
.
add_developer
(
current_user
)
end
subject
{
resolve_issue_status_counts
(
args
)
}
it
{
is_expected
.
to
be_a
(
Gitlab
::
IssuablesCountForState
)
}
specify
{
expect
(
subject
.
project
).
to
eq
(
project
)
}
it
'returns expected results'
do
result
=
resolve_issue_status_counts
expect
(
result
.
all
).
to
eq
2
expect
(
result
.
opened
).
to
eq
1
expect
(
result
.
closed
).
to
eq
1
end
it
'filters by search'
,
:aggregate_failures
do
result
=
resolve_issue_status_counts
(
search:
issue
.
title
)
expect
(
result
.
all
).
to
eq
1
expect
(
result
.
opened
).
to
eq
1
expect
(
result
.
closed
).
to
eq
0
end
it
'filters by issue type'
,
:aggregate_failures
do
result
=
resolve_issue_status_counts
(
issue_types:
[
'incident'
])
expect
(
result
.
all
).
to
eq
1
expect
(
result
.
opened
).
to
eq
0
expect
(
result
.
closed
).
to
eq
1
end
# The state param is ignored in IssuableFinder#count_by_state
it
'ignores state filter'
,
:aggregate_failures
do
result
=
resolve_issue_status_counts
(
state:
'closed'
)
expect
(
result
.
all
).
to
eq
2
expect
(
result
.
opened
).
to
eq
1
expect
(
result
.
closed
).
to
eq
1
end
private
def
resolve_issue_status_counts
(
args
=
{},
context
=
{
current_user:
current_user
})
...
...
spec/graphql/types/issue_status_count_type_spec.rb
View file @
a3e72ac4
...
...
@@ -10,7 +10,6 @@ RSpec.describe GitlabSchema.types['IssueStatusCountsType'] do
all
opened
closed
merged
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
...
...
spec/requests/api/graphql/issue_status_counts_spec.rb
View file @
a3e72ac4
...
...
@@ -50,9 +50,8 @@ RSpec.describe 'getting Issue counts by status' do
expect
(
issue_counts
).
to
eq
(
'all'
=>
2
,
'opened'
=>
1
,
'closed'
=>
1
,
'merged'
=>
0
# merged is not relevant for issues
)
# but is included in the return type (Gitlab::IssuablesCountForState)
'closed'
=>
1
)
end
end
end
...
...
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