Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-to-build.txt ]; then pip install -r requirements-to-build.txt; fi
python -m pip install poetry
poetry install
- name: Build package
run: |
poetry build
continue-on-error: false
# Linting is done in the run_linters.sh script

- name: Prep tests
Expand All @@ -49,9 +53,10 @@ jobs:
- name: Run linters
working-directory: .
run: |
python -m pip install ruff pylint flake8
chmod +x conf/run_linters.sh
conf/run_linters.sh
#- name: Cache SonarQube packages
# - name: Cache SonarQube packages
# uses: actions/cache@v4
# with:
# path: ./.sonar
Expand Down
1 change: 0 additions & 1 deletion cli/projects_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

"""

import sys
import json

from requests import RequestException
Expand Down
4 changes: 3 additions & 1 deletion conf/prep_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ function create_fresh_project {
fi
curl -X POST -u "${usertoken}:" "${url}/api/projects/delete?project=${key}"
conf/run_scanner.sh "${opts[@]}" -Dsonar.projectKey="${key}" -Dsonar.projectName="${key}" -Dsonar.host.url="${url}" "${opt_token}" "${opt_org}"
conf/run_scanner.sh "${opts[@]}" -Dsonar.projectKey="${key}" -Dsonar.projectName="${key}" -Dsonar.host.url="${url}" "${opt_token}" "${opt_org}" -Dsonar.branch.name=develop
conf/run_scanner.sh "${opts[@]}" -Dsonar.projectKey="${key}" -Dsonar.projectName="${key}" -Dsonar.host.url="${url}" "${opt_token}" "${opt_org}" -Dsonar.branch.name=release-3.x
return 0
}

conf/run_linters.sh

create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_TEST:?}" "${SONAR_TOKEN_TEST_ADMIN_USER}" "${SONAR_TOKEN_TEST_ADMIN_ANALYSIS}" -nolint
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_TEST:?}" "${SONAR_TOKEN_TEST_ADMIN_USER}" "${SONAR_TOKEN_TEST_ADMIN_ANALYSIS}"
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_LATEST:?}" "${SONAR_TOKEN_LATEST_ADMIN_USER}" "${SONAR_TOKEN_LATEST_ADMIN_ANALYSIS}"
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_CB:?}" "${SONAR_TOKEN_CB_ADMIN_USER}" "${SONAR_TOKEN_CB_ADMIN_ANALYSIS}"
create_fresh_project "${SYNC_PROJECT_KEY}" "${SONAR_HOST_URL_9:?}" "${SONAR_TOKEN_9_ADMIN_USER}" "${SONAR_TOKEN_9_ADMIN_ANALYSIS}"
Expand Down
2 changes: 1 addition & 1 deletion conf/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ if [[ "${confirm}" = "y" ]]; then
cd "${ROOT_DIR}" && docker pushrm olivierkorach/sonar-tools

echo "Running scan"
"${CONF_DIR}/scan.sh" -test
"${CONF_DIR}/run_all.sh" -test
fi
2 changes: 1 addition & 1 deletion conf/run_linters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fi
if [[ "${localbuild}" = "true" ]]; then
if [[ "${linters_to_run}" == *"shellcheck"* ]]; then
echo "===> Running shellcheck"
shellcheck $(find "${ROOT_DIR}" . -name '*.sh') \
shellcheck "$(find "${ROOT_DIR}" . -name '*.sh')" \
-s bash -f json | jq | tee "${BUILD_DIR}/shellcheck-report.json" | "${CONF_DIR}"/shellcheck2sonar.py "${external_format}" > "${SHELLCHECK_REPORT}"
[[ ! -s "${SHELLCHECK_REPORT}" ]] && rm -f "${SHELLCHECK_REPORT}"
cat "${BUILD_DIR}/shellcheck-report.json"
Expand Down
2 changes: 1 addition & 1 deletion conf/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ do
if [[ -d "${ROOT_DIR}/${GEN_LOC}/${target}/" ]]; then
# Recreate a fresh TESTSYNC project for sync tests
curl -X POST -u "${SONAR_TOKEN_TEST_ADMIN_USER}:" "${SONAR_HOST_URL_TEST}/api/projects/delete?project=${SYNC_PROJECT_KEY}"
conf/scan.sh -nolint -Dsonar.host.url="${SONAR_HOST_URL_TEST}" -Dsonar.projectKey="${SYNC_PROJECT_KEY}" -Dsonar.projectName="${SYNC_PROJECT_KEY}" -Dsonar.token="${SONAR_TOKEN_TEST_ADMIN_ANALYSIS}"
conf/run_scanner.sh -Dsonar.host.url="${SONAR_HOST_URL_TEST}" -Dsonar.projectKey="${SYNC_PROJECT_KEY}" -Dsonar.projectName="${SYNC_PROJECT_KEY}" -Dsonar.token="${SONAR_TOKEN_TEST_ADMIN_ANALYSIS}"
# Run tests
poetry run coverage run --branch --source="${ROOT_DIR}" -m pytest "${ROOT_DIR}/${GEN_LOC}/${target}/" --junit-xml="${BUILD_DIR}/xunit-results-${target}.xml"
poetry run coverage xml -o "${BUILD_DIR}/coverage-${target}.xml"
Expand Down
8 changes: 0 additions & 8 deletions migration/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

build_image=1
release=0
release_docker=0

while [[ $# -ne 0 ]]; do
case "${1}" in
nodocker)
build_image=0
;;
pypi)
release=1
;;
dockerhub)
release_docker=1
;;
*)
;;
esac
Expand Down
18 changes: 9 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions sonar/app_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from typing import Optional

import json
from http import HTTPStatus
from requests import RequestException
from requests.utils import quote

import sonar.logging as log
Expand Down Expand Up @@ -112,11 +110,7 @@ def create(cls, app: object, name: str, project_branches: list[Branch]) -> Appli
else: # Default main branch of project
params["project"].append(obj.key)
params["projectBranch"].append("")
try:
app.endpoint.post(ApplicationBranch.API[c.CREATE], params=params)
except (ConnectionError, RequestException) as e:
utilities.handle_error(e, f"creating branch {name} of {str(app)}", catch_http_statuses=(HTTPStatus.BAD_REQUEST,))
raise exceptions.ObjectAlreadyExists(f"{str(app)} branch '{name}", e.response.text)
app.endpoint.post(ApplicationBranch.API[c.CREATE], params=params)
return ApplicationBranch(app=app, name=name, project_branches=project_branches)

@classmethod
Expand Down Expand Up @@ -201,10 +195,9 @@ def update(self, name: str, project_branches: list[Branch]) -> bool:
params["projectBranch"].append(br_name)
try:
ok = self.post(ApplicationBranch.API[c.UPDATE], params=params).ok
except (ConnectionError, RequestException) as e:
utilities.handle_error(e, f"updating {str(self)}", catch_http_statuses=(HTTPStatus.NOT_FOUND,))
except exceptions.ObjectNotFound:
ApplicationBranch.CACHE.pop(self)
raise exceptions.ObjectNotFound(str(self), e.response.text)
raise

self.name = name
self._project_branches = project_branches
Expand Down
17 changes: 4 additions & 13 deletions sonar/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ def get_object(cls, endpoint: pf.Platform, key: str) -> Application:
o = Application.CACHE.get(key, endpoint.local_url)
if o:
return o
try:
data = json.loads(endpoint.get(Application.API[c.GET], params={"application": key}).text)["application"]
except (ConnectionError, RequestException) as e:
util.handle_error(e, f"searching application {key}", catch_http_statuses=(HTTPStatus.NOT_FOUND,))
raise exceptions.ObjectNotFound(key, f"Application key '{key}' not found")
data = json.loads(endpoint.get(Application.API[c.GET], params={"application": key}).text)["application"]
return cls.load(endpoint, data)

@classmethod
Expand Down Expand Up @@ -132,11 +128,7 @@ def create(cls, endpoint: pf.Platform, key: str, name: str) -> Application:
:rtype: Application
"""
check_supported(endpoint)
try:
endpoint.post(Application.API["CREATE"], params={"key": key, "name": name})
except (ConnectionError, RequestException) as e:
util.handle_error(e, f"creating application {key}", catch_http_statuses=(HTTPStatus.BAD_REQUEST,))
raise exceptions.ObjectAlreadyExists(key, e.response.text)
endpoint.post(Application.API["CREATE"], params={"key": key, "name": name})
log.info("Creating object")
return Application(endpoint=endpoint, key=key, name=name)

Expand All @@ -151,10 +143,9 @@ def refresh(self) -> None:
self.reload(json.loads(self.get("navigation/component", params={"component": self.key}).text))
self.reload(json.loads(self.get(Application.API[c.GET], params=self.api_params(c.GET)).text)["application"])
self.projects()
except (ConnectionError, RequestException) as e:
util.handle_error(e, f"refreshing {str(self)}", catch_http_statuses=(HTTPStatus.NOT_FOUND,))
except exceptions.ObjectNotFound:
Application.CACHE.pop(self)
raise exceptions.ObjectNotFound(self.key, f"{str(self)} not found")
raise

def __str__(self) -> str:
"""String name of object"""
Expand Down
Loading