Skip to content

Commit 129b760

Browse files
committed
Fixed more sonar issues
1 parent b02ab0c commit 129b760

11 files changed

Lines changed: 156 additions & 140 deletions

File tree

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
set -e
3636

37+
readonly GH_ACCEPT_HEADER="Accept: application/vnd.github+json"
38+
readonly GH_API_VERSION_HEADER="X-GitHub-Api-Version: 2022-11-28"
39+
3740
usage() {
3841
cat >&2 <<'EOF'
3942
Usage:
@@ -171,16 +174,16 @@ signature=$(
171174
JWT="${header_payload}"."${signature}"
172175

173176
INSTALLATION_ID=$(curl -X GET \
174-
-H "Accept: application/vnd.github+json" \
177+
-H "${GH_ACCEPT_HEADER}" \
175178
-H "Authorization: Bearer ${JWT}" \
176-
-H "X-GitHub-Api-Version: 2022-11-28" \
179+
-H "${GH_API_VERSION_HEADER}" \
177180
--url "https://api.github.com/app/installations" | jq -r '.[0].id')
178181

179182
PR_TRIGGER_PAT=$(curl --request POST \
180183
--url "https://api.github.com/app/installations/${INSTALLATION_ID}/access_tokens" \
181-
-H "Accept: application/vnd.github+json" \
184+
-H "${GH_ACCEPT_HEADER}" \
182185
-H "Authorization: Bearer ${JWT}" \
183-
-H "X-GitHub-Api-Version: 2022-11-28" | jq -r '.token')
186+
-H "${GH_API_VERSION_HEADER}" | jq -r '.token')
184187

185188
# Set default values if not provided
186189
if [[ -z "$PR_TRIGGER_PAT" ]]; then
@@ -243,9 +246,9 @@ echo "[INFO] Triggering workflow '$targetWorkflow' in nhs-notify-internal..."
243246
trigger_response=$(curl -s -L \
244247
--fail \
245248
-X POST \
246-
-H "Accept: application/vnd.github+json" \
249+
-H "${GH_ACCEPT_HEADER}" \
247250
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
248-
-H "X-GitHub-Api-Version: 2022-11-28" \
251+
-H "${GH_API_VERSION_HEADER}" \
249252
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/$targetWorkflow/dispatches" \
250253
-d "$DISPATCH_EVENT" 2>&1)
251254

@@ -264,9 +267,9 @@ workflow_run_url=""
264267
for _ in {1..18}; do
265268

266269
response=$(curl -s -L \
267-
-H "Accept: application/vnd.github+json" \
270+
-H "${GH_ACCEPT_HEADER}" \
268271
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
269-
-H "X-GitHub-Api-Version: 2022-11-28" \
272+
-H "${GH_API_VERSION_HEADER}" \
270273
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch")
271274

272275
if ! echo "$response" | jq empty 2>/dev/null; then
@@ -318,7 +321,7 @@ while true; do
318321
sleep 10
319322
response=$(curl -s -L \
320323
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
321-
-H "Accept: application/vnd.github+json" \
324+
-H "${GH_ACCEPT_HEADER}" \
322325
"$workflow_run_url")
323326

324327
status=$(echo "$response" | jq -r '.status')

.github/workflows/cicd-3-deploy.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ on:
1818
run-name: "Include prerelease: ${{ inputs.include_prereleases }} Version: ${{ inputs.version }} by @${{ github.actor }}"
1919
permissions:
2020
contents: read
21-
pages: write
22-
id-token: write
2321

2422
jobs:
2523
metadata:
@@ -66,6 +64,10 @@ jobs:
6664
make list-variables
6765
6866
deploy-jekyll:
67+
permissions:
68+
contents: read
69+
pages: write
70+
id-token: write
6971
environment:
7072
name: github-pages
7173
url: ${{ steps.deployment.outputs.page_url }}

docs/assets/js/nhs-notify.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// Quick poc for view full screen
22

3-
window.addEventListener("load", (event) => {
4-
var fullScreenParamName = "fullscreen";
5-
var urlParams = new URLSearchParams(document.location.search);
6-
var param = urlParams.get(fullScreenParamName);
3+
window.addEventListener("load", () => {
4+
const fullScreenParamName = "fullscreen";
5+
const urlParams = new URLSearchParams(document.location.search);
6+
const param = urlParams.get(fullScreenParamName);
77
if (param) {
88
tempViewFullScreen();
99
} else {
1010
setViewAtStart();
1111
}
1212
});
1313

14-
let nhsNotify = nhsNotifyDefaults();
14+
const nhsNotify = nhsNotifyDefaults();
1515

1616
function nhsNotifyDefaults() {
17-
var defaults = {};
17+
const defaults = {};
1818
defaults.storageName = "cb-checked";
1919
defaults.buttonName = "fullScreenButton";
2020
defaults.standard = "Standard";
@@ -24,16 +24,16 @@ function nhsNotifyDefaults() {
2424

2525
function tempViewFullScreen() {
2626
viewFullScreen();
27-
var buttons = document.getElementsByName(nhsNotify.buttonName);
27+
const buttons = document.getElementsByName(nhsNotify.buttonName);
2828
buttons.forEach((item) => {
2929
item.style.display = "none";
3030
});
3131
}
3232

3333
function viewFullScreen() {
34-
var sideBar = document.getElementsByClassName("side-bar")[0];
35-
var main = document.getElementsByClassName("main")[0];
36-
var pageInfo = document.getElementsByClassName("page-info")[0];
34+
const sideBar = document.getElementsByClassName("side-bar")[0];
35+
const main = document.getElementsByClassName("main")[0];
36+
const pageInfo = document.getElementsByClassName("page-info")[0];
3737
sideBar.style.display = "none";
3838
main.style.maxWidth = "100%";
3939
main.style.marginLeft = "0px";
@@ -45,9 +45,9 @@ function setFullScreen() {
4545
}
4646

4747
function setStandard() {
48-
var sideBar = document.getElementsByClassName("side-bar")[0];
49-
var main = document.getElementsByClassName("main")[0];
50-
var pageInfo = document.getElementsByClassName("page-info")[0];
48+
const sideBar = document.getElementsByClassName("side-bar")[0];
49+
const main = document.getElementsByClassName("main")[0];
50+
const pageInfo = document.getElementsByClassName("page-info")[0];
5151
sideBar.style.display = "";
5252
main.style.maxWidth = "";
5353
main.style.marginLeft = "";
@@ -56,7 +56,7 @@ function setStandard() {
5656
}
5757

5858
function setViewAtStart() {
59-
var currentStatus = localStorage.getItem(nhsNotify.storageName);
59+
const currentStatus = localStorage.getItem(nhsNotify.storageName);
6060
if (currentStatus == nhsNotify.fullScreen) makeChange(currentStatus);
6161
}
6262

@@ -69,41 +69,27 @@ function makeChange(newStatus) {
6969
}
7070

7171
function afterChange(currentStatus, newStatus) {
72-
var storageName = nhsNotify.storageName;
73-
var buttonName = nhsNotify.buttonName;
74-
var buttons = document.getElementsByName(buttonName);
75-
localStorage.setItem(storageName, newStatus);
72+
const buttons = document.getElementsByName(nhsNotify.buttonName);
73+
localStorage.setItem(nhsNotify.storageName, newStatus);
7674

7775
buttons.forEach((item) => {
7876
item.textContent = currentStatus + " View";
7977
});
8078
}
8179

8280
function fullScreenToggle() {
83-
var standard = nhsNotify.standard;
84-
var fullScreen = nhsNotify.fullScreen;
85-
var storageName = nhsNotify.storageName;
86-
var currentStatus = "";
87-
var newStatus = "";
88-
89-
currentStatus = localStorage.getItem(storageName);
81+
const { standard, fullScreen, storageName } = nhsNotify;
82+
let currentStatus = localStorage.getItem(storageName);
9083

9184
if (
9285
currentStatus == "false" ||
9386
currentStatus == "undefined" ||
9487
currentStatus == null
9588
) {
9689
currentStatus = standard;
97-
newStatus = fullScreen;
9890
}
9991

100-
if (currentStatus == standard) {
101-
newStatus = fullScreen;
102-
currentStatus = standard;
103-
} else {
104-
newStatus = standard;
105-
currentStatus = fullScreen;
106-
}
92+
const newStatus = currentStatus == standard ? fullScreen : standard;
10793

10894
makeChange(newStatus);
10995
}

0 commit comments

Comments
 (0)