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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM alpine:3.20.3
LABEL maintainer="[email protected]"
ENV IN_DOCKER="Yes"

ARG USERNAME=sonar
ARG USER_UID=1000
Expand Down Expand Up @@ -33,7 +34,7 @@ RUN pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir --upgrade pip setuptools wheel \
&& python setup.py bdist_wheel \
&& pip install dist/*-py3-*.whl --force-reinstall
&& pip install dist/sonar_tools-*-py3-*.whl --force-reinstall

USER ${USERNAME}
WORKDIR /home/${USERNAME}
Expand Down
4 changes: 1 addition & 3 deletions cli/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
Exports SonarQube platform configuration as JSON
"""
import sys
import json
import yaml

from cli import options
from sonar import exceptions, errcodes, utilities
Expand Down Expand Up @@ -84,7 +82,7 @@ def __parse_args(desc):
f"By default the export will show the value as '{utilities.DEFAULT}' "
"and the setting will not be imported at import time",
)
args = options.parse_and_check(parser=parser, logger_name="sonar-migration")
args = options.parse_and_check(parser=parser, logger_name="sonar-migration", is_migration=True)
return args


Expand Down
9 changes: 7 additions & 2 deletions cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __check_file_writeable(file: str) -> None:
os.remove(file)


def parse_and_check(parser: ArgumentParser, logger_name: str = None, verify_token: bool = True) -> ArgumentParser:
def parse_and_check(parser: ArgumentParser, logger_name: str = None, verify_token: bool = True, is_migration: bool = False) -> ArgumentParser:
"""Parses arguments, applies default settings and perform common environment checks"""
try:
args = parser.parse_args()
Expand All @@ -187,7 +187,12 @@ def parse_and_check(parser: ArgumentParser, logger_name: str = None, verify_toke
log.set_logger(filename=kwargs[LOGFILE], logger_name=logger_name)
log.set_debug_level(kwargs[VERBOSE])
del kwargs[VERBOSE]
log.info("sonar-tools version %s", version.PACKAGE_VERSION)
if is_migration:
log.info("sonar-migration version %s", version.MIGRATION_TOOL_VERSION)
else:
log.info("sonar-tools version %s", version.PACKAGE_VERSION)
if os.getenv("IN_DOCKER", "No") == "Yes":
kwargs[URL] = kwargs[URL].replace("http://localhost", "http://host.docker.internal")
if log.get_level() == log.DEBUG:
sanitized_args = kwargs.copy()
sanitized_args[TOKEN] = utilities.redacted_token(sanitized_args[TOKEN])
Expand Down
2 changes: 1 addition & 1 deletion deploy-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ python3 setup_migration.py bdist_wheel
pip install --upgrade --force-reinstall dist/sonar_migration-*-py3-*.whl

if [ "$build_image" == "1" ]; then
docker build -t sonar-migration:latest .
docker build -t sonar-migration:latest -f migration.Dockerfile .
fi

if [ "$build_docs" == "1" ]; then
Expand Down
42 changes: 42 additions & 0 deletions migration.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM alpine:3.20.3
LABEL maintainer="[email protected]"
ENV IN_DOCKER="Yes"

ARG USERNAME=sonar
ARG USER_UID=1000
ARG GROUPNAME=sonar

# Create the user
RUN addgroup -S ${GROUPNAME} && adduser -u ${USER_UID} -S ${USERNAME} -G ${GROUPNAME}

# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python

# create a virtual environment and add it to PATH so that it is
# applied for all future RUN and CMD calls
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv ${VIRTUAL_ENV}
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

WORKDIR /opt/sonar-migration

COPY ./sonar sonar
COPY ./requirements.txt .
COPY ./cli cli
COPY ./setup_migration.py .
COPY ./sonar_migration .
COPY ./README.md .
COPY ./LICENSE .
COPY ./sonar/audit sonar/audit

RUN pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir --upgrade pip setuptools wheel \
&& python setup_migration.py bdist_wheel \
&& pip install dist/sonar_migration-py3-*.whl --force-reinstall

USER ${USERNAME}
WORKDIR /home/${USERNAME}

ENTRYPOINT ["sonar-migration"]
5 changes: 2 additions & 3 deletions setup_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
import setuptools
from sonar import version


with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="sonar-migration",
version=version.PACKAGE_VERSION,
version=version.MIGRATION_TOOL_VERSION,
scripts=["sonar_migration"],
author="Olivier Korach",
author_email="[email protected]",
description="A collection of utility scripts for SonarQube and SonarCloud",
description="A SonarQube collection tool to use in the context of SonarQube to SonarCloud migration",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/okorach/sonar-tools",
Expand Down
6 changes: 5 additions & 1 deletion sonar/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import sonar.platform as pf
from sonar.util.types import ApiParams, ApiPayload, ObjectJsonRepr, ConfigSettings

from sonar import users, syncer, sqobject, findings, changelog, projects
from sonar import users, sqobject, findings, changelog, projects
import sonar.utilities as util

API_SET_TAGS = "issues/set_tags"
Expand Down Expand Up @@ -430,6 +430,8 @@ def accept(self) -> bool:
return self.do_transition("accept")

def __apply_event(self, event: str, settings: ConfigSettings) -> bool:
from sonar import syncer

log.debug("Applying event %s", str(event))
# origin = f"originally by *{event['userName']}* on original branch"
(event_type, data) = event.changelog_type()
Expand Down Expand Up @@ -491,6 +493,8 @@ def apply_changelog(self, source_issue: Issue, settings: ConfigSettings) -> bool
"""
:meta private:
"""
from sonar import syncer

events = source_issue.changelog()
if events is None or not events:
log.debug("Sibling %s has no changelog, no action taken", source_issue.key)
Expand Down
6 changes: 4 additions & 2 deletions sonar/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from sonar.util import types

from sonar import exceptions, errcodes
from sonar import sqobject, components, qualitygates, qualityprofiles, rules, tasks, settings, webhooks, devops, syncer
from sonar import sqobject, components, qualitygates, qualityprofiles, tasks, settings, webhooks, devops
import sonar.permissions.permissions as perms
from sonar import pull_requests, branches
import sonar.utilities as util
Expand Down Expand Up @@ -799,6 +799,8 @@ def count_third_party_issues(self, filters: dict[str, str] = None) -> dict[str,

def __sync_community(self, another_project: object, sync_settings: types.ConfigSettings) -> tuple[list[dict[str, str]], dict[str, int]]:
"""Syncs 2 projects findings on a community edition"""
from sonar import syncer

report, counters = [], {}
log.info("Syncing %s and %s issues", str(self), str(another_project))
(report, counters) = syncer.sync_lists(
Expand Down Expand Up @@ -993,7 +995,7 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
"taskHistory": [t._json for t in self.task_history()],
}
json_data["thirdPartyIssues"] = self.count_third_party_issues()
log.info("%s has %d 3rd party issues", str(self), sum(v for v in json_data["thirdPartyIssues"].values()))
log.debug("%s has %d 3rd party issues", str(self), sum(v for v in json_data["thirdPartyIssues"].values()))

settings_dict = settings.get_bulk(endpoint=self.endpoint, component=self, settings_list=settings_list, include_not_set=False)
# json_data.update({s.to_json() for s in settings_dict.values() if include_inherited or not s.inherited})
Expand Down
1 change: 1 addition & 0 deletions sonar/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
"""

PACKAGE_VERSION = "3.4"
MIGRATION_TOOL_VERSION = "0.1"