From 1d3bddad2b5e320ea6a484f9c723a8ce996aa177 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Mon, 11 Dec 2023 09:04:59 +0100 Subject: [PATCH 1/4] Don't override a running job to pending --- backend/parser/gitlab/build.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/parser/gitlab/build.ts b/backend/parser/gitlab/build.ts index 65603e2..c87502c 100644 --- a/backend/parser/gitlab/build.ts +++ b/backend/parser/gitlab/build.ts @@ -8,6 +8,7 @@ import { statusToStepState } from './helper'; class GitLabBuildParser { parse(id: string, build: GitLabBuild): Status | null { + // Created status is not relevant, we start displaying when a job is pending if (build.build_status === 'created') { return null; } @@ -18,6 +19,7 @@ class GitLabBuildParser { const processId = build.pipeline_id; + // If the pushed build (step) is not part of the status its processes yet, add it if (!processes.find((process) => process.id === processId)) { if (isOldProcess(status, processId)) { return null; @@ -80,6 +82,7 @@ class GitLabBuildParser { const stageId = Slugify(build.build_stage); + // If the pushed build (step) is not part of the process its stages yet, add it if (!stages.find((stage) => stage.id === stageId)) { stages.push({ id: stageId, @@ -109,6 +112,7 @@ class GitLabBuildParser { const stepId = Slugify(build.build_name); + // If the pushed build (step) is not part of the stage its steps yet, add it if (!steps.find((step) => step.id === stepId)) { steps.push({ id: stepId, @@ -120,7 +124,17 @@ class GitLabBuildParser { steps = steps.map((step) => { if (step.id === stepId) { - step.state = statusToStepState(build.build_status, build.build_allow_failure); + // TODO: check if previous was running, and current is started, then ignore + + const previousState = step.state; + const newState = statusToStepState(build.build_status, build.build_allow_failure); + + // Don't set job to pending when it's running already + if (previousState === 'running' && newState === 'pending') { + return step; + } + + step.state = newState; step.time = new Date().toUTCString(); } From f8968f926ccaa3e7a0e6b5f1359ec9dbc3ef53b4 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Mon, 11 Dec 2023 09:07:57 +0100 Subject: [PATCH 2/4] Remove already solved TODO --- backend/parser/gitlab/build.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/parser/gitlab/build.ts b/backend/parser/gitlab/build.ts index c87502c..032296d 100644 --- a/backend/parser/gitlab/build.ts +++ b/backend/parser/gitlab/build.ts @@ -124,8 +124,6 @@ class GitLabBuildParser { steps = steps.map((step) => { if (step.id === stepId) { - // TODO: check if previous was running, and current is started, then ignore - const previousState = step.state; const newState = statusToStepState(build.build_status, build.build_allow_failure); From c183da39c648e608290b7a19a89abc0926706311 Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Mon, 11 Dec 2023 09:13:07 +0100 Subject: [PATCH 3/4] Add test case for not overriding running jobs with pending --- .../fixtures/gitlab/branch-with-mr/16.json | 112 ++++++++-------- .../fixtures/gitlab/branch-with-mr/30.json | 126 +++++++++--------- 2 files changed, 119 insertions(+), 119 deletions(-) diff --git a/cypress/fixtures/gitlab/branch-with-mr/16.json b/cypress/fixtures/gitlab/branch-with-mr/16.json index 6bd0487..5197e88 100644 --- a/cypress/fixtures/gitlab/branch-with-mr/16.json +++ b/cypress/fixtures/gitlab/branch-with-mr/16.json @@ -1,58 +1,58 @@ { - "headers": { - "content-type": "application/json", - "user-agent": "GitLab/14.10.0-pre", - "x-gitlab-event": "Job Hook" - }, - "body": { - "object_kind": "build", - "ref": "74", - "tag": false, - "before_sha": "057ffcf3b58f839c17fff0e022b8011eca4cf303", - "sha": "70b15b53ded5151bb15efa80279f4cc732996717", - "build_id": 2314349282, - "build_name": "api tests", - "build_stage": "test", - "build_status": "pending", - "build_created_at": "2022-04-09 19:26:31 UTC", - "build_started_at": null, - "build_finished_at": null, - "build_duration": null, - "build_queued_duration": 0.075305112, - "build_allow_failure": false, - "build_failure_reason": "unknown_failure", - "pipeline_id": 513076930, - "runner": null, - "project_id": 33715538, - "project_name": "FuturePortal / Nawcast", - "user": { - "id": 203336, - "name": "Rick van der Staaij", - "username": "rick.nu", - "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/203336/avatar.png", - "email": "[REDACTED]" - }, - "commit": { - "id": 513076930, - "sha": "70b15b53ded5151bb15efa80279f4cc732996717", - "message": "[#74] Add web frame slide type in the dashboard\n", - "author_name": "Rick van der Staaij", - "author_email": "[REDACTED]", - "author_url": "https://gitlab.com/rick.nu", - "status": "created", - "duration": null, - "started_at": null, - "finished_at": null - }, - "repository": { - "name": "Nawcast", - "url": "git@gitlab.com:FuturePortal/Nawcast.git", - "description": "https://nawcast.com", - "homepage": "https://gitlab.com/FuturePortal/Nawcast", - "git_http_url": "https://gitlab.com/FuturePortal/Nawcast.git", - "git_ssh_url": "git@gitlab.com:FuturePortal/Nawcast.git", - "visibility_level": 0 - }, - "environment": null - } + "headers": { + "content-type": "application/json", + "user-agent": "GitLab/14.10.0-pre", + "x-gitlab-event": "Job Hook" + }, + "body": { + "object_kind": "build", + "ref": "74", + "tag": false, + "before_sha": "057ffcf3b58f839c17fff0e022b8011eca4cf303", + "sha": "70b15b53ded5151bb15efa80279f4cc732996717", + "build_id": 2314349282, + "build_name": "api tests", + "build_stage": "test", + "build_status": "running", + "build_created_at": "2022-04-09 19:26:31 UTC", + "build_started_at": null, + "build_finished_at": null, + "build_duration": null, + "build_queued_duration": 0.075305112, + "build_allow_failure": false, + "build_failure_reason": "unknown_failure", + "pipeline_id": 513076930, + "runner": null, + "project_id": 33715538, + "project_name": "FuturePortal / Nawcast", + "user": { + "id": 203336, + "name": "Rick van der Staaij", + "username": "rick.nu", + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/203336/avatar.png", + "email": "[REDACTED]" + }, + "commit": { + "id": 513076930, + "sha": "70b15b53ded5151bb15efa80279f4cc732996717", + "message": "[#74] Add web frame slide type in the dashboard\n", + "author_name": "Rick van der Staaij", + "author_email": "[REDACTED]", + "author_url": "https://gitlab.com/rick.nu", + "status": "created", + "duration": null, + "started_at": null, + "finished_at": null + }, + "repository": { + "name": "Nawcast", + "url": "git@gitlab.com:FuturePortal/Nawcast.git", + "description": "https://nawcast.com", + "homepage": "https://gitlab.com/FuturePortal/Nawcast", + "git_http_url": "https://gitlab.com/FuturePortal/Nawcast.git", + "git_ssh_url": "git@gitlab.com:FuturePortal/Nawcast.git", + "visibility_level": 0 + }, + "environment": null + } } diff --git a/cypress/fixtures/gitlab/branch-with-mr/30.json b/cypress/fixtures/gitlab/branch-with-mr/30.json index 6ee03f2..372843b 100644 --- a/cypress/fixtures/gitlab/branch-with-mr/30.json +++ b/cypress/fixtures/gitlab/branch-with-mr/30.json @@ -1,65 +1,65 @@ { - "headers": { - "content-type": "application/json", - "user-agent": "GitLab/14.10.0-pre", - "x-gitlab-event": "Job Hook" - }, - "body": { - "object_kind": "build", - "ref": "74", - "tag": false, - "before_sha": "057ffcf3b58f839c17fff0e022b8011eca4cf303", - "sha": "70b15b53ded5151bb15efa80279f4cc732996717", - "build_id": 2314349282, - "build_name": "api tests", - "build_stage": "test", - "build_status": "running", - "build_created_at": "2022-04-09 19:26:31 UTC", - "build_started_at": "2022-04-09 19:26:33 UTC", - "build_finished_at": null, - "build_duration": 0.134215871, - "build_queued_duration": 2.140293, - "build_allow_failure": false, - "build_failure_reason": "unknown_failure", - "pipeline_id": 513076930, - "runner": { - "id": 13775607, - "description": "local.rick.nu", - "runner_type": "group_type", - "active": true, - "is_shared": false, - "tags": [] - }, - "project_id": 33715538, - "project_name": "FuturePortal / Nawcast", - "user": { - "id": 203336, - "name": "Rick van der Staaij", - "username": "rick.nu", - "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/203336/avatar.png", - "email": "[REDACTED]" - }, - "commit": { - "id": 513076930, - "sha": "70b15b53ded5151bb15efa80279f4cc732996717", - "message": "[#74] Add web frame slide type in the dashboard\n", - "author_name": "Rick van der Staaij", - "author_email": "[REDACTED]", - "author_url": "https://gitlab.com/rick.nu", - "status": "running", - "duration": null, - "started_at": "2022-04-09 19:26:32 UTC", - "finished_at": null - }, - "repository": { - "name": "Nawcast", - "url": "git@gitlab.com:FuturePortal/Nawcast.git", - "description": "https://nawcast.com", - "homepage": "https://gitlab.com/FuturePortal/Nawcast", - "git_http_url": "https://gitlab.com/FuturePortal/Nawcast.git", - "git_ssh_url": "git@gitlab.com:FuturePortal/Nawcast.git", - "visibility_level": 0 - }, - "environment": null - } + "headers": { + "content-type": "application/json", + "user-agent": "GitLab/14.10.0-pre", + "x-gitlab-event": "Job Hook" + }, + "body": { + "object_kind": "build", + "ref": "74", + "tag": false, + "before_sha": "057ffcf3b58f839c17fff0e022b8011eca4cf303", + "sha": "70b15b53ded5151bb15efa80279f4cc732996717", + "build_id": 2314349282, + "build_name": "api tests", + "build_stage": "test", + "build_status": "pending", + "build_created_at": "2022-04-09 19:26:31 UTC", + "build_started_at": "2022-04-09 19:26:33 UTC", + "build_finished_at": null, + "build_duration": 0.134215871, + "build_queued_duration": 2.140293, + "build_allow_failure": false, + "build_failure_reason": "unknown_failure", + "pipeline_id": 513076930, + "runner": { + "id": 13775607, + "description": "local.rick.nu", + "runner_type": "group_type", + "active": true, + "is_shared": false, + "tags": [] + }, + "project_id": 33715538, + "project_name": "FuturePortal / Nawcast", + "user": { + "id": 203336, + "name": "Rick van der Staaij", + "username": "rick.nu", + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/203336/avatar.png", + "email": "[REDACTED]" + }, + "commit": { + "id": 513076930, + "sha": "70b15b53ded5151bb15efa80279f4cc732996717", + "message": "[#74] Add web frame slide type in the dashboard\n", + "author_name": "Rick van der Staaij", + "author_email": "[REDACTED]", + "author_url": "https://gitlab.com/rick.nu", + "status": "running", + "duration": null, + "started_at": "2022-04-09 19:26:32 UTC", + "finished_at": null + }, + "repository": { + "name": "Nawcast", + "url": "git@gitlab.com:FuturePortal/Nawcast.git", + "description": "https://nawcast.com", + "homepage": "https://gitlab.com/FuturePortal/Nawcast", + "git_http_url": "https://gitlab.com/FuturePortal/Nawcast.git", + "git_ssh_url": "git@gitlab.com:FuturePortal/Nawcast.git", + "visibility_level": 0 + }, + "environment": null + } } From f60041b0fefa02a84be0c2b76e7425a43552b24e Mon Sep 17 00:00:00 2001 From: Rick van der Staaij Date: Mon, 11 Dec 2023 09:13:56 +0100 Subject: [PATCH 4/4] Bump version to 4.11.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e9eb90f..799b7e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cimonitor", - "version": "4.11.1", + "version": "4.11.2", "description": "Monitors all your projects CI automatically", "repository": "git@github.com:FuturePortal/CIMonitor.git", "license": "MIT",