Skip to content
Commits on Source (4)
PATH
remote: .
specs:
gitlab-triage (1.43.2)
gitlab-triage (1.44.0)
activesupport (>= 5.1)
globalid (~> 1.0, >= 1.0.1)
graphql (< 2.1.0)
......
......@@ -177,6 +177,7 @@ Available condition types:
- [`labels` condition](#labels-condition)
- [`forbidden_labels` condition](#forbidden-labels-condition)
- [`no_additional_labels` condition](#no-additional-labels-condition)
- [`author_username` condition](#author-username-condition)
- [`author_member` condition](#author-member-condition)
- [`assignee_member` condition](#assignee-member-condition)
- [`draft` condition](#draft-condition)
......@@ -489,6 +490,17 @@ conditions:
no_additional_labels: true
```
##### Author username condition
Accepts the username to filter on.
Example:
```yml
conditions:
author_username: gitlab-bot
```
##### Author Member condition
This condition determines whether the author of a resource is a member of the specified group or project.
......
......@@ -501,6 +501,7 @@ module Gitlab
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def build_get_url(resource_type, conditions)
# Example issues query with state and labels
# https://gitlab.com/api/v4/projects/test-triage%2Fissue-project/issues?state=open&labels=project%20label%20with%20spaces,group_label_no_spaces
......@@ -510,6 +511,8 @@ module Gitlab
condition_builders = []
condition_builders << APIQueryBuilders::SingleQueryParamBuilder.new('iids', options.resource_reference[1..]) if options.resource_reference
author_username = conditions[:author_username]
condition_builders << APIQueryBuilders::SingleQueryParamBuilder.new('author_username', author_username) if author_username
condition_builders << APIQueryBuilders::MultiQueryParamBuilder.new('labels', conditions[:labels], ',') if conditions[:labels]
......@@ -560,6 +563,7 @@ module Gitlab
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
def milestone_condition_builder(resource_type, milestone_condition)
milestone_value = Array(milestone_condition)[0].to_s # back-compatibility
......
......@@ -91,6 +91,7 @@ module Gitlab
conditions.each do |condition, condition_params|
condition_queries << QueryParamBuilders::DateParamBuilder.new(condition_params) if condition.to_s == 'date'
condition_queries << QueryParamBuilders::BaseParamBuilder.new('authorUsername', condition_params) if condition.to_s == 'author_username'
condition_queries << QueryParamBuilders::BaseParamBuilder.new('milestoneTitle', condition_params) if condition.to_s == 'milestone'
condition_queries << QueryParamBuilders::BaseParamBuilder.new('state', condition_params, with_quotes: false) if condition.to_s == 'state'
condition_queries << QueryParamBuilders::BaseParamBuilder.new('iids', '$iids', with_quotes: false) if condition.to_s == 'iids'
......
......@@ -2,6 +2,6 @@
module Gitlab
module Triage
VERSION = '1.43.2'
VERSION = '1.44.0'
end
end
......@@ -492,6 +492,36 @@ describe Gitlab::Triage::Engine do
end
end
context "with author_username condition" do
let(:policies) do
{
resource_rules: {
issues: {
rules: [
{
name: 'Rule 1',
conditions: {
author_username: 'gitlab-bot'
},
actions: {
comment: 'Hello World!'
}
}
]
}
}
}
end
it 'pass the correct "author_username" param to the API call' do
expect(Gitlab::Triage::UrlBuilders::UrlBuilder).to receive(:new)
.with(a_hash_including(params: { per_page: 100, 'author_username' => 'gitlab-bot' }))
.and_call_original
expect { subject.perform }.to output.to_stdout
end
end
describe 'summarize rules' do
let(:policies) do
{
......
......@@ -372,6 +372,21 @@ describe Gitlab::Triage::GraphqlQueries::QueryBuilder do
end
end
shared_examples 'author username graphql query' do
context 'when author username condition is provided' do
let(:conditions) do
{
author_username: 'gitlab-bot'
}
end
let(:resource_query) { ', authorUsername: "gitlab-bot"' }
let(:fields) { 'labels { nodes { title } } author { id name username }' }
it_behaves_like 'graphql only query'
end
end
shared_examples 'target branch graphql query' do
context 'when target branch condition is provided' do
let(:conditions) do
......@@ -470,6 +485,7 @@ describe Gitlab::Triage::GraphqlQueries::QueryBuilder do
it_behaves_like 'milestone graphql query'
it_behaves_like 'state graphql query'
it_behaves_like 'source branch graphql query'
it_behaves_like 'author username graphql query'
it_behaves_like 'target branch graphql query'
it_behaves_like 'draft: true graphql query'
it_behaves_like 'draft: false graphql query'
......