-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TM Comment Consolidation in Github/Gitlab #2131
base: dev
Are you sure you want to change the base?
Changes from all commits
4bec6d1
d004750
fe1101c
3195a73
61a604b
653b825
699eb34
5cd2be6
531e969
1ab83f4
36f5102
9f64b49
54bd7c6
d80cd85
b943efd
994d165
be422d2
d811acc
3b08f4e
3bd3bef
a1e631f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
] | ||
} | ||
} | ||
} |
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 | ||
} | ||
} |
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query GetCurrentUser { | ||
currentUser | ||
{ | ||
username | ||
} | ||
} |
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 | ||
} | ||
} | ||
} |
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 | ||
} | ||
} | ||
} | ||
} | ||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pointing out another connection that needs paginating eventually |
||
state | ||
diffHeadSha | ||
mergeCommitSha | ||
closedAt | ||
iid | ||
id | ||
} | ||
} | ||
} | ||
} |
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(); | ||
} | ||
} |
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; | ||
} | ||
} | ||
} | ||
} |
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; } | ||
} | ||
} |
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> | ||
Drulikar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<PackageReference Include="StrawberryShake.Server" Version="15.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="GQL\Queries\" /> | ||
<Folder Include="GQL\Mutations\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"devDependencies": { | ||
"apollo": "^2.34.0" | ||
}, | ||
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the wrong version but that's my fault I think. Reminder to myself to fix after merging |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that we likely need to paginate any connections we're querying in the future but I'll wait for someone to complain about it