Fix deployments visit URL and date filter (#78)

* Add method to update multiple deployments in single query

* Fix deployments URL visit and date filter

* Clean fixtures data

* Update fixtures data

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
Nabarun Gogoi 2024-02-20 10:53:42 +05:30 committed by GitHub
parent c3d1b4f3eb
commit a45fb4c617
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 45 additions and 247 deletions

View File

@ -316,6 +316,19 @@ export class Database {
return Boolean(updateResult.affected); return Boolean(updateResult.affected);
} }
async updateDeploymentsByProjectIds (projectIds: string[], data: DeepPartial<Deployment>): Promise<boolean> {
const deploymentRepository = this.dataSource.getRepository(Deployment);
const updateResult = await deploymentRepository
.createQueryBuilder()
.update(Deployment)
.set(data)
.where('projectId IN (:...projectIds)', { projectIds })
.execute();
return Boolean(updateResult.affected);
}
async addProject (userId: string, organizationId: string, data: DeepPartial<Project>): Promise<Project> { async addProject (userId: string, organizationId: string, data: DeepPartial<Project>): Promise<Project> {
const projectRepository = this.dataSource.getRepository(Project); const projectRepository = this.dataSource.getRepository(Project);

View File

@ -78,8 +78,10 @@ export class Service {
log(`Found ${records.length} ApplicationDeploymentRecords`); log(`Found ${records.length} ApplicationDeploymentRecords`);
// Update deployments for which ApplicationDeploymentRecords were returned // Update deployments for which ApplicationDeploymentRecords were returned
if (records.length) {
await this.updateDeploymentsWithRecordData(records); await this.updateDeploymentsWithRecordData(records);
} }
}
this.deployRecordCheckTimeout = setTimeout(() => { this.deployRecordCheckTimeout = setTimeout(() => {
this.checkDeployRecordsAndUpdate(); this.checkDeployRecordsAndUpdate();
@ -110,10 +112,7 @@ export class Service {
}, new Set<string>()); }, new Set<string>());
// Set old deployments isCurrent to false // Set old deployments isCurrent to false
await Promise.all(Array.from(productionDeploymentProjectIds).map( await this.db.updateDeploymentsByProjectIds(Array.from(productionDeploymentProjectIds), { isCurrent: false });
// TODO: Add DB method to update multiple deployments in single query
async (projectId) => this.db.updateDeployment({ projectId }, { isCurrent: false })
));
const recordToDeploymentsMap = deployments.reduce((acc: {[key: string]: Deployment}, deployment) => { const recordToDeploymentsMap = deployments.reduce((acc: {[key: string]: Deployment}, deployment) => {
acc[deployment.applicationRecordId] = deployment; acc[deployment.applicationRecordId] = deployment;
@ -135,7 +134,7 @@ export class Service {
} }
); );
log(`Updated deployment deployment ${deployment.id} with URL ${record.attributes.url}`); log(`Updated deployment ${deployment.id} with URL ${record.attributes.url}`);
}); });
await Promise.all(deploymentUpdatePromises); await Promise.all(deploymentUpdatePromises);
@ -295,7 +294,6 @@ export class Service {
octokit, octokit,
{ {
project: oldDeployment.project, project: oldDeployment.project,
isCurrent: true,
branch: oldDeployment.branch, branch: oldDeployment.branch,
environment: Environment.Production, environment: Environment.Production,
domain: prodBranchDomains[0], domain: prodBranchDomains[0],
@ -357,7 +355,6 @@ export class Service {
commitHash: data.commitHash, commitHash: data.commitHash,
commitMessage: data.commitMessage, commitMessage: data.commitMessage,
environment: data.environment, environment: data.environment,
isCurrent: data.isCurrent,
status: DeploymentStatus.Building, status: DeploymentStatus.Building,
applicationRecordId, applicationRecordId,
applicationRecordData, applicationRecordData,
@ -400,7 +397,6 @@ export class Service {
octokit, octokit,
{ {
project, project,
isCurrent: true,
branch: project.prodBranch, branch: project.prodBranch,
environment: Environment.Production, environment: Environment.Production,
domain: null, domain: null,
@ -486,7 +482,6 @@ export class Service {
octokit, octokit,
{ {
project, project,
isCurrent: project.prodBranch === branch,
branch, branch,
environment: project.prodBranch === branch ? Environment.Production : Environment.Preview, environment: project.prodBranch === branch ? Environment.Production : Environment.Preview,
domain, domain,
@ -543,7 +538,6 @@ export class Service {
project: oldDeployment.project, project: oldDeployment.project,
// TODO: Put isCurrent field in project // TODO: Put isCurrent field in project
branch: oldDeployment.branch, branch: oldDeployment.branch,
isCurrent: true,
environment: Environment.Production, environment: Environment.Production,
domain: oldDeployment.domain, domain: oldDeployment.domain,
commitHash: oldDeployment.commitHash, commitHash: oldDeployment.commitHash,

View File

@ -6,7 +6,7 @@
}, },
{ {
"id": "7eb9b3eb-eb74-4b53-b59a-69884c82a7fb", "id": "7eb9b3eb-eb74-4b53-b59a-69884c82a7fb",
"name": "AirFoil", "name": "Laconic",
"slug": "airfoil-2" "slug": "laconic-2"
} }
] ]

View File

@ -1,37 +1,37 @@
[ [
{ {
"projectIndex": 0, "projectIndex": 0,
"name": "randomurl.snowballtools.xyz", "name": "example.snowballtools.xyz",
"status": "Live", "status": "Live",
"branch": "main" "branch": "main"
}, },
{ {
"projectIndex": 0, "projectIndex": 0,
"name": "saugatt.com", "name": "example.org",
"status": "Pending", "status": "Pending",
"branch": "test" "branch": "test"
}, },
{ {
"projectIndex": 1, "projectIndex": 1,
"name": "randomurl.snowballtools.xyz", "name": "example.snowballtools.xyz",
"status": "Live", "status": "Live",
"branch": "main" "branch": "main"
}, },
{ {
"projectIndex": 1, "projectIndex": 1,
"name": "saugatt.com", "name": "example.org",
"status": "Pending", "status": "Pending",
"branch": "test" "branch": "test"
}, },
{ {
"projectIndex": 2, "projectIndex": 2,
"name": "randomurl.snowballtools.xyz", "name": "example.snowballtools.xyz",
"status": "Live", "status": "Live",
"branch": "main" "branch": "main"
}, },
{ {
"projectIndex": 2, "projectIndex": 2,
"name": "saugatt.com", "name": "example.org",
"status": "Pending", "status": "Pending",
"branch": "test" "branch": "test"
}, },

View File

@ -1,21 +1,21 @@
[ [
{ {
"projectIndex": 0, "projectIndex": 0,
"name": "www.saugatt.com", "name": "www.example.org",
"status": "Pending", "status": "Pending",
"redirectToIndex": 1, "redirectToIndex": 1,
"branch": "test" "branch": "test"
}, },
{ {
"projectIndex": 1, "projectIndex": 1,
"name": "www.saugatt.com", "name": "www.example.org",
"status": "Pending", "status": "Pending",
"redirectToIndex": 3, "redirectToIndex": 3,
"branch": "test" "branch": "test"
}, },
{ {
"projectIndex": 2, "projectIndex": 2,
"name": "www.saugatt.com", "name": "www.example.org",
"status": "Pending", "status": "Pending",
"redirectToIndex": 5, "redirectToIndex": 5,
"branch": "test" "branch": "test"

View File

@ -1,20 +1,20 @@
[ [
{ {
"id": "59f4355d-9549-4aac-9b54-eeefceeabef0", "id": "59f4355d-9549-4aac-9b54-eeefceeabef0",
"name": "Saugat Yadav", "name": "Snowball",
"email": "saugaty@airfoil.studio", "email": "snowball@snowballtools.xyz",
"isVerified": true "isVerified": true
}, },
{ {
"id": "e505b212-8da6-48b2-9614-098225dab34b", "id": "e505b212-8da6-48b2-9614-098225dab34b",
"name": "Gideon Low", "name": "Alice Anderson",
"email": "gideonl@airfoil.studio", "email": "alice@snowballtools.xyz",
"isVerified": true "isVerified": true
}, },
{ {
"id": "cd892fad-9138-4aa2-a62c-414a32776ea7", "id": "cd892fad-9138-4aa2-a62c-414a32776ea7",
"name": "Sushan Yadav", "name": "Bob Banner",
"email": "sushany@airfoil.studio", "email": "bob@snowballtools.xyz",
"isVerified": true "isVerified": true
} }
] ]

View File

@ -20,7 +20,7 @@ const log = debug('snowball:initialize-database');
const USER_DATA_PATH = './fixtures/users.json'; const USER_DATA_PATH = './fixtures/users.json';
const PROJECT_DATA_PATH = './fixtures/projects.json'; const PROJECT_DATA_PATH = './fixtures/projects.json';
const ORGANIZATION_DATA_PATH = './fixtures/organizations.json'; const ORGANIZATION_DATA_PATH = './fixtures/organizations.json';
const USER_ORGANIZATION_DATA_PATH = './fixtures/user-orgnizations.json'; const USER_ORGANIZATION_DATA_PATH = './fixtures/user-organizations.json';
const PROJECT_MEMBER_DATA_PATH = './fixtures/project-members.json'; const PROJECT_MEMBER_DATA_PATH = './fixtures/project-members.json';
const PRIMARY_DOMAIN_DATA_PATH = './fixtures/primary-domains.json'; const PRIMARY_DOMAIN_DATA_PATH = './fixtures/primary-domains.json';
const DEPLOYMENT_DATA_PATH = './fixtures/deployments.json'; const DEPLOYMENT_DATA_PATH = './fixtures/deployments.json';

View File

@ -2,7 +2,7 @@
{ {
"id": 1, "id": 1,
"projectid": 1, "projectid": 1,
"name": "randomurl.snowballtools.xyz", "name": "example.snowballtools.xyz",
"status": "live", "status": "live",
"record": null, "record": null,
"isRedirectedto": false "isRedirectedto": false
@ -10,7 +10,7 @@
{ {
"id": 2, "id": 2,
"projectid": 1, "projectid": 1,
"name": "saugatt.com", "name": "example.org",
"status": "pending", "status": "pending",
"record": { "record": {
"type": "A", "type": "A",
@ -22,7 +22,7 @@
{ {
"id": 3, "id": 3,
"projectid": 1, "projectid": 1,
"name": "www.saugatt.com", "name": "www.example.org",
"status": "pending", "status": "pending",
"record": { "record": {
"type": "CNAME", "type": "CNAME",

View File

@ -1,17 +0,0 @@
[
{
"name": "Saugat Yadav",
"email": "saugaty@airfoil.studio",
"id": 1
},
{
"name": "Gideon Low",
"email": "gideonl@airfoil.studio",
"id": 2
},
{
"name": "Sushan Yadav",
"email": "sushany@airfoil.studio",
"id": 3
}
]

View File

@ -1,6 +1,6 @@
[ [
"[20:50:03.502] Running build in Washington, D.C., USA (East) iad1", "[20:50:03.502] Running build in Washington, D.C., USA (East) iad1",
"[20:50:03.641] Cloning github.com/saugatyadav11/nextjs2 (Branch: main, Commit: 4a5f47f)", "[20:50:03.641] Cloning github.com/cerc-io/nextjs2 (Branch: main, Commit: 4a5f47f)",
"[20:50:04.004] Previous build cache not available", "[20:50:04.004] Previous build cache not available",
"[20:50:04.118] Cloning completed: 480.574ms", "[20:50:04.118] Cloning completed: 480.574ms",
"[20:50:04.382] Running 'vercel build'", "[20:50:04.382] Running 'vercel build'",

View File

@ -1,190 +0,0 @@
[
{
"id": 1,
"icon": "^",
"name": "iglootools",
"title": "Iglootools",
"domain": null,
"organization": "Airfoil",
"url": "iglootools.co",
"createdAt": "2023-12-07T04:20:00",
"createdBy": "Alice",
"deployment": "iglootools.snowballtools.co",
"source": "feature/add-remote-control",
"latestCommit": {
"message": "subscription added",
"createdAt": "2023-12-11T04:20:00",
"branch": "main"
},
"repositoryId": 1,
"members": [
{
"id": 1,
"permissions": []
},
{
"id": 2,
"permissions": ["view", "edit"]
},
{
"id": 3,
"permissions": ["view"]
}
],
"ownerId": 1
},
{
"id": 2,
"icon": "^",
"name": "snowball-starter-kit",
"title": "Snowball Starter Kit",
"domain": null,
"organization": "Snowball",
"url": "starterkit.snowballtools.com",
"createdAt": "2023-12-04T04:20:00",
"createdBy": "Bob",
"deployment": "deploy.snowballtools.com",
"source": "prod/add-docker-compose",
"latestCommit": {
"message": "component updates",
"createdAt": "2023-12-11T04:20:00",
"branch": "staging"
},
"repositoryId": 1,
"members": [
{
"id": 2,
"permissions": []
},
{
"id": 3,
"permissions": ["view"]
}
],
"ownerId": 2
},
{
"id": 3,
"icon": "^",
"name": "web3-android",
"title": "Web3 Android",
"domain": null,
"organization": "Personal",
"url": "web3fordroids.com",
"createdAt": "2023-12-01T04:20:00",
"createdBy": "Charlie",
"deployment": "deploy.web3fordroids.com",
"source": "dev/style-page",
"latestCommit": {
"message": "No repo connected",
"createdAt": "2023-12-01T04:20:00",
"branch": "main"
},
"repositoryId": 1,
"members": [
{
"id": 1,
"permissions": []
},
{
"id": 2,
"permissions": ["view", "edit"]
},
{
"id": 3,
"permissions": ["view"]
}
],
"ownerId": 1
},
{
"id": 4,
"icon": "^",
"name": "passkeys-demo",
"title": "Passkeys Demo",
"domain": null,
"organization": "Airfoil",
"url": "passkeys.iglootools.xyz",
"createdAt": "2023-12-01T04:20:00",
"createdBy": "David",
"deployment": "demo.passkeys.xyz",
"source": "dev/style-page",
"latestCommit": {
"message": "hello world",
"createdAt": "2023-12-01T04:20:00",
"branch": "main"
},
"repositoryId": 1,
"members": [
{
"id": 1,
"permissions": []
},
{
"id": 2,
"permissions": ["view", "edit"]
},
{
"id": 3,
"permissions": ["view"]
}
],
"ownerId": 1
},
{
"id": 5,
"icon": "^",
"name": "iglootools",
"title": "Iglootools",
"domain": null,
"organization": "Airfoil",
"url": "iglootools.xyz",
"createdAt": "2023-12-11T04:20:00",
"createdBy": "Erin",
"deployment": "staging.snowballtools.com",
"source": "prod/fix-error",
"latestCommit": {
"message": "404 added",
"createdAt": "2023-12-09T04:20:00",
"branch": "main"
},
"repositoryId": 1,
"members": [
{
"id": 3,
"permissions": []
}
],
"ownerId": 3
},
{
"id": 6,
"icon": "^",
"name": "iglootools",
"title": "Iglootools",
"domain": null,
"organization": "Airfoil",
"url": "iglootools.xyz",
"createdAt": "2023-12-11T04:20:00",
"createdBy": "Frank",
"deployment": "iglootools.snowballtools.com",
"source": "prod/fix-error",
"latestCommit": {
"message": "design system integrated",
"createdAt": "2023-12-09T04:20:00",
"branch": "prod"
},
"repositoryId": 1,
"members": [
{
"id": 2,
"permissions": []
},
{
"id": 3,
"permissions": ["view"]
}
],
"ownerId": 2
}
]

View File

@ -122,11 +122,7 @@ const DeploymentDetailsCard = ({
<button className="self-start">...</button> <button className="self-start">...</button>
</MenuHandler> </MenuHandler>
<MenuList> <MenuList>
<a <a href={deployment.url} target="_blank" rel="noreferrer">
href={'https://' + deployment.url}
target="_blank"
rel="noreferrer"
>
<MenuItem disabled={!Boolean(deployment.url)}>^ Visit</MenuItem> <MenuItem disabled={!Boolean(deployment.url)}>^ Visit</MenuItem>
</a> </a>
<MenuItem <MenuItem

View File

@ -66,8 +66,10 @@ const DeploymentsTabPanel = () => {
const dateMatch = const dateMatch =
!filterValue.updateAtRange || !filterValue.updateAtRange ||
(new Date(deployment.updatedAt) >= filterValue.updateAtRange!.from! && (new Date(Number(deployment.createdAt)) >=
new Date(deployment.updatedAt) <= filterValue.updateAtRange!.to!); filterValue.updateAtRange!.from! &&
new Date(Number(deployment.createdAt)) <=
filterValue.updateAtRange!.to!);
return branchMatch && statusMatch && dateMatch; return branchMatch && statusMatch && dateMatch;
}); });