-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2131 from Drulikar/tm_spam_reduction
TM Comment Consolidation in Github/Gitlab
- Loading branch information
Showing
25 changed files
with
4,141 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/.graphqlrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"schema": "schema.graphql", | ||
"documents": "**/*.graphql", | ||
"extensions": { | ||
"strawberryShake": { | ||
"name": "GraphQLClient", | ||
"url": "../../artifacts/gitlab-api.graphql", | ||
"namespace": "Tgstation.Server.Host.Utils.GitLab.GraphQL", | ||
"records": { | ||
"inputs": false, | ||
"entities": false | ||
}, | ||
"transportProfiles": [ | ||
{ | ||
"default": "Http", | ||
"subscription": "Http" | ||
} | ||
] | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GQL/Mutations/CreateNote.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mutation CreateNote($id: NoteableID!, $body: String!) { | ||
createNote(input: { noteableId: $id, body: $body }) { | ||
note { | ||
id | ||
body | ||
discussion { | ||
id | ||
} | ||
} | ||
errors | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GQL/Mutations/ModifyNote.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mutation ModifyNote($id: NoteID!, $body: String!) { | ||
updateNote(input: { id: $id, body: $body }) { | ||
note { | ||
id | ||
body | ||
} | ||
errors | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GQL/Queries/GetCurrentUser.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query GetCurrentUser { | ||
currentUser | ||
{ | ||
username | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GQL/Queries/GetMergeRequest.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
query GetMergeRequest($project: ID!, $number: String!) { | ||
project(fullPath: $project) { | ||
mergeRequest(iid: $number) { | ||
author { username } | ||
description | ||
title | ||
diffHeadSha | ||
mergeCommitSha | ||
webUrl | ||
iid | ||
id | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GQL/Queries/GetMergeRequestNotes.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
query GetMergeRequestNotes($project: ID!, $number: String!) { | ||
project(fullPath: $project) { | ||
mergeRequest(iid: $number) { | ||
iid | ||
id | ||
notes { | ||
nodes { | ||
author { username } | ||
body | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GQL/Queries/GetMergeRequests.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
query GetMergeRequests($project: ID!, $numbers: [String!]!) { | ||
project(fullPath: $project) { | ||
mergeRequests(iids: $numbers) { | ||
nodes { | ||
state | ||
diffHeadSha | ||
mergeCommitSha | ||
closedAt | ||
iid | ||
id | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GraphQLGitLabClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Tgstation.Server.Host.Utils.GitLab.GraphQL | ||
{ | ||
/// <inheritdoc /> | ||
sealed class GraphQLGitLabClient : IGraphQLGitLabClient | ||
{ | ||
/// <inheritdoc /> | ||
public IGraphQLClient GraphQL { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="ServiceProvider"/> containing the <see cref="GraphQL"/> client. | ||
/// </summary> | ||
readonly ServiceProvider serviceProvider; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GraphQLGitLabClient"/> class. | ||
/// </summary> | ||
/// <param name="serviceProvider">The value of <see cref="serviceProvider"/>.</param> | ||
public GraphQLGitLabClient(ServiceProvider serviceProvider) | ||
{ | ||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
GraphQL = serviceProvider.GetService<IGraphQLClient>() ?? throw new ArgumentException($"Expected an {nameof(IGraphQLClient)} service in the provider!", nameof(serviceProvider)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ValueTask DisposeAsync() | ||
=> serviceProvider.DisposeAsync(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/GraphQLGitLabClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Tgstation.Server.Host.Utils.GitLab.GraphQL | ||
{ | ||
/// <summary> | ||
/// Factory for creating <see cref="IGraphQLGitLabClient"/>s. | ||
/// </summary> | ||
public sealed class GraphQLGitLabClientFactory | ||
{ | ||
/// <summary> | ||
/// Sets up a <see cref="IGraphQLGitLabClient"/>. | ||
/// </summary> | ||
/// <param name="bearerToken">The token to use for authentication, if any.</param> | ||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a new <see cref="IGraphQLGitLabClient"/>.</returns> | ||
public static async ValueTask<IGraphQLGitLabClient> CreateClient(string? bearerToken = null) | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
|
||
var clientBuilder = serviceCollection | ||
.AddGraphQLClient(); | ||
var graphQLEndpoint = new Uri("https://gitlab.com/api/graphql"); | ||
|
||
clientBuilder.ConfigureHttpClient( | ||
client => | ||
{ | ||
client.BaseAddress = new Uri("https://gitlab.com/api/graphql"); | ||
if (bearerToken != null) | ||
{ | ||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken); | ||
} | ||
}); | ||
|
||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
try | ||
{ | ||
return new GraphQLGitLabClient(serviceProvider); | ||
} | ||
catch | ||
{ | ||
await serviceProvider.DisposeAsync(); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Tgstation.Server.Host.Utils.GitLab.GraphQL/IGraphQLGitLabClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Tgstation.Server.Host.Utils.GitLab.GraphQL | ||
{ | ||
/// <summary> | ||
/// Wrapper for using a GitLab <see cref="IGraphQLClient"/>. | ||
/// </summary> | ||
public interface IGraphQLGitLabClient : IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// Gets the underlying <see cref="IGraphQLClient"/>. | ||
/// </summary> | ||
IGraphQLClient GraphQL { get; } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...tation.Server.Host.Utils.GitLab.GraphQL/Tgstation.Server.Host.Utils.GitLab.GraphQL.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="../../build/SrcCommon.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>$(TgsFrameworkVersion)</TargetFrameworks> | ||
<Version>$(TgsCoreVersion)</Version> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<Target Name="InstallApollo" Inputs="package.json;yarn.lock" Outputs="node_modules/.bin/apollo"> | ||
<Message Text="Installing Apollo..." Importance="high" /> | ||
<Exec Command="yarn install --immutable --ignore-engines" /> | ||
</Target> | ||
|
||
<Target Name="GetApi" DependsOnTargets="InstallApollo" Inputs="node_modules/.bin/apollo" Outputs="../../artifacts/gitlab-api.graphql"> | ||
<Message Text="Fetching GitLab GraphQL API schema..." Importance="high" /> | ||
<MakeDir Directories="../../artifacts" /> | ||
<Exec Command="node_modules/.bin/apollo client:download-schema --endpoint=https://gitlab.com/api/graphql ../../artifacts/gitlab-api.graphql" /> | ||
</Target> | ||
|
||
<!-- https://github.com/ChilliCream/graphql-platform/blob/c0c8df525ca0f47bf3b3b409a8b22cbe37f7a9c0/src/StrawberryShake/MetaPackages/Common/MSBuild/StrawberryShake.targets#L20 --> | ||
<Target Name="ImportGraphQLApiSchema" DependsOnTargets="GetApi" BeforeTargets="_GraphQLCodeGenerationRoot" Inputs="../../artifacts/gitlab-api.graphql" Outputs="schema.graphql"> | ||
<Copy SkipUnchangedFiles="true" SourceFiles="../../artifacts/gitlab-api.graphql" DestinationFiles="schema.graphql" /> | ||
<WriteLinesToFile File="schema.graphql" Lines="$([System.IO.File]::ReadAllText('schema.graphql').Replace('\', ''))" Overwrite="true" Encoding="UTF-8" /> | ||
</Target> | ||
|
||
<Target Name="FixWarningsInGeneratedSchema" AfterTargets="GenerateGraphQLCode"> | ||
<PropertyGroup> | ||
<InputFile>$(IntermediateOutputPath)berry/GraphQLClient.Client.cs</InputFile> | ||
<OutputFile>$(IntermediateOutputPath)berry/GraphQLClient.Client.cs</OutputFile> | ||
</PropertyGroup> | ||
<WriteLinesToFile File="$(OutputFile)" Lines="$([System.IO.File]::ReadAllText($(InputFile)).Replace('/ <auto-generated/>','/ <auto-generated />%0d%0a#pragma warning disable'))" Overwrite="true" Encoding="Unicode" /> | ||
</Target> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="StrawberryShake.Server" Version="15.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="GQL\Queries\" /> | ||
<Folder Include="GQL\Mutations\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"devDependencies": { | ||
"apollo": "^2.34.0" | ||
}, | ||
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610" | ||
} |
Oops, something went wrong.