Skip to content

Commit 753e80f

Browse files
authored
Make querybuilder thread safe (#142)
1 parent 0cb904e commit 753e80f

23 files changed

+183
-184
lines changed
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
41
using GitLabApiClient.Models.Branches.Requests;
52

63
namespace GitLabApiClient.Internal.Queries
74
{
85
internal class BranchQueryBuilder : QueryBuilder<BranchQueryOptions>
96
{
10-
protected override void BuildCore(BranchQueryOptions options)
7+
protected override void BuildCore(Query query, BranchQueryOptions options)
118
{
129
if (!string.IsNullOrEmpty(options.Search))
13-
Add("search", options.Search);
10+
query.Add("search", options.Search);
1411
}
1512
}
1613
}

src/GitLabApiClient/Internal/Queries/CommitQueryBuilder.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,28 @@ namespace GitLabApiClient.Internal.Queries
99
{
1010
internal class CommitQueryBuilder : QueryBuilder<CommitQueryOptions>
1111
{
12-
protected override void BuildCore(CommitQueryOptions options)
12+
protected override void BuildCore(Query query, CommitQueryOptions options)
1313
{
1414
if (!string.IsNullOrEmpty(options.RefName))
15-
Add("ref_name", options.RefName);
15+
query.Add("ref_name", options.RefName);
1616

1717
if (options.Path.IsNotNullOrEmpty())
18-
Add("path", options.Path);
18+
query.Add("path", options.Path);
1919

2020
if (options.Since.HasValue)
21-
Add("since", options.Since.Value);
21+
query.Add("since", options.Since.Value);
2222

2323
if (options.Until.HasValue)
24-
Add("until", options.Until.Value);
24+
query.Add("until", options.Until.Value);
2525

2626
if (options.All.HasValue)
27-
Add("all", options.All.Value);
27+
query.Add("all", options.All.Value);
2828

2929
if (options.WithStats.HasValue)
30-
Add("with_stats", options.WithStats.Value);
30+
query.Add("with_stats", options.WithStats.Value);
3131

3232
if (options.FirstParent.HasValue)
33-
Add("first_parent", options.FirstParent.Value);
34-
33+
query.Add("first_parent", options.FirstParent.Value);
3534
}
3635
}
3736
}

src/GitLabApiClient/Internal/Queries/CommitRefsQueryBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace GitLabApiClient.Internal.Queries
66
{
77
internal sealed class CommitRefsQueryBuilder : QueryBuilder<CommitRefsQueryOptions>
88
{
9-
protected override void BuildCore(CommitRefsQueryOptions options)
9+
protected override void BuildCore(Query query, CommitRefsQueryOptions options)
1010
{
1111
if (options.Type != CommitRefType.All)
1212
{
13-
Add("type", options.Type.ToLowerCaseString());
13+
query.Add("type", options.Type.ToLowerCaseString());
1414
}
1515
}
1616
}

src/GitLabApiClient/Internal/Queries/CommitStatusesQueryBuilder.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ namespace GitLabApiClient.Internal.Queries
55
{
66
internal class CommitStatusesQueryBuilder : QueryBuilder<CommitStatusesQueryOptions>
77
{
8-
protected override void BuildCore(CommitStatusesQueryOptions options)
8+
protected override void BuildCore(Query query, CommitStatusesQueryOptions options)
99
{
1010
if (!string.IsNullOrEmpty(options.Ref))
11-
Add("ref", options.Ref);
11+
query.Add("ref", options.Ref);
1212

1313
if (options.Name.IsNotNullOrEmpty())
14-
Add("name", options.Name);
14+
query.Add("name", options.Name);
1515

1616
if (options.Stage.IsNotNullOrEmpty())
17-
Add("stage", options.Stage);
17+
query.Add("stage", options.Stage);
1818

1919
if (options.All.HasValue)
20-
Add("all", options.All.Value);
21-
20+
query.Add("all", options.All.Value);
2221
}
2322
}
2423
}

src/GitLabApiClient/Internal/Queries/GroupLabelsQueryBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ internal class GroupLabelsQueryBuilder : QueryBuilder<GroupLabelsQueryOptions>
77
#region Overrides of QueryBuilder<GroupLabelsQueryOptions>
88

99
/// <inheritdoc />
10-
protected override void BuildCore(GroupLabelsQueryOptions options)
10+
protected override void BuildCore(Query query, GroupLabelsQueryOptions options)
1111
{
1212
if (options.WithCounts)
1313
{
14-
Add("with_counts", true);
14+
query.Add("with_counts", true);
1515
}
1616

1717
if (!options.IncludeAncestorGroups)
1818
{
19-
Add("include_ancestor_groups", false);
19+
query.Add("include_ancestor_groups", false);
2020
}
2121
}
2222

src/GitLabApiClient/Internal/Queries/GroupsProjectsQueryBuilder.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,52 @@ namespace GitLabApiClient.Internal.Queries
66
{
77
internal class ProjectsGroupQueryBuilder : QueryBuilder<ProjectsGroupQueryOptions>
88
{
9-
protected override void BuildCore(ProjectsGroupQueryOptions options)
9+
protected override void BuildCore(Query query, ProjectsGroupQueryOptions options)
1010
{
1111
if (options.Archived)
12-
Add("archived", options.Archived);
12+
query.Add("archived", options.Archived);
1313

1414
if (options.Visibility != GroupsVisibility.Public)
15-
Add("visibility", GetVisibilityQueryValue(options.Visibility));
15+
query.Add("visibility", GetVisibilityQueryValue(options.Visibility));
1616

1717
if (options.Order != GroupsProjectsOrder.CreatedAt)
18-
Add("order_by", GetOrderQueryValue(options.Order));
18+
query.Add("order_by", GetOrderQueryValue(options.Order));
1919

2020
if (options.Sort != GroupsSort.Ascending)
21-
Add("sort", GetSortQueryValue(options.Sort));
21+
query.Add("sort", GetSortQueryValue(options.Sort));
2222

2323
if (!options.Search.IsNullOrEmpty())
24-
Add("search", options.Search);
24+
query.Add("search", options.Search);
2525

2626
if (options.Simple)
27-
Add("simple", options.Simple);
27+
query.Add("simple", options.Simple);
2828

2929
if (options.Owned)
30-
Add("owned", options.Owned);
30+
query.Add("owned", options.Owned);
3131

3232
if (options.Starred)
33-
Add("starred", options.Starred);
33+
query.Add("starred", options.Starred);
3434

3535
if (options.WithIssuesEnabled)
36-
Add("with_issues_enabled", options.WithIssuesEnabled);
36+
query.Add("with_issues_enabled", options.WithIssuesEnabled);
3737

3838
if (options.WithMergeRequestsEnabled)
39-
Add("with_merge_requests_enabled", options.WithMergeRequestsEnabled);
39+
query.Add("with_merge_requests_enabled", options.WithMergeRequestsEnabled);
4040

4141
if (!options.WithShared)
42-
Add("with_shared", options.WithShared);
42+
query.Add("with_shared", options.WithShared);
4343

4444
if (options.IncludeSubgroups)
45-
Add("include_subgroups", options.IncludeSubgroups);
45+
query.Add("include_subgroups", options.IncludeSubgroups);
4646

4747
if (options.MinAccessLevel != null)
48-
Add("min_access_level", (int)options.MinAccessLevel);
48+
query.Add("min_access_level", (int)options.MinAccessLevel);
4949

5050
if (options.WithCustomAttributes)
51-
Add("with_custom_attributes", options.WithCustomAttributes);
51+
query.Add("with_custom_attributes", options.WithCustomAttributes);
5252

5353
if (options.WithSecurityReports)
54-
Add("with_security_reports", options.WithSecurityReports);
55-
54+
query.Add("with_security_reports", options.WithSecurityReports);
5655
}
5756

5857
private static string GetVisibilityQueryValue(GroupsVisibility visibility)

src/GitLabApiClient/Internal/Queries/GroupsQueryBuilder.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ namespace GitLabApiClient.Internal.Queries
66
{
77
internal sealed class GroupsQueryBuilder : QueryBuilder<GroupsQueryOptions>
88
{
9-
protected override void BuildCore(GroupsQueryOptions options)
9+
protected override void BuildCore(Query query, GroupsQueryOptions options)
1010
{
11-
Add("skip_groups", options.SkipGroups);
11+
query.Add("skip_groups", options.SkipGroups);
1212

1313
if (options.AllAvailable)
14-
Add("all_available", options.AllAvailable);
14+
query.Add("all_available", options.AllAvailable);
1515

1616
if (!options.Search.IsNullOrEmpty())
17-
Add("search", options.Search);
17+
query.Add("search", options.Search);
1818

1919
if (options.Order != GroupsOrder.Name)
20-
Add("order_by", GetOrderQueryValue(options.Order));
20+
query.Add("order_by", GetOrderQueryValue(options.Order));
2121

2222
if (options.Sort != GroupsSort.Ascending)
23-
Add("sort", GetSortQueryValue(options.Sort));
23+
query.Add("sort", GetSortQueryValue(options.Sort));
2424

2525
if (options.Statistics)
26-
Add("statistics", options.Statistics);
26+
query.Add("statistics", options.Statistics);
2727

2828
if (options.WithCustomAttributes)
29-
Add("with_custom_attributes", options.WithCustomAttributes);
29+
query.Add("with_custom_attributes", options.WithCustomAttributes);
3030

3131
if (options.Owned)
32-
Add("owned", options.Owned);
32+
query.Add("owned", options.Owned);
3333

3434
if (options.MinAccessLevel.HasValue)
35-
Add("min_access_level", (int)options.MinAccessLevel.Value);
35+
query.Add("min_access_level", (int)options.MinAccessLevel.Value);
3636
}
3737

3838
private static string GetOrderQueryValue(GroupsOrder order)

src/GitLabApiClient/Internal/Queries/IssuesQueryBuilder.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,55 @@ namespace GitLabApiClient.Internal.Queries
99
{
1010
internal class IssuesQueryBuilder : QueryBuilder<IssuesQueryOptions>
1111
{
12-
protected override void BuildCore(IssuesQueryOptions options)
12+
protected override void BuildCore(Query query, IssuesQueryOptions options)
1313
{
1414
string stateQueryValue = GetStateQueryValue(options.State);
1515
if (!stateQueryValue.IsNullOrEmpty())
16-
Add("state", stateQueryValue);
16+
query.Add("state", stateQueryValue);
1717

1818
if (options.Labels.Any())
19-
Add("labels", options.Labels);
19+
query.Add("labels", options.Labels);
2020

2121
if (!options.MilestoneTitle.IsNullOrEmpty())
22-
Add("milestone", options.MilestoneTitle);
22+
query.Add("milestone", options.MilestoneTitle);
2323

24-
Add("scope", GetScopeQueryValue(options.Scope));
24+
query.Add("scope", GetScopeQueryValue(options.Scope));
2525

2626
if (options.AuthorId.HasValue)
27-
Add("author_id", options.AuthorId.Value);
27+
query.Add("author_id", options.AuthorId.Value);
2828
else if (!string.IsNullOrWhiteSpace(options.AuthorUsername))
29-
Add("author_username", options.AuthorUsername);
29+
query.Add("author_username", options.AuthorUsername);
3030

3131
if (options.AssigneeId.HasValue)
32-
Add("assignee_id", options.AssigneeId.Value);
32+
query.Add("assignee_id", options.AssigneeId.Value);
3333
else if (options.AssigneeUsername.Any())
34-
Add("assignee_username", options.AssigneeUsername);
34+
query.Add("assignee_username", options.AssigneeUsername);
3535

36-
Add(options.IssueIds);
36+
query.Add(options.IssueIds);
3737

3838
if (options.Order != IssuesOrder.CreatedAt)
39-
Add("order_by", GetIssuesOrderQueryValue(options.Order));
39+
query.Add("order_by", GetIssuesOrderQueryValue(options.Order));
4040

4141
if (options.SortOrder != SortOrder.Descending)
42-
Add("sort", GetSortOrderQueryValue(options.SortOrder));
42+
query.Add("sort", GetSortOrderQueryValue(options.SortOrder));
4343

4444
if (!options.Filter.IsNullOrEmpty())
45-
Add("search", options.Filter);
45+
query.Add("search", options.Filter);
4646

4747
if (options.IsConfidential)
48-
Add("confidential", true);
48+
query.Add("confidential", true);
4949

5050
if (options.CreatedBefore.HasValue)
51-
Add("created_before", options.CreatedBefore.Value);
51+
query.Add("created_before", options.CreatedBefore.Value);
5252

5353
if (options.CreatedAfter.HasValue)
54-
Add("created_after", options.CreatedAfter.Value);
54+
query.Add("created_after", options.CreatedAfter.Value);
5555

5656
if (options.UpdatedBefore.HasValue)
57-
Add("updated_before", options.UpdatedBefore.Value);
57+
query.Add("updated_before", options.UpdatedBefore.Value);
5858

5959
if (options.UpdatedAfter.HasValue)
60-
Add("updated_after", options.UpdatedAfter.Value);
60+
query.Add("updated_after", options.UpdatedAfter.Value);
6161
}
6262

6363
private static string GetStateQueryValue(IssueState state)

src/GitLabApiClient/Models/Job/Requests/JobQueryBuilder.cs renamed to src/GitLabApiClient/Internal/Queries/JobQueryBuilder.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
using System;
2-
using GitLabApiClient.Internal.Queries;
31
using GitLabApiClient.Internal.Utilities;
2+
using GitLabApiClient.Models.Job.Requests;
43

5-
namespace GitLabApiClient.Models.Job.Requests
4+
namespace GitLabApiClient.Internal.Queries
65
{
76
internal sealed class JobQueryBuilder : QueryBuilder<JobQueryOptions>
87
{
98
#region Overrides of QueryBuilder<PipelineQueryOptions>
109

1110
/// <inheritdoc />
12-
protected override void BuildCore(JobQueryOptions options)
11+
protected override void BuildCore(Query query, JobQueryOptions options)
1312
{
1413
if (options.Scope != JobScope.All)
1514
{
16-
Add("scope", options.Scope.ToLowerCaseString());
15+
query.Add("scope", options.Scope.ToLowerCaseString());
1716
}
1817
}
1918

src/GitLabApiClient/Internal/Queries/MergeRequestsQueryBuilder.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@ namespace GitLabApiClient.Internal.Queries
88
{
99
internal class MergeRequestsQueryBuilder : QueryBuilder<MergeRequestsQueryOptions>
1010
{
11-
protected override void BuildCore(MergeRequestsQueryOptions options)
11+
protected override void BuildCore(Query query, MergeRequestsQueryOptions options)
1212
{
1313
string stateQueryValue = GetStateQueryValue(options.State);
1414
if (!stateQueryValue.IsNullOrEmpty())
15-
Add("state", stateQueryValue);
15+
query.Add("state", stateQueryValue);
1616

1717
if (options.Order != MergeRequestsOrder.CreatedAt)
18-
Add("order_by", GetIssuesOrderQueryValue(options.Order));
18+
query.Add("order_by", GetIssuesOrderQueryValue(options.Order));
1919

2020
if (options.SortOrder != SortOrder.Descending)
21-
Add("sort", GetSortOrderQueryValue(options.SortOrder));
21+
query.Add("sort", GetSortOrderQueryValue(options.SortOrder));
2222

2323
if (!options.MilestoneTitle.IsNullOrEmpty())
24-
Add("milestone", options.MilestoneTitle);
24+
query.Add("milestone", options.MilestoneTitle);
2525

2626
if (options.Simple)
27-
Add("view", "simple");
27+
query.Add("view", "simple");
2828

2929
if (options.Labels.Any())
30-
Add("labels", options.Labels);
30+
query.Add("labels", options.Labels);
3131

3232
if (options.CreatedAfter.HasValue)
33-
Add("created_after", options.CreatedAfter.Value);
33+
query.Add("created_after", options.CreatedAfter.Value);
3434

3535
if (options.CreatedBefore.HasValue)
36-
Add("created_before", options.CreatedBefore.Value);
36+
query.Add("created_before", options.CreatedBefore.Value);
3737

38-
Add("scope", GetScopeQueryValue(options.Scope));
38+
query.Add("scope", GetScopeQueryValue(options.Scope));
3939

4040
if (options.AuthorId.HasValue)
41-
Add("author_id", options.AuthorId.Value);
41+
query.Add("author_id", options.AuthorId.Value);
4242

4343
if (options.AssigneeId.HasValue)
44-
Add("assignee_id", options.AssigneeId.Value);
44+
query.Add("assignee_id", options.AssigneeId.Value);
4545
}
4646

4747
private static string GetStateQueryValue(QueryMergeRequestState state)

0 commit comments

Comments
 (0)