Pass env variables when creating project
This commit is contained in:
parent
b38bab5ddd
commit
1bd28e0309
@ -211,8 +211,15 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
organizationSlug,
|
||||
data,
|
||||
lrn,
|
||||
auctionParams
|
||||
}: { organizationSlug: string; data: AddProjectFromTemplateInput; lrn: string; auctionParams: AuctionParams },
|
||||
auctionParams,
|
||||
environmentVariables
|
||||
}: {
|
||||
organizationSlug: string;
|
||||
data: AddProjectFromTemplateInput;
|
||||
lrn: string;
|
||||
auctionParams: AuctionParams,
|
||||
environmentVariables: { environments: string[]; key: string; value: string }[];
|
||||
},
|
||||
context: any,
|
||||
) => {
|
||||
try {
|
||||
@ -221,7 +228,8 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
organizationSlug,
|
||||
data,
|
||||
lrn,
|
||||
auctionParams
|
||||
auctionParams,
|
||||
environmentVariables
|
||||
);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
@ -235,12 +243,26 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
organizationSlug,
|
||||
data,
|
||||
lrn,
|
||||
auctionParams
|
||||
}: { organizationSlug: string; data: DeepPartial<Project>; lrn: string; auctionParams: AuctionParams },
|
||||
auctionParams,
|
||||
environmentVariables
|
||||
}: {
|
||||
organizationSlug: string;
|
||||
data: DeepPartial<Project>;
|
||||
lrn: string;
|
||||
auctionParams: AuctionParams,
|
||||
environmentVariables: { environments: string[]; key: string; value: string }[];
|
||||
},
|
||||
context: any,
|
||||
) => {
|
||||
try {
|
||||
return await service.addProject(context.user, organizationSlug, data, lrn, auctionParams);
|
||||
return await service.addProject(
|
||||
context.user,
|
||||
organizationSlug,
|
||||
data,
|
||||
lrn,
|
||||
auctionParams,
|
||||
environmentVariables
|
||||
);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
throw err;
|
||||
|
@ -271,12 +271,14 @@ type Mutation {
|
||||
data: AddProjectFromTemplateInput
|
||||
lrn: String
|
||||
auctionParams: AuctionParams
|
||||
environmentVariables: [AddEnvironmentVariableInput!]
|
||||
): Project!
|
||||
addProject(
|
||||
organizationSlug: String!
|
||||
data: AddProjectInput!
|
||||
lrn: String
|
||||
auctionParams: AuctionParams
|
||||
environmentVariables: [AddEnvironmentVariableInput!]
|
||||
): Project!
|
||||
updateProject(projectId: String!, data: UpdateProjectInput): Boolean!
|
||||
redeployToProd(deploymentId: String!): Boolean!
|
||||
|
@ -784,7 +784,8 @@ export class Service {
|
||||
organizationSlug: string,
|
||||
data: AddProjectFromTemplateInput,
|
||||
lrn?: string,
|
||||
auctionParams?: AuctionParams
|
||||
auctionParams?: AuctionParams,
|
||||
environmentVariables?: { environments: string[]; key: string; value: string }[],
|
||||
): Promise<Project | undefined> {
|
||||
try {
|
||||
const octokit = await this.getOctokit(user.id);
|
||||
@ -815,7 +816,7 @@ export class Service {
|
||||
repository: gitRepo.data.full_name,
|
||||
// TODO: Set selected template
|
||||
template: 'webapp',
|
||||
}, lrn, auctionParams);
|
||||
}, lrn, auctionParams, environmentVariables);
|
||||
|
||||
if (!project || !project.id) {
|
||||
throw new Error('Failed to create project from template');
|
||||
@ -833,7 +834,8 @@ export class Service {
|
||||
organizationSlug: string,
|
||||
data: DeepPartial<Project>,
|
||||
lrn?: string,
|
||||
auctionParams?: AuctionParams
|
||||
auctionParams?: AuctionParams,
|
||||
environmentVariables?: { environments: string[]; key: string; value: string }[],
|
||||
): Promise<Project | undefined> {
|
||||
const organization = await this.db.getOrganization({
|
||||
where: {
|
||||
@ -844,8 +846,11 @@ export class Service {
|
||||
throw new Error('Organization does not exist');
|
||||
}
|
||||
|
||||
const project = await this.db.addProject(user, organization.id, data);
|
||||
log(`Project created ${project.id}`);
|
||||
const project = await this.db.addProject(user, organization.id, data);4
|
||||
|
||||
if(environmentVariables) {
|
||||
await this.addEnvironmentVariables(project.id, environmentVariables);
|
||||
}
|
||||
|
||||
const octokit = await this.getOctokit(user.id);
|
||||
const [owner, repo] = project.repository.split('/');
|
||||
|
@ -3,7 +3,7 @@ import { useForm, Controller } from 'react-hook-form';
|
||||
import { FormProvider, FieldValues } from 'react-hook-form';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { useMediaQuery } from 'usehooks-ts';
|
||||
import { AuctionParams } from 'gql-client';
|
||||
import { AddEnvironmentVariableInput, AuctionParams } from 'gql-client';
|
||||
|
||||
import {
|
||||
ArrowRightCircleFilledIcon,
|
||||
@ -55,7 +55,7 @@ const Configure = () => {
|
||||
const isTabletView = useMediaQuery('(min-width: 720px)'); // md:
|
||||
const buttonSize = isTabletView ? { size: 'lg' as const } : {};
|
||||
|
||||
const createProject = async (data: FieldValues): Promise<string> => {
|
||||
const createProject = async (data: FieldValues, envVariables: AddEnvironmentVariableInput[]): Promise<string> => {
|
||||
setIsLoading(true);
|
||||
let projectId: string | null = null;
|
||||
|
||||
@ -81,13 +81,15 @@ const Configure = () => {
|
||||
isPrivate,
|
||||
};
|
||||
|
||||
const { addProjectFromTemplate } = await client.addProjectFromTemplate(
|
||||
orgSlug!,
|
||||
projectData,
|
||||
lrn,
|
||||
auctionParams
|
||||
);
|
||||
projectId = addProjectFromTemplate.id;
|
||||
const { addProjectFromTemplate } = await client.addProjectFromTemplate(
|
||||
orgSlug!,
|
||||
projectData,
|
||||
lrn,
|
||||
auctionParams,
|
||||
envVariables
|
||||
);
|
||||
|
||||
projectId = addProjectFromTemplate.id;
|
||||
} else {
|
||||
const { addProject } = await client.addProject(
|
||||
orgSlug!,
|
||||
@ -98,7 +100,8 @@ const Configure = () => {
|
||||
template: 'webapp',
|
||||
},
|
||||
lrn,
|
||||
auctionParams
|
||||
auctionParams,
|
||||
envVariables
|
||||
);
|
||||
|
||||
projectId = addProject.id;
|
||||
@ -134,12 +137,12 @@ const Configure = () => {
|
||||
};
|
||||
});
|
||||
|
||||
const projectId = await createProject(createFormData);
|
||||
const projectId = await createProject(createFormData, environmentVariables);
|
||||
|
||||
const { addEnvironmentVariables: isEnvironmentVariablesAdded } =
|
||||
await client.addEnvironmentVariables(projectId, environmentVariables);
|
||||
const { environmentVariables: isEnvironmentVariablesAdded } =
|
||||
await client.getEnvironmentVariables(projectId);
|
||||
|
||||
if (isEnvironmentVariablesAdded) {
|
||||
if (isEnvironmentVariablesAdded.length > 0) {
|
||||
toast({
|
||||
id:
|
||||
createFormData.variables.length > 1
|
||||
|
@ -233,6 +233,7 @@ export class GQLClient {
|
||||
data: types.AddProjectFromTemplateInput,
|
||||
lrn?: string,
|
||||
auctionParams?: types.AuctionParams,
|
||||
environmentVariables?: types.AddEnvironmentVariableInput[]
|
||||
): Promise<types.AddProjectFromTemplateResponse> {
|
||||
const result = await this.client.mutate({
|
||||
mutation: mutations.addProjectFromTemplate,
|
||||
@ -240,7 +241,8 @@ export class GQLClient {
|
||||
organizationSlug,
|
||||
data,
|
||||
lrn,
|
||||
auctionParams
|
||||
auctionParams,
|
||||
environmentVariables
|
||||
},
|
||||
});
|
||||
|
||||
@ -252,6 +254,7 @@ export class GQLClient {
|
||||
data: types.AddProjectInput,
|
||||
lrn?: string,
|
||||
auctionParams?: types.AuctionParams,
|
||||
environmentVariables?: types.AddEnvironmentVariableInput[]
|
||||
): Promise<types.AddProjectResponse> {
|
||||
const result = await this.client.mutate({
|
||||
mutation: mutations.addProject,
|
||||
@ -259,7 +262,8 @@ export class GQLClient {
|
||||
organizationSlug,
|
||||
data,
|
||||
lrn,
|
||||
auctionParams
|
||||
auctionParams,
|
||||
environmentVariables
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -49,16 +49,16 @@ export const updateDeploymentToProd = gql`
|
||||
`;
|
||||
|
||||
export const addProjectFromTemplate = gql`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput, $lrn: String, $auctionParams: AuctionParams) {
|
||||
addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams) {
|
||||
mutation ($organizationSlug: String!, $data: AddProjectFromTemplateInput, $lrn: String, $auctionParams: AuctionParams, $environmentVariables: [AddEnvironmentVariableInput!]) {
|
||||
addProjectFromTemplate(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams, environmentVariables: $environmentVariables) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const addProject = gql`
|
||||
mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionParams: AuctionParams) {
|
||||
addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams) {
|
||||
mutation ($organizationSlug: String!, $data: AddProjectInput!, $lrn: String, $auctionParams: AuctionParams, $environmentVariables: [AddEnvironmentVariableInput!]) {
|
||||
addProject(organizationSlug: $organizationSlug, data: $data, lrn: $lrn, auctionParams: $auctionParams, environmentVariables: $environmentVariables) {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user