Skip to content

Commit

Permalink
feat(webserver): add GraphQL endpoints for gitlab integration (#1967)
Browse files Browse the repository at this point in the history
* feat(webserver): add GraphQL endpoints for gitlab integration

* Update graphql schema

* Extract input types

* Fix ui code
  • Loading branch information
boxbeam authored Apr 26, 2024
1 parent 0f6fe63 commit 46e3906
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import {
} from '../../components/github-form'

const deleteGithubRepositoryProviderMutation = graphql(/* GraphQL */ `
mutation DeleteGithubRepositoryProvider($id: ID!) {
mutation DeleteRepositoryProvider($id: ID!) {
deleteGithubRepositoryProvider(id: $id)
}
`)

const updateGithubRepositoryProviderMutation = graphql(/* GraphQL */ `
mutation UpdateGithubRepositoryProvider(
$input: UpdateGithubRepositoryProviderInput!
$input: UpdateRepositoryProviderInput!
) {
updateGithubRepositoryProvider(input: $input)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

const createGithubRepositoryProvider = graphql(/* GraphQL */ `
mutation CreateGithubRepositoryProvider(
$input: CreateGithubRepositoryProviderInput!
$input: CreateRepositoryProviderInput!
) {
createGithubRepositoryProvider(input: $input)
}
Expand Down
87 changes: 64 additions & 23 deletions ee/tabby-webserver/graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
input UpdateRepositoryProviderInput {
id: ID!
displayName: String!
accessToken: String!
}

type GitlabRepositoryProvider {
id: ID!
displayName: String!
connected: Boolean!
}

enum Language {
RUST
PYTHON
Expand Down Expand Up @@ -36,6 +48,11 @@ type JobRun {
stderr: String!
}

type GitlabProvidedRepositoryEdge {
node: GitlabProvidedRepository!
cursor: String!
}

enum AuthMethod {
NONE
PLAIN
Expand Down Expand Up @@ -71,6 +88,11 @@ type LicenseInfo {
expiresAt: DateTimeUtc
}

type GitlabRepositoryProviderEdge {
node: GitlabRepositoryProvider!
cursor: String!
}

type GithubRepositoryProviderConnection {
edges: [GithubRepositoryProviderEdge!]!
pageInfo: PageInfo!
Expand Down Expand Up @@ -130,6 +152,11 @@ type Invitation {
createdAt: DateTimeUtc!
}

type GitlabProvidedRepositoryConnection {
edges: [GitlabProvidedRepositoryEdge!]!
pageInfo: PageInfo!
}

type EmailSetting {
smtpUsername: String!
smtpServer: String!
Expand All @@ -139,17 +166,17 @@ type EmailSetting {
authMethod: AuthMethod!
}

type TokenAuthResponse {
accessToken: String!
refreshToken: String!
}

type JobStats {
success: Int!
failed: Int!
pending: Int!
}

type TokenAuthResponse {
accessToken: String!
refreshToken: String!
}

type NetworkSetting {
externalUrl: String!
}
Expand Down Expand Up @@ -201,10 +228,14 @@ type Mutation {
deleteEmailSetting: Boolean!
uploadLicense(license: String!): Boolean!
resetLicense: Boolean!
createGithubRepositoryProvider(input: CreateGithubRepositoryProviderInput!): ID!
createGithubRepositoryProvider(input: CreateRepositoryProviderInput!): ID!
deleteGithubRepositoryProvider(id: ID!): Boolean!
updateGithubRepositoryProvider(input: UpdateGithubRepositoryProviderInput!): Boolean!
updateGithubRepositoryProvider(input: UpdateRepositoryProviderInput!): Boolean!
updateGithubProvidedRepositoryActive(id: ID!, active: Boolean!): Boolean!
createGitlabRepositoryProvider(input: CreateRepositoryProviderInput!): ID!
deleteGitlabRepositoryProvider(id: ID!): Boolean!
updateGitlabRepositoryProvider(input: UpdateRepositoryProviderInput!): Boolean!
updateGitlabProvidedRepositoryActive(id: ID!, active: Boolean!): Boolean!
}

type UserEventEdge {
Expand All @@ -217,12 +248,6 @@ type RepositoryEdge {
cursor: String!
}

input UpdateGithubRepositoryProviderInput {
id: ID!
displayName: String!
accessToken: String!
}

"DateTime"
scalar DateTimeUtc

Expand Down Expand Up @@ -250,6 +275,8 @@ type Query {
invitations(after: String, before: String, first: Int, last: Int): InvitationConnection!
githubRepositoryProviders(ids: [ID!], after: String, before: String, first: Int, last: Int): GithubRepositoryProviderConnection!
githubRepositories(providerIds: [ID!]!, after: String, before: String, first: Int, last: Int): GithubProvidedRepositoryConnection!
gitlabRepositoryProviders(ids: [ID!], after: String, before: String, first: Int, last: Int): GitlabRepositoryProviderConnection!
gitlabRepositories(providerIds: [ID!]!, after: String, before: String, first: Int, last: Int): GitlabProvidedRepositoryConnection!
jobRuns(ids: [ID!], jobs: [String!], after: String, before: String, first: Int, last: Int): JobRunConnection!
jobRunStats(jobs: [String!]): JobStats!
emailSetting: EmailSetting
Expand Down Expand Up @@ -299,6 +326,11 @@ type RefreshTokenResponse {
refreshExpiresAt: DateTimeUtc!
}

type GitlabRepositoryProviderConnection {
edges: [GitlabRepositoryProviderEdge!]!
pageInfo: PageInfo!
}

type RepositoryConnection {
edges: [RepositoryEdge!]!
pageInfo: PageInfo!
Expand All @@ -320,6 +352,15 @@ enum LicenseType {
ENTERPRISE
}

type GitlabProvidedRepository {
id: ID!
vendorId: String!
gitlabRepositoryProviderId: ID!
name: String!
gitUrl: String!
active: Boolean!
}

type OAuthCredential {
provider: OAuthProvider!
clientId: String!
Expand Down Expand Up @@ -347,7 +388,7 @@ input PasswordResetInput {
password2: String!
}

input CreateGithubRepositoryProviderInput {
input CreateRepositoryProviderInput {
displayName: String!
accessToken: String!
}
Expand All @@ -363,10 +404,6 @@ type User {
isPasswordSet: Boolean!
}

input RequestInvitationInput {
email: String!
}

type Worker {
kind: WorkerKind!
name: String!
Expand All @@ -378,23 +415,27 @@ type Worker {
cudaDevices: [String!]!
}

enum OAuthProvider {
GITHUB
GOOGLE
}

type InvitationEdge {
node: Invitation!
cursor: String!
}

enum OAuthProvider {
GITHUB
GOOGLE
}

type PageInfo {
hasPreviousPage: Boolean!
hasNextPage: Boolean!
startCursor: String
endCursor: String
}

input RequestInvitationInput {
email: String!
}

type GithubProvidedRepositoryEdge {
node: GithubProvidedRepository!
cursor: String!
Expand Down
26 changes: 1 addition & 25 deletions ee/tabby-webserver/src/schema/github_repository_provider.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use juniper::{GraphQLInputObject, GraphQLObject, ID};
use validator::Validate;
use juniper::{GraphQLObject, ID};

use super::Context;
use crate::{juniper::relay::NodeType, schema::Result};

#[derive(GraphQLInputObject, Validate)]
pub struct CreateGithubRepositoryProviderInput {
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLInputObject, Validate)]
pub struct UpdateGithubRepositoryProviderInput {
pub id: ID,
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLObject, Debug, PartialEq)]
#[graphql(context = Context)]
pub struct GithubRepositoryProvider {
Expand Down
26 changes: 1 addition & 25 deletions ee/tabby-webserver/src/schema/gitlab_repository_provider.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use juniper::{GraphQLInputObject, GraphQLObject, ID};
use validator::Validate;
use juniper::{GraphQLObject, ID};

use super::Context;
use crate::{juniper::relay::NodeType, schema::Result};

#[derive(GraphQLInputObject, Validate)]
pub struct CreateGitlabRepositoryProviderInput {
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLInputObject, Validate)]
pub struct UpdateGitlabRepositoryProviderInput {
pub id: ID,
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLObject, Debug, PartialEq)]
#[graphql(context = Context)]
pub struct GitlabRepositoryProvider {
Expand Down
Loading

0 comments on commit 46e3906

Please sign in to comment.