forked from cerc-io/snowballtools-base
Show public repo GitHub activity without authentication (#68)
* Handle request error while fetching Git activity * Use default Octokit instance if auth token is not available * Rename input arguments of mutation methods to data --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
@@ -236,9 +236,9 @@ export class Database {
|
||||
return savedEnvironmentVariables;
|
||||
}
|
||||
|
||||
async updateEnvironmentVariable (environmentVariableId: string, update: DeepPartial<EnvironmentVariable>): Promise<boolean> {
|
||||
async updateEnvironmentVariable (environmentVariableId: string, data: DeepPartial<EnvironmentVariable>): Promise<boolean> {
|
||||
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
||||
const updateResult = await environmentVariableRepository.update({ id: environmentVariableId }, update);
|
||||
const updateResult = await environmentVariableRepository.update({ id: environmentVariableId }, data);
|
||||
|
||||
return Boolean(updateResult.affected);
|
||||
}
|
||||
@@ -293,18 +293,18 @@ export class Database {
|
||||
return projects;
|
||||
}
|
||||
|
||||
async updateDeploymentById (deploymentId: string, updates: DeepPartial<Deployment>): Promise<boolean> {
|
||||
async updateDeploymentById (deploymentId: string, data: DeepPartial<Deployment>): Promise<boolean> {
|
||||
const deploymentRepository = this.dataSource.getRepository(Deployment);
|
||||
const updateResult = await deploymentRepository.update({ id: deploymentId }, updates);
|
||||
const updateResult = await deploymentRepository.update({ id: deploymentId }, data);
|
||||
|
||||
return Boolean(updateResult.affected);
|
||||
}
|
||||
|
||||
async addProject (userId: string, organizationId: string, projectDetails: DeepPartial<Project>): Promise<Project> {
|
||||
async addProject (userId: string, organizationId: string, data: DeepPartial<Project>): Promise<Project> {
|
||||
const projectRepository = this.dataSource.getRepository(Project);
|
||||
|
||||
// TODO: Check if organization exists
|
||||
const newProject = projectRepository.create(projectDetails);
|
||||
const newProject = projectRepository.create(data);
|
||||
// TODO: Set default empty array for webhooks in TypeORM
|
||||
newProject.webhooks = [];
|
||||
// TODO: Set icon according to framework
|
||||
@@ -323,9 +323,9 @@ export class Database {
|
||||
return projectRepository.save(newProject);
|
||||
}
|
||||
|
||||
async updateProjectById (projectId: string, updates: DeepPartial<Project>): Promise<boolean> {
|
||||
async updateProjectById (projectId: string, data: DeepPartial<Project>): Promise<boolean> {
|
||||
const projectRepository = this.dataSource.getRepository(Project);
|
||||
const updateResult = await projectRepository.update({ id: projectId }, updates);
|
||||
const updateResult = await projectRepository.update({ id: projectId }, data);
|
||||
|
||||
return Boolean(updateResult.affected);
|
||||
}
|
||||
@@ -372,9 +372,9 @@ export class Database {
|
||||
return domain;
|
||||
}
|
||||
|
||||
async updateDomainById (domainId: string, updates: DeepPartial<Domain>): Promise<boolean> {
|
||||
async updateDomainById (domainId: string, data: DeepPartial<Domain>): Promise<boolean> {
|
||||
const domainRepository = this.dataSource.getRepository(Domain);
|
||||
const updateResult = await domainRepository.update({ id: domainId }, updates);
|
||||
const updateResult = await domainRepository.update({ id: domainId }, data);
|
||||
|
||||
return Boolean(updateResult.affected);
|
||||
}
|
||||
|
||||
@@ -135,9 +135,9 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
}
|
||||
},
|
||||
|
||||
updateProject: async (_: any, { projectId, projectDetails }: { projectId: string, projectDetails: DeepPartial<Project> }) => {
|
||||
updateProject: async (_: any, { projectId, data }: { projectId: string, data: DeepPartial<Project> }) => {
|
||||
try {
|
||||
return await service.updateProject(projectId, projectDetails);
|
||||
return await service.updateProject(projectId, data);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
@@ -179,18 +179,18 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
}
|
||||
},
|
||||
|
||||
addDomain: async (_: any, { projectId, domainDetails }: { projectId: string, domainDetails: { name: string } }) => {
|
||||
addDomain: async (_: any, { projectId, data }: { projectId: string, data: { name: string } }) => {
|
||||
try {
|
||||
return Boolean(await service.addDomain(projectId, domainDetails));
|
||||
return Boolean(await service.addDomain(projectId, data));
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
updateDomain: async (_: any, { domainId, domainDetails }: { domainId: string, domainDetails: DeepPartial<Domain>}) => {
|
||||
updateDomain: async (_: any, { domainId, data }: { domainId: string, data: DeepPartial<Domain>}) => {
|
||||
try {
|
||||
return await service.updateDomain(domainId, domainDetails);
|
||||
return await service.updateDomain(domainId, data);
|
||||
} catch (err) {
|
||||
log(err);
|
||||
return false;
|
||||
|
||||
@@ -195,13 +195,13 @@ type Mutation {
|
||||
removeEnvironmentVariable(environmentVariableId: String!): Boolean!
|
||||
updateDeploymentToProd(deploymentId: String!): Boolean!
|
||||
addProject(organizationSlug: String!, data: AddProjectInput): Project!
|
||||
updateProject(projectId: String!, projectDetails: UpdateProjectInput): Boolean!
|
||||
updateProject(projectId: String!, data: UpdateProjectInput): Boolean!
|
||||
redeployToProd(deploymentId: String!): Boolean!
|
||||
deleteProject(projectId: String!): Boolean!
|
||||
deleteDomain(domainId: String!): Boolean!
|
||||
rollbackDeployment(projectId: String!, deploymentId: String!): Boolean!
|
||||
addDomain(projectId: String!, domainDetails: AddDomainInput!): Boolean!
|
||||
updateDomain(domainId: String!, domainDetails: UpdateDomainInput!): Boolean!
|
||||
addDomain(projectId: String!, data: AddDomainInput!): Boolean!
|
||||
updateDomain(domainId: String!, data: UpdateDomainInput!): Boolean!
|
||||
authenticateGitHub(code: String!): AuthResult!
|
||||
unauthenticateGitHub: Boolean!
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ export class Service {
|
||||
return newCurrentDeploymentUpdate && oldCurrentDeploymentUpdate;
|
||||
}
|
||||
|
||||
async addDomain (projectId: string, domainDetails: { name: string }): Promise<{
|
||||
async addDomain (projectId: string, data: { name: string }): Promise<{
|
||||
primaryDomain: Domain,
|
||||
redirectedDomain: Domain
|
||||
}> {
|
||||
@@ -416,14 +416,14 @@ export class Service {
|
||||
}
|
||||
|
||||
const primaryDomainDetails = {
|
||||
...domainDetails,
|
||||
...data,
|
||||
branch: currentProject.prodBranch,
|
||||
project: currentProject
|
||||
};
|
||||
|
||||
const savedPrimaryDomain = await this.db.addDomain(primaryDomainDetails);
|
||||
|
||||
const domainArr = domainDetails.name.split('www.');
|
||||
const domainArr = data.name.split('www.');
|
||||
|
||||
const redirectedDomainDetails = {
|
||||
name: domainArr.length > 1 ? domainArr[1] : `www.${domainArr[0]}`,
|
||||
@@ -437,7 +437,7 @@ export class Service {
|
||||
return { primaryDomain: savedPrimaryDomain, redirectedDomain: savedRedirectedDomain };
|
||||
}
|
||||
|
||||
async updateDomain (domainId: string, domainDetails: DeepPartial<Domain>): Promise<boolean> {
|
||||
async updateDomain (domainId: string, data: DeepPartial<Domain>): Promise<boolean> {
|
||||
const domain = await this.db.getDomain({
|
||||
where: {
|
||||
id: domainId
|
||||
@@ -449,7 +449,7 @@ export class Service {
|
||||
}
|
||||
|
||||
const newDomain = {
|
||||
...domainDetails
|
||||
...data
|
||||
};
|
||||
|
||||
const domainsRedirectedFrom = await this.db.getDomains({
|
||||
@@ -462,14 +462,14 @@ export class Service {
|
||||
});
|
||||
|
||||
// If there are domains redirecting to current domain, only branch of current domain can be updated
|
||||
if (domainsRedirectedFrom.length > 0 && domainDetails.branch === domain.branch) {
|
||||
if (domainsRedirectedFrom.length > 0 && data.branch === domain.branch) {
|
||||
throw new Error('Remove all redirects to this domain before updating');
|
||||
}
|
||||
|
||||
if (domainDetails.redirectToId) {
|
||||
if (data.redirectToId) {
|
||||
const redirectedDomain = await this.db.getDomain({
|
||||
where: {
|
||||
id: domainDetails.redirectToId
|
||||
id: data.redirectToId
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user