Skip to content
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

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ artifacts/
/src/Tgstation.Server.Host/wwwroot
/src/Tgstation.Server.Host/--applicationName
/src/Tgstation.Server.Host/ClientApp
/src/Tgstation.Server.Host.Utils.GitLab.GraphQL/node_modules
/src/Tgstation.Server.Host.Utils.GitLab.GraphQL/schema.graphql
/tools/Tgstation.Server.ReleaseNotes/release_notes.md
launchSettings.json
release_notes.md
Expand All @@ -29,3 +31,4 @@ changelog.yml
*.sqlite3
packaging/
yarn-error.log*
.graphqlrc.json
21 changes: 21 additions & 0 deletions src/Tgstation.Server.Host.Utils.GitLab.GraphQL/.graphqlrc.json
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 {
Copy link
Member

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

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 {
Copy link
Member

Choose a reason for hiding this comment

The 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('/ &lt;auto-generated/&gt;','/ &lt;auto-generated /&gt;%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>
6 changes: 6 additions & 0 deletions src/Tgstation.Server.Host.Utils.GitLab.GraphQL/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"apollo": "^2.34.0"
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
Copy link
Member

Choose a reason for hiding this comment

The 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

}
Loading
Loading