mirror of
https://github.com/snowball-tools/snowballtools-base.git
synced 2024-11-17 12:19:20 +00:00
feat(template projects): generate git repo on backend (#218)
### TL;DR - Still cretaes app if user migrates from page The PR introduces a new `AddProjectFromTemplate` mutation to facilitate project creation using a repository template. This change centralizes the template project creation logic within the backend, improving code maintainability by removing redundant client-side code. ### What changed? - Added `AddProjectFromTemplate` input type in `schema.gql` and corresponding TypeScript interfaces. - Implemented `addProjectFromTemplate` resolver with error handling and Octokit integration for repository creation. - Updated `service.ts` to include the new `addProjectFromTemplate` method. - Created new GraphQL `Mutation` for `addProjectFromTemplate` in the GraphQL schema. - Adjusted the client-side GQLClient to support the new mutation. - Modified frontend to utilize the new backend mutation for project creation from a template. ### How to test? 1. Ensure your backend server is running. 2. Use a GraphQL client like Postman to call the `addProjectFromTemplate` mutation with appropriate input. 3. Verify that the new project is created using the specified template, and appropriate error messages are returned for failures. 4. Check the frontend flow for creating a project from a template to ensure it is working correctly. ### Why make this change? This change enhances code maintainability by centralizing template project creation logic within the backend, thereby reducing redundancy and potential inconsistencies in client-side implementations. ---
This commit is contained in:
parent
b12c95b2ff
commit
a684743bd6
@ -6,6 +6,7 @@ import { Permission } from './entity/ProjectMember';
|
||||
import { Domain } from './entity/Domain';
|
||||
import { Project } from './entity/Project';
|
||||
import { EnvironmentVariable } from './entity/EnvironmentVariable';
|
||||
import { AddProjectFromTemplateInput } from './types';
|
||||
|
||||
const log = debug('snowball:resolver');
|
||||
|
||||
@ -197,6 +198,26 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
}
|
||||
},
|
||||
|
||||
addProjectFromTemplate: async (
|
||||
_: any,
|
||||
{
|
||||
organizationSlug,
|
||||
data,
|
||||
}: { organizationSlug: string; data: AddProjectFromTemplateInput },
|
||||
context: any,
|
||||
) => {
|
||||
try {
|
||||
return await service.addProjectFromTemplate(
|
||||
context.user,
|
||||
organizationSlug,
|
||||
data,
|
||||
);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
addProject: async (
|
||||
_: any,
|
||||
{
|
||||
|
@ -130,6 +130,14 @@ input AddEnvironmentVariableInput {
|
||||
value: String!
|
||||
}
|
||||
|
||||
input AddProjectFromTemplateInput {
|
||||
templateOwner: String!
|
||||
templateRepo: String!
|
||||
owner: String!
|
||||
name: String!
|
||||
isPrivate: Boolean!
|
||||
}
|
||||
|
||||
input AddProjectInput {
|
||||
name: String!
|
||||
repository: String!
|
||||
@ -204,6 +212,10 @@ type Mutation {
|
||||
): Boolean!
|
||||
removeEnvironmentVariable(environmentVariableId: String!): Boolean!
|
||||
updateDeploymentToProd(deploymentId: String!): Boolean!
|
||||
addProjectFromTemplate(
|
||||
organizationSlug: String!
|
||||
data: AddProjectFromTemplateInput
|
||||
): Project!
|
||||
addProject(organizationSlug: String!, data: AddProjectInput): Project!
|
||||
updateProject(projectId: String!, data: UpdateProjectInput): Boolean!
|
||||
redeployToProd(deploymentId: String!): Boolean!
|
||||
|
@ -16,6 +16,7 @@ import { User } from './entity/User';
|
||||
import { Registry } from './registry';
|
||||
import { GitHubConfig, RegistryConfig } from './config';
|
||||
import {
|
||||
AddProjectFromTemplateInput,
|
||||
AppDeploymentRecord,
|
||||
AppDeploymentRemovalRecord,
|
||||
GitPushEventPayload,
|
||||
@ -643,6 +644,53 @@ export class Service {
|
||||
return newDeployment;
|
||||
}
|
||||
|
||||
async addProjectFromTemplate(
|
||||
user: User,
|
||||
organizationSlug: string,
|
||||
data: AddProjectFromTemplateInput,
|
||||
): Promise<Project | undefined> {
|
||||
try {
|
||||
const octokit = await this.getOctokit(user.id);
|
||||
|
||||
const gitRepo = await octokit?.rest.repos.createUsingTemplate({
|
||||
template_owner: data.templateOwner,
|
||||
template_repo: data.templateRepo,
|
||||
owner: data.owner,
|
||||
name: data.name,
|
||||
include_all_branches: false,
|
||||
private: data.isPrivate,
|
||||
});
|
||||
|
||||
if (!gitRepo) {
|
||||
throw new Error('Failed to create repository from template');
|
||||
}
|
||||
|
||||
const createdTemplateRepo = await octokit.rest.repos.get({
|
||||
owner: data.owner,
|
||||
repo: data.name,
|
||||
});
|
||||
|
||||
const prodBranch = createdTemplateRepo.data.default_branch ?? 'main';
|
||||
|
||||
const project = await this.addProject(user, organizationSlug, {
|
||||
name: `${gitRepo.data.owner!.login}-${gitRepo.data.name}`,
|
||||
prodBranch,
|
||||
repository: gitRepo.data.full_name,
|
||||
// TODO: Set selected template
|
||||
template: 'webapp',
|
||||
});
|
||||
|
||||
if (!project || !project.id) {
|
||||
throw new Error('Failed to create project from template');
|
||||
}
|
||||
|
||||
return project;
|
||||
} catch (error) {
|
||||
console.error('Error creating project from template:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async addProject(
|
||||
user: User,
|
||||
organizationSlug: string,
|
||||
@ -672,7 +720,7 @@ export class Service {
|
||||
});
|
||||
|
||||
// Create deployment with prod branch and latest commit
|
||||
await this.createDeployment(user.id, octokit, {
|
||||
const deployment = await this.createDeployment(user.id, octokit, {
|
||||
project,
|
||||
branch: project.prodBranch,
|
||||
environment: Environment.Production,
|
||||
@ -683,6 +731,8 @@ export class Service {
|
||||
|
||||
await this.createRepoHook(octokit, project);
|
||||
|
||||
console.log('projectid is', project.id);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ export interface AppDeploymentRecordAttributes {
|
||||
export interface AppDeploymentRemovalRecordAttributes {
|
||||
deployment: string;
|
||||
request: string;
|
||||
type: "ApplicationDeploymentRemovalRecord";
|
||||
type: 'ApplicationDeploymentRemovalRecord';
|
||||
version: string;
|
||||
}
|
||||
|
||||
@ -61,3 +61,11 @@ export interface AppDeploymentRecord extends RegistryRecord {
|
||||
export interface AppDeploymentRemovalRecord extends RegistryRecord {
|
||||
attributes: AppDeploymentRemovalRecordAttributes;
|
||||
}
|
||||
|
||||
export interface AddProjectFromTemplateInput {
|
||||
templateOwner: string;
|
||||
templateRepo: string;
|
||||
owner: string;
|
||||
name: string;
|
||||
isPrivate: boolean;
|
||||
}
|
||||
|
@ -50,36 +50,22 @@ const CreateRepo = () => {
|
||||
assert(template.repoFullName, 'Template URL not provided');
|
||||
const [owner, repo] = template.repoFullName.split('/');
|
||||
|
||||
// TODO: Handle this functionality in backend
|
||||
const gitRepo = await octokit?.rest.repos.createUsingTemplate({
|
||||
template_owner: owner,
|
||||
template_repo: repo,
|
||||
setIsLoading(true);
|
||||
|
||||
const { addProjectFromTemplate } = await client.addProjectFromTemplate(
|
||||
orgSlug!,
|
||||
{
|
||||
templateOwner: owner,
|
||||
templateRepo: repo,
|
||||
owner: data.account,
|
||||
name: data.repoName,
|
||||
include_all_branches: false,
|
||||
private: data.isPrivate,
|
||||
});
|
||||
isPrivate: false,
|
||||
},
|
||||
);
|
||||
|
||||
if (!gitRepo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Refetch to always get correct default branch
|
||||
const templateRepo = await octokit.rest.repos.get({
|
||||
owner: template.repoFullName.split('/')[0],
|
||||
repo: template.repoFullName.split('/')[1],
|
||||
});
|
||||
const prodBranch = templateRepo.data.default_branch ?? 'main';
|
||||
|
||||
const { addProject } = await client.addProject(orgSlug!, {
|
||||
name: `${gitRepo.data.owner!.login}-${gitRepo.data.name}`,
|
||||
prodBranch,
|
||||
repository: gitRepo.data.full_name,
|
||||
// TODO: Set selected template
|
||||
template: 'webapp',
|
||||
});
|
||||
|
||||
navigate(`deploy?projectId=${addProject.id}&templateId=${template.id}`);
|
||||
navigate(
|
||||
`deploy?projectId=${addProjectFromTemplate.id}&templateId=${template.id}`,
|
||||
);
|
||||
} catch (err) {
|
||||
setIsLoading(false);
|
||||
|
||||
|
13
packages/gql-client/dist/index.d.mts
vendored
13
packages/gql-client/dist/index.d.mts
vendored
@ -185,6 +185,9 @@ type RemoveEnvironmentVariableResponse = {
|
||||
type UpdateDeploymentToProdResponse = {
|
||||
updateDeploymentToProd: boolean;
|
||||
};
|
||||
type AddProjectFromTemplateResponse = {
|
||||
addProjectFromTemplate: Project;
|
||||
};
|
||||
type AddProjectResponse = {
|
||||
addProject: Project;
|
||||
};
|
||||
@ -200,6 +203,13 @@ type DeleteProjectResponse = {
|
||||
type DeleteDomainResponse = {
|
||||
deleteDomain: boolean;
|
||||
};
|
||||
type AddProjectFromTemplateInput = {
|
||||
templateOwner: string;
|
||||
templateRepo: string;
|
||||
owner: string;
|
||||
name: string;
|
||||
isPrivate: boolean;
|
||||
};
|
||||
type AddProjectInput = {
|
||||
name: string;
|
||||
repository: string;
|
||||
@ -267,6 +277,7 @@ declare class GQLClient {
|
||||
updateEnvironmentVariable(environmentVariableId: string, data: UpdateEnvironmentVariableInput): Promise<UpdateEnvironmentVariableResponse>;
|
||||
removeEnvironmentVariable(environmentVariableId: string): Promise<RemoveEnvironmentVariableResponse>;
|
||||
updateDeploymentToProd(deploymentId: string): Promise<UpdateDeploymentToProdResponse>;
|
||||
addProjectFromTemplate(organizationSlug: string, data: AddProjectFromTemplateInput): Promise<AddProjectFromTemplateResponse>;
|
||||
addProject(organizationSlug: string, data: AddProjectInput): Promise<AddProjectResponse>;
|
||||
updateProject(projectId: string, data: UpdateProjectInput): Promise<UpdateProjectResponse>;
|
||||
updateDomain(domainId: string, data: UpdateDomainInput): Promise<UpdateDomainResponse>;
|
||||
@ -281,4 +292,4 @@ declare class GQLClient {
|
||||
unauthenticateGithub(): Promise<UnauthenticateGitHubResponse>;
|
||||
}
|
||||
|
||||
export { type AddDomainInput, type AddDomainResponse, type AddEnvironmentVariableInput, type AddEnvironmentVariablesResponse, type AddProjectInput, type AddProjectMemberInput, type AddProjectMemberResponse, type AddProjectResponse, type AuthenticateGitHubResponse, type DeleteDeploymentResponse, type DeleteDomainResponse, type DeleteProjectResponse, type Deployment, DeploymentStatus, type Domain, DomainStatus, Environment, type EnvironmentVariable, type FilterDomainInput, GQLClient, type GetDeploymentsResponse, type GetDomainsResponse, type GetEnvironmentVariablesResponse, type GetOrganizationsResponse, type GetProjectMembersResponse, type GetProjectResponse, type GetProjectsInOrganizationResponse, type GetUserResponse, type GraphQLConfig, type Organization, type OrganizationMember, type OrganizationProject, Permission, type Project, type ProjectMember, type RedeployToProdResponse, type RemoveEnvironmentVariableResponse, type RemoveProjectMemberResponse, Role, type RollbackDeploymentResponse, type SearchProjectsResponse, type UnauthenticateGitHubResponse, type UpdateDeploymentToProdResponse, type UpdateDomainInput, type UpdateDomainResponse, type UpdateEnvironmentVariableInput, type UpdateEnvironmentVariableResponse, type UpdateProjectInput, type UpdateProjectMemberInput, type UpdateProjectMemberResponse, type UpdateProjectResponse, type User };
|
||||
export { type AddDomainInput, type AddDomainResponse, type AddEnvironmentVariableInput, type AddEnvironmentVariablesResponse, type AddProjectFromTemplateInput, type AddProjectFromTemplateResponse, type AddProjectInput, type AddProjectMemberInput, type AddProjectMemberResponse, type AddProjectResponse, type AuthenticateGitHubResponse, type DeleteDeploymentResponse, type DeleteDomainResponse, type DeleteProjectResponse, type Deployment, DeploymentStatus, type Domain, DomainStatus, Environment, type EnvironmentVariable, type FilterDomainInput, GQLClient, type GetDeploymentsResponse, type GetDomainsResponse, type GetEnvironmentVariablesResponse, type GetOrganizationsResponse, type GetProjectMembersResponse, type GetProjectResponse, type GetProjectsInOrganizationResponse, type GetUserResponse, type GraphQLConfig, type Organization, type OrganizationMember, type OrganizationProject, Permission, type Project, type ProjectMember, type RedeployToProdResponse, type RemoveEnvironmentVariableResponse, type RemoveProjectMemberResponse, Role, type RollbackDeploymentResponse, type SearchProjectsResponse, type UnauthenticateGitHubResponse, type UpdateDeploymentToProdResponse, type UpdateDomainInput, type UpdateDomainResponse, type UpdateEnvironmentVariableInput, type UpdateEnvironmentVariableResponse, type UpdateProjectInput, type UpdateProjectMemberInput, type UpdateProjectMemberResponse, type UpdateProjectResponse, type User };
|
||||
|
13
packages/gql-client/dist/index.d.ts
vendored
13
packages/gql-client/dist/index.d.ts
vendored
@ -185,6 +185,9 @@ type RemoveEnvironmentVariableResponse = {
|
||||
type UpdateDeploymentToProdResponse = {
|
||||
updateDeploymentToProd: boolean;
|
||||
};
|
||||
type AddProjectFromTemplateResponse = {
|
||||
addProjectFromTemplate: Project;
|
||||
};
|
||||
type AddProjectResponse = {
|
||||
addProject: Project;
|
||||
};
|
||||
@ -200,6 +203,13 @@ type DeleteProjectResponse = {
|
||||
type DeleteDomainResponse = {
|
||||
deleteDomain: boolean;
|
||||
};
|
||||
type AddProjectFromTemplateInput = {
|
||||
templateOwner: string;
|
||||
templateRepo: string;
|
||||
owner: string;
|
||||
name: string;
|
||||
isPrivate: boolean;
|
||||
};
|
||||
type AddProjectInput = {
|
||||
name: string;
|
||||
repository: string;
|
||||
@ -267,6 +277,7 @@ declare class GQLClient {
|
||||
updateEnvironmentVariable(environmentVariableId: string, data: UpdateEnvironmentVariableInput): Promise<UpdateEnvironmentVariableResponse>;
|
||||
removeEnvironmentVariable(environmentVariableId: string): Promise<RemoveEnvironmentVariableResponse>;
|
||||
updateDeploymentToProd(deploymentId: string): Promise<UpdateDeploymentToProdResponse>;
|
||||
addProjectFromTemplate(organizationSlug: string, data: AddProjectFromTemplateInput): Promise<AddProjectFromTemplateResponse>;
|
||||
addProject(organizationSlug: string, data: AddProjectInput): Promise<AddProjectResponse>;
|
||||
updateProject(projectId: string, data: UpdateProjectInput): Promise<UpdateProjectResponse>;
|
||||
updateDomain(domainId: string, data: UpdateDomainInput): Promise<UpdateDomainResponse>;
|
||||
@ -281,4 +292,4 @@ declare class GQLClient {
|
||||
unauthenticateGithub(): Promise<UnauthenticateGitHubResponse>;
|
||||
}
|
||||
|
||||
export { type AddDomainInput, type AddDomainResponse, type AddEnvironmentVariableInput, type AddEnvironmentVariablesResponse, type AddProjectInput, type AddProjectMemberInput, type AddProjectMemberResponse, type AddProjectResponse, type AuthenticateGitHubResponse, type DeleteDeploymentResponse, type DeleteDomainResponse, type DeleteProjectResponse, type Deployment, DeploymentStatus, type Domain, DomainStatus, Environment, type EnvironmentVariable, type FilterDomainInput, GQLClient, type GetDeploymentsResponse, type GetDomainsResponse, type GetEnvironmentVariablesResponse, type GetOrganizationsResponse, type GetProjectMembersResponse, type GetProjectResponse, type GetProjectsInOrganizationResponse, type GetUserResponse, type GraphQLConfig, type Organization, type OrganizationMember, type OrganizationProject, Permission, type Project, type ProjectMember, type RedeployToProdResponse, type RemoveEnvironmentVariableResponse, type RemoveProjectMemberResponse, Role, type RollbackDeploymentResponse, type SearchProjectsResponse, type UnauthenticateGitHubResponse, type UpdateDeploymentToProdResponse, type UpdateDomainInput, type UpdateDomainResponse, type UpdateEnvironmentVariableInput, type UpdateEnvironmentVariableResponse, type UpdateProjectInput, type UpdateProjectMemberInput, type UpdateProjectMemberResponse, type UpdateProjectResponse, type User };
|
||||
export { type AddDomainInput, type AddDomainResponse, type AddEnvironmentVariableInput, type AddEnvironmentVariablesResponse, type AddProjectFromTemplateInput, type AddProjectFromTemplateResponse, type AddProjectInput, type AddProjectMemberInput, type AddProjectMemberResponse, type AddProjectResponse, type AuthenticateGitHubResponse, type DeleteDeploymentResponse, type DeleteDomainResponse, type DeleteProjectResponse, type Deployment, DeploymentStatus, type Domain, DomainStatus, Environment, type EnvironmentVariable, type FilterDomainInput, GQLClient, type GetDeploymentsResponse, type GetDomainsResponse, type GetEnvironmentVariablesResponse, type GetOrganizationsResponse, type GetProjectMembersResponse, type GetProjectResponse, type GetProjectsInOrganizationResponse, type GetUserResponse, type GraphQLConfig, type Organization, type OrganizationMember, type OrganizationProject, Permission, type Project, type ProjectMember, type RedeployToProdResponse, type RemoveEnvironmentVariableResponse, type RemoveProjectMemberResponse, Role, type RollbackDeploymentResponse, type SearchProjectsResponse, type UnauthenticateGitHubResponse, type UpdateDeploymentToProdResponse, type UpdateDomainInput, type UpdateDomainResponse, type UpdateEnvironmentVariableInput, type UpdateEnvironmentVariableResponse, type UpdateProjectInput, type UpdateProjectMemberInput, type UpdateProjectMemberResponse, type UpdateProjectResponse, type User };
|
||||
|
47
packages/gql-client/dist/index.js
vendored
47
packages/gql-client/dist/index.js
vendored
@ -287,8 +287,14 @@ mutation ($projectId: String!, $data: [AddEnvironmentVariableInput!]) {
|
||||
}
|
||||
`;
|
||||
var updateEnvironmentVariable = import_client2.gql`
|
||||
mutation ($environmentVariableId: String!, $data: UpdateEnvironmentVariableInput!) {
|
||||
updateEnvironmentVariable(environmentVariableId: $environmentVariableId, data: $data)
|
||||
mutation (
|
||||
$environmentVariableId: String!
|
||||
$data: UpdateEnvironmentVariableInput!
|
||||
) {
|
||||
updateEnvironmentVariable(
|
||||
environmentVariableId: $environmentVariableId
|
||||
data: $data
|
||||
)
|
||||
}
|
||||
`;
|
||||
var removeEnvironmentVariable = import_client2.gql`
|
||||
@ -301,20 +307,30 @@ mutation ($deploymentId: String!) {
|
||||
updateDeploymentToProd(deploymentId: $deploymentId)
|
||||
}
|
||||
`;
|
||||
var addProjectFromTemplate = import_client2.gql`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput) {
|
||||
addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
var addProject = import_client2.gql`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectInput) {
|
||||
addProject(organizationSlug: $organizationSlug, data: $data) {
|
||||
id
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var updateProjectMutation = import_client2.gql`
|
||||
mutation ($projectId: String!, $data: UpdateProjectInput) {
|
||||
updateProject(projectId: $projectId, data: $data)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var updateDomainMutation = import_client2.gql`
|
||||
mutation ($domainId: String!, $data: UpdateDomainInput!) {
|
||||
updateDomain(domainId: $domainId, data: $data)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var redeployToProd = import_client2.gql`
|
||||
mutation ($deploymentId: String!) {
|
||||
redeployToProd(deploymentId: $deploymentId)
|
||||
@ -328,7 +344,8 @@ mutation ($projectId: String!) {
|
||||
var deleteDomain = import_client2.gql`
|
||||
mutation ($domainId: String!) {
|
||||
deleteDomain(domainId: $domainId)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var rollbackDeployment = import_client2.gql`
|
||||
mutation ($projectId: String!, $deploymentId: String!) {
|
||||
rollbackDeployment(projectId: $projectId, deploymentId: $deploymentId)
|
||||
@ -349,11 +366,13 @@ mutation ($code: String!) {
|
||||
authenticateGitHub(code: $code) {
|
||||
token
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var unauthenticateGitHub = import_client2.gql`
|
||||
mutation {
|
||||
unauthenticateGitHub
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
// src/client.ts
|
||||
var defaultOptions = {
|
||||
@ -538,6 +557,18 @@ var GQLClient = class {
|
||||
return data;
|
||||
});
|
||||
}
|
||||
addProjectFromTemplate(organizationSlug, data) {
|
||||
return __async(this, null, function* () {
|
||||
const result = yield this.client.mutate({
|
||||
mutation: addProjectFromTemplate,
|
||||
variables: {
|
||||
organizationSlug,
|
||||
data
|
||||
}
|
||||
});
|
||||
return result.data;
|
||||
});
|
||||
}
|
||||
addProject(organizationSlug, data) {
|
||||
return __async(this, null, function* () {
|
||||
const result = yield this.client.mutate({
|
||||
|
2
packages/gql-client/dist/index.js.map
vendored
2
packages/gql-client/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
47
packages/gql-client/dist/index.mjs
vendored
47
packages/gql-client/dist/index.mjs
vendored
@ -260,8 +260,14 @@ mutation ($projectId: String!, $data: [AddEnvironmentVariableInput!]) {
|
||||
}
|
||||
`;
|
||||
var updateEnvironmentVariable = gql2`
|
||||
mutation ($environmentVariableId: String!, $data: UpdateEnvironmentVariableInput!) {
|
||||
updateEnvironmentVariable(environmentVariableId: $environmentVariableId, data: $data)
|
||||
mutation (
|
||||
$environmentVariableId: String!
|
||||
$data: UpdateEnvironmentVariableInput!
|
||||
) {
|
||||
updateEnvironmentVariable(
|
||||
environmentVariableId: $environmentVariableId
|
||||
data: $data
|
||||
)
|
||||
}
|
||||
`;
|
||||
var removeEnvironmentVariable = gql2`
|
||||
@ -274,20 +280,30 @@ mutation ($deploymentId: String!) {
|
||||
updateDeploymentToProd(deploymentId: $deploymentId)
|
||||
}
|
||||
`;
|
||||
var addProjectFromTemplate = gql2`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput) {
|
||||
addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
var addProject = gql2`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectInput) {
|
||||
addProject(organizationSlug: $organizationSlug, data: $data) {
|
||||
id
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var updateProjectMutation = gql2`
|
||||
mutation ($projectId: String!, $data: UpdateProjectInput) {
|
||||
updateProject(projectId: $projectId, data: $data)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var updateDomainMutation = gql2`
|
||||
mutation ($domainId: String!, $data: UpdateDomainInput!) {
|
||||
updateDomain(domainId: $domainId, data: $data)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var redeployToProd = gql2`
|
||||
mutation ($deploymentId: String!) {
|
||||
redeployToProd(deploymentId: $deploymentId)
|
||||
@ -301,7 +317,8 @@ mutation ($projectId: String!) {
|
||||
var deleteDomain = gql2`
|
||||
mutation ($domainId: String!) {
|
||||
deleteDomain(domainId: $domainId)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var rollbackDeployment = gql2`
|
||||
mutation ($projectId: String!, $deploymentId: String!) {
|
||||
rollbackDeployment(projectId: $projectId, deploymentId: $deploymentId)
|
||||
@ -322,11 +339,13 @@ mutation ($code: String!) {
|
||||
authenticateGitHub(code: $code) {
|
||||
token
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
var unauthenticateGitHub = gql2`
|
||||
mutation {
|
||||
unauthenticateGitHub
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
// src/client.ts
|
||||
var defaultOptions = {
|
||||
@ -511,6 +530,18 @@ var GQLClient = class {
|
||||
return data;
|
||||
});
|
||||
}
|
||||
addProjectFromTemplate(organizationSlug, data) {
|
||||
return __async(this, null, function* () {
|
||||
const result = yield this.client.mutate({
|
||||
mutation: addProjectFromTemplate,
|
||||
variables: {
|
||||
organizationSlug,
|
||||
data
|
||||
}
|
||||
});
|
||||
return result.data;
|
||||
});
|
||||
}
|
||||
addProject(organizationSlug, data) {
|
||||
return __async(this, null, function* () {
|
||||
const result = yield this.client.mutate({
|
||||
|
2
packages/gql-client/dist/index.mjs.map
vendored
2
packages/gql-client/dist/index.mjs.map
vendored
File diff suppressed because one or more lines are too long
@ -228,6 +228,21 @@ export class GQLClient {
|
||||
return data;
|
||||
}
|
||||
|
||||
async addProjectFromTemplate(
|
||||
organizationSlug: string,
|
||||
data: types.AddProjectFromTemplateInput
|
||||
): Promise<types.AddProjectFromTemplateResponse> {
|
||||
const result = await this.client.mutate({
|
||||
mutation: mutations.addProjectFromTemplate,
|
||||
variables: {
|
||||
organizationSlug,
|
||||
data,
|
||||
},
|
||||
});
|
||||
|
||||
return result.data;
|
||||
}
|
||||
|
||||
async addProject(
|
||||
organizationSlug: string,
|
||||
data: types.AddProjectInput
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import { gql } from "@apollo/client";
|
||||
|
||||
export const removeProjectMember = gql`
|
||||
mutation ($projectMemberId: String!) {
|
||||
@ -25,8 +25,14 @@ mutation ($projectId: String!, $data: [AddEnvironmentVariableInput!]) {
|
||||
`;
|
||||
|
||||
export const updateEnvironmentVariable = gql`
|
||||
mutation ($environmentVariableId: String!, $data: UpdateEnvironmentVariableInput!) {
|
||||
updateEnvironmentVariable(environmentVariableId: $environmentVariableId, data: $data)
|
||||
mutation (
|
||||
$environmentVariableId: String!
|
||||
$data: UpdateEnvironmentVariableInput!
|
||||
) {
|
||||
updateEnvironmentVariable(
|
||||
environmentVariableId: $environmentVariableId
|
||||
data: $data
|
||||
)
|
||||
}
|
||||
`;
|
||||
|
||||
@ -42,22 +48,33 @@ mutation ($deploymentId: String!) {
|
||||
}
|
||||
`;
|
||||
|
||||
export const addProjectFromTemplate = gql`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput) {
|
||||
addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const addProject = gql`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectInput) {
|
||||
addProject(organizationSlug: $organizationSlug, data: $data) {
|
||||
id
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
export const updateProjectMutation = gql`
|
||||
mutation ($projectId: String!, $data: UpdateProjectInput) {
|
||||
updateProject(projectId: $projectId, data: $data)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
export const updateDomainMutation = gql`
|
||||
mutation ($domainId: String!, $data: UpdateDomainInput!) {
|
||||
updateDomain(domainId: $domainId, data: $data)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
export const redeployToProd = gql`
|
||||
mutation ($deploymentId: String!) {
|
||||
@ -74,7 +91,8 @@ mutation ($projectId: String!) {
|
||||
export const deleteDomain = gql`
|
||||
mutation ($domainId: String!) {
|
||||
deleteDomain(domainId: $domainId)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
export const rollbackDeployment = gql`
|
||||
mutation ($projectId: String!, $deploymentId: String!) {
|
||||
@ -99,9 +117,11 @@ mutation ($code: String!) {
|
||||
authenticateGitHub(code: $code) {
|
||||
token
|
||||
}
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
export const unauthenticateGitHub = gql`
|
||||
mutation {
|
||||
unauthenticateGitHub
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
@ -1,298 +1,311 @@
|
||||
import { addProjectFromTemplate } from "./mutations";
|
||||
// Note: equivalent to types present in GQL schema
|
||||
|
||||
export enum Role {
|
||||
Owner = 'Owner',
|
||||
Maintainer = 'Maintainer',
|
||||
Reader = 'Reader',
|
||||
Owner = "Owner",
|
||||
Maintainer = "Maintainer",
|
||||
Reader = "Reader",
|
||||
}
|
||||
|
||||
export enum Permission {
|
||||
View = 'View',
|
||||
Edit = 'Edit',
|
||||
View = "View",
|
||||
Edit = "Edit",
|
||||
}
|
||||
|
||||
export enum Environment {
|
||||
Production = 'Production',
|
||||
Preview = 'Preview',
|
||||
Development = 'Development',
|
||||
Production = "Production",
|
||||
Preview = "Preview",
|
||||
Development = "Development",
|
||||
}
|
||||
|
||||
export enum DeploymentStatus {
|
||||
Building = 'Building',
|
||||
Ready = 'Ready',
|
||||
Error = 'Error',
|
||||
Deleting = 'Deleting'
|
||||
Building = "Building",
|
||||
Ready = "Ready",
|
||||
Error = "Error",
|
||||
Deleting = "Deleting",
|
||||
}
|
||||
|
||||
export enum DomainStatus {
|
||||
Live = 'Live',
|
||||
Pending = 'Pending',
|
||||
Live = "Live",
|
||||
Pending = "Pending",
|
||||
}
|
||||
|
||||
export type EnvironmentVariable = {
|
||||
id: string
|
||||
environment: Environment
|
||||
key: string
|
||||
value: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
id: string;
|
||||
environment: Environment;
|
||||
key: string;
|
||||
value: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type Domain = {
|
||||
id: string
|
||||
branch: string
|
||||
name: string
|
||||
status: DomainStatus
|
||||
redirectTo: Domain | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
id: string;
|
||||
branch: string;
|
||||
name: string;
|
||||
status: DomainStatus;
|
||||
redirectTo: Domain | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type User = {
|
||||
id: string
|
||||
name: string | null
|
||||
email: string
|
||||
isVerified: boolean
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
gitHubToken: string | null
|
||||
}
|
||||
id: string;
|
||||
name: string | null;
|
||||
email: string;
|
||||
isVerified: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
gitHubToken: string | null;
|
||||
};
|
||||
|
||||
export type Deployment = {
|
||||
id: string
|
||||
domain: Domain
|
||||
branch: string
|
||||
commitHash: string
|
||||
commitMessage: string
|
||||
url?: string
|
||||
environment: Environment
|
||||
isCurrent: boolean
|
||||
status: DeploymentStatus
|
||||
createdBy: User
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
id: string;
|
||||
domain: Domain;
|
||||
branch: string;
|
||||
commitHash: string;
|
||||
commitMessage: string;
|
||||
url?: string;
|
||||
environment: Environment;
|
||||
isCurrent: boolean;
|
||||
status: DeploymentStatus;
|
||||
createdBy: User;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type OrganizationMember = {
|
||||
id: string
|
||||
member: User
|
||||
role: Role
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
id: string;
|
||||
member: User;
|
||||
role: Role;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type ProjectMember = {
|
||||
id: string
|
||||
member: User
|
||||
permissions: Permission[]
|
||||
isPending: boolean
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
id: string;
|
||||
member: User;
|
||||
permissions: Permission[];
|
||||
isPending: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type OrganizationProject = {
|
||||
id: string
|
||||
owner: User
|
||||
deployments: Deployment[]
|
||||
name: string
|
||||
repository: string
|
||||
prodBranch: string
|
||||
description: string
|
||||
template: string
|
||||
framework: string
|
||||
webhooks: string[]
|
||||
members: ProjectMember[]
|
||||
environmentVariables: EnvironmentVariable[]
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
id: string;
|
||||
owner: User;
|
||||
deployments: Deployment[];
|
||||
name: string;
|
||||
repository: string;
|
||||
prodBranch: string;
|
||||
description: string;
|
||||
template: string;
|
||||
framework: string;
|
||||
webhooks: string[];
|
||||
members: ProjectMember[];
|
||||
environmentVariables: EnvironmentVariable[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type Organization = {
|
||||
id: string
|
||||
name: string
|
||||
slug: string
|
||||
projects: OrganizationProject[]
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
members: OrganizationMember[]
|
||||
}
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
projects: OrganizationProject[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
members: OrganizationMember[];
|
||||
};
|
||||
|
||||
export type Project = {
|
||||
id: string
|
||||
owner: User
|
||||
deployments: Deployment[]
|
||||
name: string
|
||||
repository: string
|
||||
prodBranch: string
|
||||
description: string
|
||||
template: string
|
||||
framework: string
|
||||
webhooks: string[]
|
||||
members: ProjectMember[]
|
||||
environmentVariables: EnvironmentVariable[]
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
organization: Organization
|
||||
icon: string
|
||||
subDomain: string
|
||||
}
|
||||
id: string;
|
||||
owner: User;
|
||||
deployments: Deployment[];
|
||||
name: string;
|
||||
repository: string;
|
||||
prodBranch: string;
|
||||
description: string;
|
||||
template: string;
|
||||
framework: string;
|
||||
webhooks: string[];
|
||||
members: ProjectMember[];
|
||||
environmentVariables: EnvironmentVariable[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
organization: Organization;
|
||||
icon: string;
|
||||
subDomain: string;
|
||||
};
|
||||
|
||||
export type GetProjectMembersResponse = {
|
||||
projectMembers: ProjectMember[]
|
||||
}
|
||||
projectMembers: ProjectMember[];
|
||||
};
|
||||
|
||||
export type AddProjectMemberResponse = {
|
||||
addProjectMember: boolean
|
||||
}
|
||||
addProjectMember: boolean;
|
||||
};
|
||||
|
||||
export type RemoveProjectMemberResponse = {
|
||||
removeProjectMember: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type UpdateProjectMemberResponse = {
|
||||
updateProjectMember: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type GetDeploymentsResponse = {
|
||||
deployments: Deployment[]
|
||||
}
|
||||
deployments: Deployment[];
|
||||
};
|
||||
|
||||
export type GetEnvironmentVariablesResponse = {
|
||||
environmentVariables: EnvironmentVariable[]
|
||||
}
|
||||
environmentVariables: EnvironmentVariable[];
|
||||
};
|
||||
|
||||
export type GetOrganizationsResponse = {
|
||||
organizations: Organization[]
|
||||
}
|
||||
organizations: Organization[];
|
||||
};
|
||||
|
||||
export type GetUserResponse = {
|
||||
user: User
|
||||
}
|
||||
user: User;
|
||||
};
|
||||
|
||||
export type GetProjectResponse = {
|
||||
project: Project | null
|
||||
}
|
||||
project: Project | null;
|
||||
};
|
||||
|
||||
export type GetProjectsInOrganizationResponse = {
|
||||
projectsInOrganization: Project[]
|
||||
}
|
||||
projectsInOrganization: Project[];
|
||||
};
|
||||
|
||||
export type GetDomainsResponse = {
|
||||
domains: Domain[]
|
||||
}
|
||||
domains: Domain[];
|
||||
};
|
||||
|
||||
export type SearchProjectsResponse = {
|
||||
searchProjects: Project[]
|
||||
}
|
||||
searchProjects: Project[];
|
||||
};
|
||||
|
||||
export type AddEnvironmentVariablesResponse = {
|
||||
addEnvironmentVariables: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type AddEnvironmentVariableInput = {
|
||||
environments: string[];
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
};
|
||||
|
||||
export type UpdateEnvironmentVariableInput = {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
};
|
||||
|
||||
export type UpdateProjectMemberInput = {
|
||||
permissions: Permission[];
|
||||
}
|
||||
};
|
||||
|
||||
export type AddProjectMemberInput = {
|
||||
email: string;
|
||||
permissions: Permission[]
|
||||
}
|
||||
permissions: Permission[];
|
||||
};
|
||||
|
||||
export type UpdateEnvironmentVariableResponse = {
|
||||
updateEnvironmentVariable: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type RemoveEnvironmentVariableResponse = {
|
||||
removeEnvironmentVariable: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type UpdateDeploymentToProdResponse = {
|
||||
updateDeploymentToProd: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type AddProjectFromTemplateResponse = {
|
||||
addProjectFromTemplate: Project;
|
||||
};
|
||||
|
||||
export type AddProjectResponse = {
|
||||
addProject: Project
|
||||
}
|
||||
addProject: Project;
|
||||
};
|
||||
|
||||
export type UpdateProjectResponse = {
|
||||
updateProject: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type UpdateDomainResponse = {
|
||||
updateDomain: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type DeleteProjectResponse = {
|
||||
deleteProject: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type DeleteDomainResponse = {
|
||||
deleteDomain: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export type AddProjectFromTemplateInput = {
|
||||
templateOwner: string;
|
||||
templateRepo: string;
|
||||
owner: string;
|
||||
name: string;
|
||||
isPrivate: boolean;
|
||||
};
|
||||
|
||||
export type AddProjectInput = {
|
||||
name: string;
|
||||
repository: string;
|
||||
prodBranch: string;
|
||||
template?: string;
|
||||
}
|
||||
};
|
||||
|
||||
export type UpdateProjectInput = {
|
||||
name?: string
|
||||
description?: string
|
||||
prodBranch?: string
|
||||
webhooks?: string[]
|
||||
organizationId?: string
|
||||
}
|
||||
name?: string;
|
||||
description?: string;
|
||||
prodBranch?: string;
|
||||
webhooks?: string[];
|
||||
organizationId?: string;
|
||||
};
|
||||
|
||||
export type UpdateDomainInput = {
|
||||
name?: string;
|
||||
branch?: string;
|
||||
redirectToId?: string | null;
|
||||
}
|
||||
};
|
||||
|
||||
export type RedeployToProdResponse = {
|
||||
redeployToProd: boolean
|
||||
}
|
||||
redeployToProd: boolean;
|
||||
};
|
||||
|
||||
export type RollbackDeploymentResponse = {
|
||||
rollbackDeployment: boolean
|
||||
}
|
||||
rollbackDeployment: boolean;
|
||||
};
|
||||
|
||||
export type DeleteDeploymentResponse = {
|
||||
deleteDeployment: boolean
|
||||
}
|
||||
deleteDeployment: boolean;
|
||||
};
|
||||
|
||||
export type AddDomainInput = {
|
||||
name: string
|
||||
}
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type FilterDomainInput = {
|
||||
branch?: string
|
||||
status?: DomainStatus
|
||||
}
|
||||
branch?: string;
|
||||
status?: DomainStatus;
|
||||
};
|
||||
|
||||
export type AddDomainResponse = {
|
||||
addDomain: true
|
||||
}
|
||||
addDomain: true;
|
||||
};
|
||||
|
||||
export type AuthenticateGitHubResponse = {
|
||||
authenticateGitHub: {
|
||||
token: string
|
||||
}
|
||||
}
|
||||
token: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type UnauthenticateGitHubResponse = {
|
||||
unauthenticateGitHub: boolean
|
||||
}
|
||||
unauthenticateGitHub: boolean;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user