Skip to content

Commit

Permalink
fixing sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses-cognizant committed Aug 8, 2024
1 parent d2876a6 commit e7b3c7e
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 76 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/check-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ jobs:
name: Run Pull Request Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm install
- run: npm run format:check
- run: npm run lint
- run: npm test
# No longer needed with the latest version of the SonarCloud GitHub Action
# https://community.sonarsource.com/t/code-coverage-doesnt-work-with-github-action/16747/6
# - name: make sonar aware of coverage tests path
# run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage/lcov.info
- name: SonarCloud Scan
if: github.actor != 'dependabot[bot]'
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
12 changes: 11 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build and Publish
uses: DEFRA/cdp-build-action/build@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: npm install && npm test
# No longer needed with the latest version of the SonarCloud GitHub Action
# https://community.sonarsource.com/t/code-coverage-doesnt-work-with-github-action/16747/6
# - name: make sonar aware of coverage tests path
# run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage/lcov.info
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2 changes: 1 addition & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const config = convict({
doc: 'OS Name Places key',
format: '*',
sensitive: true,
default: 'vvR3FiaNjSWCnFzSKBst23TX6efl0oL9',
default: '',
env: 'OS_PLACES_API_KEY'
},
osPlacesApiUrl: {
Expand Down
41 changes: 27 additions & 14 deletions src/server/accessibility/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,45 @@ import { english } from '~/src/server/data/en/en.js'

const accessibilityController = {
handler: (request, h) => {
/* eslint-disable camelcase */
const {
footer: { accessibility },
footer: {
accessibility: {
paragraphs,
pageTitle,
title,
utm_source,
userId,
headings,
heading
}
},
cookieBanner,
phaseBanner,
footerTxt,
multipleLocations
multipleLocations: { serviceName }
} = english
const lang = 'en'
const { query } = request
if (query?.lang && query?.lang === 'cy') {
const language = 'en'
const {
query: { lang }
} = request
if (lang && lang === 'cy') {
return h.redirect('/hygyrchedd/cy')
}
return h.view('accessibility/index', {
userId: query?.userId,
utm_source: query?.utm_source,
pageTitle: accessibility.pageTitle,
title: accessibility.title,
heading: accessibility.heading,
headings: accessibility.headings,
paragraphs: accessibility.paragraphs,
userId,
utm_source,
pageTitle,
title,
heading,
headings,
paragraphs,
displayBacklink: false,
phaseBanner,
footerTxt,
cookieBanner,
serviceName: multipleLocations.serviceName,
lang: query.lang ?? lang
serviceName,
lang: lang ?? language
})
}
}
Expand Down
33 changes: 19 additions & 14 deletions src/server/accessibility/cy/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,36 @@ import { welsh } from '~/src/server/data/cy/cy.js'
const accessibilityController = {
handler: (request, h) => {
const {
footer: { accessibility },
footer: {
accessibility: { pageTitle, title, heading, headings, paragraphs }
},
cookieBanner,
phaseBanner,
footerTxt,
multipleLocations
multipleLocations: { serviceName }
} = welsh
const { query } = request
const lang = 'cy'
if (query?.lang && query?.lang === 'en') {
/* eslint-disable camelcase */
const {
query: { lang, userId, utm_source }
} = request
const language = 'cy'
if (lang && lang === 'en') {
return h.redirect('/accessibility')
}
return h.view('accessibility/index', {
userId: query?.userId,
utm_source: query?.utm_source,
pageTitle: accessibility.pageTitle,
title: accessibility.title,
heading: accessibility.heading,
headings: accessibility.headings,
paragraphs: accessibility.paragraphs,
userId,
utm_source,
pageTitle,
title,
heading,
headings,
paragraphs,
displayBacklink: false,
phaseBanner,
footerTxt,
cookieBanner,
serviceName: multipleLocations.serviceName,
lang: query?.lang ?? lang
serviceName,
lang: lang ?? language
})
}
}
Expand Down
43 changes: 27 additions & 16 deletions src/server/cookies/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,45 @@ import { english } from '~/src/server/data/en/en.js'
const cookiesController = {
handler: (request, h) => {
const {
footer: { cookies },
footer: {
cookies: {
pageTitle,
title,
headings,
heading,
table1,
table2,
paragraphs
}
},
cookieBanner,
phaseBanner,
footerTxt,
multipleLocations
multipleLocations: { serviceName }
} = english
const { query } = request
const lang = 'en'
if (query?.lang && query?.lang === 'cy') {
/* eslint-disable camelcase */
const { query: lang, userId, utm_source } = request
const language = 'en'
if (lang && lang === 'cy') {
return h.redirect('/briwsion/cy')
}
return h.view('cookies/index', {
userId: query?.userId,
utm_source: query?.utm_source,
pageTitle: cookies.pageTitle,
title: cookies.title,
heading: cookies.heading,
headings: cookies.headings,
table1: cookies.table1,
table2: cookies.table2,
paragraphs: cookies.paragraphs,
userId,
utm_source,
pageTitle,
title,
heading,
headings,
table1,
table2,
paragraphs,
displayBacklink: false,
phaseBanner,
footerTxt,
cookieBanner,
serviceName: multipleLocations.serviceName,
serviceName,
page: 'cookies',
lang: lang ?? lang
lang: lang ?? language
})
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/server/privacy/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@ import { english } from '~/src/server/data/en/en.js'
const privacyController = {
handler: (request, h) => {
const {
footer: { privacy },
footer: {
privacy: { title, pageTitle, heading, headings, paragraphs }
},
cookieBanner,
phaseBanner,
footerTxt,
multipleLocations
multipleLocations: serviceName
} = english
const { query } = request
const lang = 'en'
if (query?.lang && query?.lang === 'cy') {
/* eslint-disable camelcase */
const { query: lang, userId, utm_source } = request
const language = 'en'
if (lang && lang === 'cy') {
return h.redirect('/preifatrwydd/cy')
}
return h.view('privacy/index', {
userId: query?.userId,
utm_source: query?.utm_source,
pageTitle: privacy.pageTitle,
title: privacy.title,
heading: privacy.heading,
headings: privacy.headings,
paragraphs: privacy.paragraphs,
userId,
utm_source,
pageTitle,
title,
heading,
headings,
paragraphs,
displayBacklink: false,
phaseBanner,
footerTxt,
cookieBanner,
serviceName: multipleLocations.serviceName,
serviceName,
page: 'privacy',
lang: query?.lang ?? lang
lang: lang ?? language
})
}
}
Expand Down
33 changes: 19 additions & 14 deletions src/server/privacy/cy/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,37 @@ import { welsh } from '~/src/server/data/cy/cy.js'
const privacyController = {
handler: (request, h) => {
const {
footer: { privacy },
footer: {
privacy: { pageTitle, title, heading, headings, paragraphs }
},
cookieBanner,
phaseBanner,
footerTxt,
multipleLocations
multipleLocations: { serviceName }
} = welsh
const { query } = request
const lang = 'cy'
if (query?.lang && query?.lang === 'en') {
/* eslint-disable camelcase */
const {
query: { lang, userId, utm_source }
} = request
const language = 'cy'
if (lang && lang === 'en') {
return h.redirect('/privacy')
}
return h.view('privacy/index', {
userId: query?.userId,
utm_source: query?.utm_source,
pageTitle: privacy.pageTitle,
title: privacy.title,
heading: privacy.heading,
headings: privacy.headings,
paragraphs: privacy.paragraphs,
userId,
utm_source,
pageTitle,
title,
heading,
headings,
paragraphs,
displayBacklink: false,
phaseBanner,
footerTxt,
cookieBanner,
serviceName: multipleLocations.serviceName,
serviceName,
page: 'privacy',
lang: query?.lang ?? lang
lang: lang ?? language
})
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sonar.projectKey=8a3e3fc5664ed1006f22cc2abfbdc42bf4208f91
sonar.organization=defra

#sonar.projectName=cdp-example-node-backend

sonar.links.homepage=https://github.com/DEFRA/aqie-front-end
sonar.links.ci=https://github.com/DEFRA/aqie-front-end/actions
sonar.links.scm=https://github.com/DEFRA/aqie-front-end
sonar.links.issue=https://github.com/DEFRA/aqie-front-end/issues

sonar.sources=src/
sonar.exclusions=src/**/*.test.js
sonar.tests=src/
sonar.test.inclusions=src/**/*.test.js

sonar.javascript.lcov.reportPaths=./coverage/lcov.info

0 comments on commit e7b3c7e

Please sign in to comment.