From 94b1f5c46f7af13ae0872d9662a17bf36dbafdbe Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:40:36 +0530 Subject: [PATCH 01/11] Fix VIN --- .../java/com/crapi/utils/GenerateVIN.java | 119 ++++++++++-------- services/web/src/constants/constants.js | 2 +- 2 files changed, 65 insertions(+), 56 deletions(-) diff --git a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java index b3c5a5b8..0de7dc25 100644 --- a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java +++ b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java @@ -12,59 +12,68 @@ * limitations under the License. */ -package com.crapi.utils; + package com.crapi.utils; -import java.util.Random; - -public class GenerateVIN { - - static String charsequence = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - static String num = "0123456789"; - String vin = ""; - String pincode = ""; - Random random; - - public GenerateVIN() { - random = new Random(); - } - - public GenerateVIN(long seed) { - random = new Random(seed); - } - - /** @return random generate pin code for add vehicle */ - public String generatePincode() { - pincode += getNum(3); - return pincode; - } - - /** @return rendom generate VIN for vehicle */ - public String generateVIN() { - vin += getNum(0) + getChar(3) + getNum(1) + getChar(3) + getNum(5); - return vin; - } - - public String getChar(int num) { - String randStr = ""; - for (int j = 0; j <= num; j++) randStr += randomCharacter(); - return randStr; - } - - public String getNum(int num) { - String randNum = ""; - for (int k = 0; k <= num; k++) randNum += randomNumber(); - return randNum; - } - - public String randomCharacter() { - int n = charsequence.length(); - int r = random.nextInt(n); - return charsequence.substring(r, r + 1); - } - - public String randomNumber() { - int n = num.length(); - int r = random.nextInt(n); - return num.substring(r, r + 1); - } -} + import java.util.Random; + + public class GenerateVIN { + + static String charsequence = "ABCDEFGHJKLMNPRSTUVWXYZ"; // I, O, Q are excluded + static String num = "0123456789"; + String vin = ""; + String pincode = ""; + Random random; + + public GenerateVIN() { + random = new Random(); + } + + public GenerateVIN(long seed) { + random = new Random(seed); + } + + /** @return random generate pin code for add vehicle */ + public String generatePincode() { + pincode += getNum(3); + return pincode; + } + + /** @return randomly generated VIN */ + public String generateVIN() { + StringBuilder vin = new StringBuilder(); + for (int i = 0; i < 17; i++) { + if (random.nextBoolean()) { + vin.append(randomCharacter()); + } else { + vin.append(randomNumber()); + } + } + return vin.toString(); + } + + + public String getChar(int num) { + String randStr = ""; + for (int j = 0; j <= num; j++) randStr += randomCharacter(); + return randStr; + } + + public String getNum(int num) { + String randNum = ""; + for (int k = 0; k <= num; k++) randNum += randomNumber(); + return randNum; + } + + public String randomCharacter() { + int n = charsequence.length(); + int r = random.nextInt(n); + return charsequence.substring(r, r + 1); + } + + public String randomNumber() { + int n = num.length(); + int r = random.nextInt(n); + return num.substring(r, r + 1); + } + } + \ No newline at end of file diff --git a/services/web/src/constants/constants.js b/services/web/src/constants/constants.js index 81d5f8ce..3fdea018 100644 --- a/services/web/src/constants/constants.js +++ b/services/web/src/constants/constants.js @@ -23,4 +23,4 @@ export const PASSWORD_VALIDATION = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,16}$/; export const NAME_VALIDATION = /^[a-zA-Z ]+$/; export const PIN_CODE_VALIDATION = /^[0-9]{4}$/; -export const VIN_VALIDATION = /^[0-9][A-Z]{4}[0-9]{2}[A-Z]{4}[0-9]{6}$/; +export const VIN_VALIDATION = /^[A-HJ-NPR-Z0-9]{17}$/; From 889c4d8889ab752592e9501e19e66620cb7955aa Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:41:42 +0530 Subject: [PATCH 02/11] Fix spaces --- .../java/com/crapi/utils/GenerateVIN.java | 127 +++++++++--------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java index 0de7dc25..d6380e6f 100644 --- a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java +++ b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java @@ -12,68 +12,67 @@ * limitations under the License. */ - package com.crapi.utils; +package com.crapi.utils; - import java.util.Random; - - public class GenerateVIN { - - static String charsequence = "ABCDEFGHJKLMNPRSTUVWXYZ"; // I, O, Q are excluded - static String num = "0123456789"; - String vin = ""; - String pincode = ""; - Random random; - - public GenerateVIN() { - random = new Random(); - } - - public GenerateVIN(long seed) { - random = new Random(seed); - } - - /** @return random generate pin code for add vehicle */ - public String generatePincode() { - pincode += getNum(3); - return pincode; - } - - /** @return randomly generated VIN */ - public String generateVIN() { - StringBuilder vin = new StringBuilder(); - for (int i = 0; i < 17; i++) { - if (random.nextBoolean()) { - vin.append(randomCharacter()); - } else { - vin.append(randomNumber()); - } - } - return vin.toString(); - } - - - public String getChar(int num) { - String randStr = ""; - for (int j = 0; j <= num; j++) randStr += randomCharacter(); - return randStr; - } - - public String getNum(int num) { - String randNum = ""; - for (int k = 0; k <= num; k++) randNum += randomNumber(); - return randNum; - } - - public String randomCharacter() { - int n = charsequence.length(); - int r = random.nextInt(n); - return charsequence.substring(r, r + 1); - } - - public String randomNumber() { - int n = num.length(); - int r = random.nextInt(n); - return num.substring(r, r + 1); - } - } - \ No newline at end of file +import java.util.Random; + +public class GenerateVIN { + + static String charsequence = "ABCDEFGHJKLMNPRSTUVWXYZ"; // I, O, Q are excluded + static String num = "0123456789"; + String vin = ""; + String pincode = ""; + Random random; + + public GenerateVIN() { + random = new Random(); + } + + public GenerateVIN(long seed) { + random = new Random(seed); + } + + /** @return random generate pin code for add vehicle */ + public String generatePincode() { + pincode += getNum(3); + return pincode; + } + + /** @return randomly generated VIN */ + public String generateVIN() { + StringBuilder vin = new StringBuilder(); + for (int i = 0; i < 17; i++) { + if (random.nextBoolean()) { + vin.append(randomCharacter()); + } else { + vin.append(randomNumber()); + } + } + return vin.toString(); + } + + + public String getChar(int num) { + String randStr = ""; + for (int j = 0; j <= num; j++) randStr += randomCharacter(); + return randStr; + } + + public String getNum(int num) { + String randNum = ""; + for (int k = 0; k <= num; k++) randNum += randomNumber(); + return randNum; + } + + public String randomCharacter() { + int n = charsequence.length(); + int r = random.nextInt(n); + return charsequence.substring(r, r + 1); + } + + public String randomNumber() { + int n = num.length(); + int r = random.nextInt(n); + return num.substring(r, r + 1); + } +} From b2506a0ab5bf6e6aa7a05b7ea8a5b9a8339671bd Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:58:42 +0530 Subject: [PATCH 03/11] SpotlessApply --- services/identity/.java-version | 2 +- .../java/com/crapi/utils/GenerateVIN.java | 33 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/services/identity/.java-version b/services/identity/.java-version index 98d9bcb7..2dbc24b3 100644 --- a/services/identity/.java-version +++ b/services/identity/.java-version @@ -1 +1 @@ -17 +11.0 diff --git a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java index d6380e6f..d3fa14cf 100644 --- a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java +++ b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java @@ -1,16 +1,16 @@ /* - * Licensed under the Apache License, Version 2.0 (the “License”); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an “AS IS” BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Licensed under the Apache License, Version 2.0 (the “License”); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an “AS IS” BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ package com.crapi.utils; @@ -32,13 +32,17 @@ public GenerateVIN(long seed) { random = new Random(seed); } - /** @return random generate pin code for add vehicle */ + /** + * @return random generate pin code for add vehicle + */ public String generatePincode() { pincode += getNum(3); return pincode; } - /** @return randomly generated VIN */ + /** + * @return randomly generated VIN + */ public String generateVIN() { StringBuilder vin = new StringBuilder(); for (int i = 0; i < 17; i++) { @@ -51,7 +55,6 @@ public String generateVIN() { return vin.toString(); } - public String getChar(int num) { String randStr = ""; for (int j = 0; j <= num; j++) randStr += randomCharacter(); From 83371c5adb5727cf575acee9359181df281b049c Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:00:12 +0530 Subject: [PATCH 04/11] SpotlessApply --- .../src/main/java/com/crapi/utils/GenerateVIN.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java index d3fa14cf..1c902596 100644 --- a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java +++ b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java @@ -32,17 +32,13 @@ public GenerateVIN(long seed) { random = new Random(seed); } - /** - * @return random generate pin code for add vehicle - */ + /** @return random generate pin code for add vehicle */ public String generatePincode() { pincode += getNum(3); return pincode; } - /** - * @return randomly generated VIN - */ + /** @return randomly generated VIN */ public String generateVIN() { StringBuilder vin = new StringBuilder(); for (int i = 0; i < 17; i++) { @@ -55,6 +51,7 @@ public String generateVIN() { return vin.toString(); } + public String getChar(int num) { String randStr = ""; for (int j = 0; j <= num; j++) randStr += randomCharacter(); From a82e4cd355fa547bfb5b4e614e6582c917716d8f Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:26:33 +0530 Subject: [PATCH 05/11] SpotlessApply --- .../java/com/crapi/utils/GenerateVIN.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java index 1c902596..292c3906 100644 --- a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java +++ b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java @@ -1,16 +1,16 @@ /* -* Licensed under the Apache License, Version 2.0 (the “License”); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an “AS IS” BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Licensed under the Apache License, Version 2.0 (the “License”); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an “AS IS” BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.crapi.utils; @@ -51,7 +51,6 @@ public String generateVIN() { return vin.toString(); } - public String getChar(int num) { String randStr = ""; for (int j = 0; j <= num; j++) randStr += randomCharacter(); From 31f147d07bdb4993b040ff8da2423038a9f3cb20 Mon Sep 17 00:00:00 2001 From: Namburi Soujanya <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:27:53 +0530 Subject: [PATCH 06/11] Update .java-version --- services/identity/.java-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/identity/.java-version b/services/identity/.java-version index 2dbc24b3..98d9bcb7 100644 --- a/services/identity/.java-version +++ b/services/identity/.java-version @@ -1 +1 @@ -11.0 +17 From 0f753db519c25dda82a304194cc2be0ee58d2eae Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:46:43 +0530 Subject: [PATCH 07/11] Add docker compose --- .github/workflows/pr-build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index d45a9e17..30e54611 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -146,10 +146,10 @@ jobs: - name: Cleanup docker before running if: always() continue-on-error: true - run: docker-compose -f deploy/docker/docker-compose.yml down --volumes --remove-orphans + run: docker compose -f deploy/docker/docker-compose.yml down --volumes --remove-orphans - name: Run crAPI using built images - run: VERSION=${{ env.TAG_NAME }} docker-compose -f deploy/docker/docker-compose.yml --compatibility up -d + run: VERSION=${{ env.TAG_NAME }} docker compose -f deploy/docker/docker-compose.yml --compatibility up -d - name: Install Node uses: actions/setup-node@v3 @@ -168,7 +168,7 @@ jobs: - name: Cleanup docker if: always() - run: docker-compose -f deploy/docker/docker-compose.yml down --volumes --remove-orphans + run: docker compose -f deploy/docker/docker-compose.yml down --volumes --remove-orphans tests: @@ -195,7 +195,7 @@ jobs: go-version: '1.21' - name: Start the database - run: docker-compose -f services/docker-database.yml up -d + run: docker compose -f services/docker-database.yml up -d - name: Run identity tests run: | From b47b6c340e6159e1a3183ed8994ce0bf71fcc24a Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:22:37 +0530 Subject: [PATCH 08/11] Upgrade orgoro --- .github/workflows/pr-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 30e54611..65fb062b 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -249,7 +249,7 @@ jobs: coverage xml -o coverage.xml - name: Publish Coverage for workshop - uses: orgoro/coverage@v3.1 + uses: orgoro/coverage@v3.2 with: coverageFile: services/workshop/coverage.xml token: ${{ secrets.GITHUB_TOKEN }} From dc0ac9bf9fc61a2d4f5f2b7e908589dc46665403 Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:41:49 +0530 Subject: [PATCH 09/11] Add coverage summary instead --- .github/workflows/pr-build.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 65fb062b..e9433906 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -247,12 +247,21 @@ jobs: IS_TESTING=True coverage run ./manage.py test --no-input crapi coverage report coverage xml -o coverage.xml - - - name: Publish Coverage for workshop - uses: orgoro/coverage@v3.2 + + - name: Coverage Report for workshop + uses: irongut/CodeCoverageSummary@v1.3.0 with: - coverageFile: services/workshop/coverage.xml - token: ${{ secrets.GITHUB_TOKEN }} + filename: 'services/workshop/coverage.xml' + badge: true + format: 'markdown' + output: 'both' + + - name: Add Coverage PR Comment + uses: marocchino/sticky-pull-request-comment@v2 + if: github.event_name == 'pull_request' + with: + recreate: true + path: code-coverage-results.md - name: node prettier run: | From c4efe63e9ff0e7880534c1ec02457662be83ec60 Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:46:45 +0530 Subject: [PATCH 10/11] Revert pr build --- .github/workflows/pr-build.yml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index e9433906..65fb062b 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -247,21 +247,12 @@ jobs: IS_TESTING=True coverage run ./manage.py test --no-input crapi coverage report coverage xml -o coverage.xml - - - name: Coverage Report for workshop - uses: irongut/CodeCoverageSummary@v1.3.0 + + - name: Publish Coverage for workshop + uses: orgoro/coverage@v3.2 with: - filename: 'services/workshop/coverage.xml' - badge: true - format: 'markdown' - output: 'both' - - - name: Add Coverage PR Comment - uses: marocchino/sticky-pull-request-comment@v2 - if: github.event_name == 'pull_request' - with: - recreate: true - path: code-coverage-results.md + coverageFile: services/workshop/coverage.xml + token: ${{ secrets.GITHUB_TOKEN }} - name: node prettier run: | From 660c08e9206fcbd37829a3386b44acd6f4f2c8cc Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:48:11 +0530 Subject: [PATCH 11/11] add permissions pull request write --- .github/workflows/pr-build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 65fb062b..9dbce091 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -22,6 +22,8 @@ jobs: runs-on: ubuntu-latest env: PLATFORMS: "linux/amd64,linux/arm64" + permissions: + pull-requests: write steps: - name: Checkout code uses: actions/checkout@v4