Skip to content

Commit

Permalink
Revert "Merge branch 'devel' into feat/topsis_risk_assessment"
Browse files Browse the repository at this point in the history
This reverts commit 98a3bcb, reversing
changes made to 8e26cfe.
  • Loading branch information
FredericDymko committed Sep 21, 2023
1 parent 98a3bcb commit 62fdcdc
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 262 deletions.
6 changes: 2 additions & 4 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ OTTM_CURRENT_BRANCH=devel
OTTM_SOURCE_REPO_URL=https://github.com/dbeaver/dbeaver
# Either "github" or "gitlab", other SCM are not yet supported
OTTM_SOURCE_REPO_SCM=github
# Consider all tags as versions. If False, will only take releases
OTTM_SCM_USE_ALL_TAGS=False
# SCM base URL - leave empty for public repo
OTTM_SCM_BASE_URL=
# Token to access github or gitlab
Expand Down Expand Up @@ -68,8 +66,8 @@ OTTM_LEGACY_MINIMUM_DAYS=365
# The number of seconds to wait after a failed API call due to a limit of calls exceeded
OTTM_RETRY_DELAY=3600

# The url for Survey API
SURVEY_BACK_API_URL=http://localhost:8000/
# The url for survey api
SURVEY_BACK_API_URL="http://localhost:8000/"
# The name of the project for Survey API
SURVEY_PROJECT_NAME=

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim
FROM python:3.10-slim

RUN useradd --create-home --shell /bin/bash optittm-user

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ For each release the tool will:

### Prerequisites

- Python >= 3.11 to run BugPrediction or Docker
- A project in Java, PHP or Python
- A project in Java or PHP
- Source code on GitHub or GitLab
- Project releases and issues on GitHub, GitLab, Jira or other
- To analyse a Java project, have Java >= 8 installed
Expand Down
84 changes: 29 additions & 55 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,53 @@

AVAILABLE_SCM = ["github", "gitlab"]


class Configuration:

next_version_name = "Next Release"

def __init__(self):

self.log_level = self.__get_log_level("OTTM_LOG_LEVEL")

self.code_maat_path = self.__get_external_tool("OTTM_CODE_MAAT_PATH")
self.code_ck_path = self.__get_external_tool("OTTM_CODE_CK_PATH")
self.code_maat_path = self.__get_external_tool("OTTM_CODE_MAAT_PATH")
self.code_ck_path = self.__get_external_tool("OTTM_CODE_CK_PATH")
self.code_jpeek_path = self.__get_external_tool("OTTM_CODE_JPEEK_PATH")
self.code_pdepend_path = self.__get_external_tool("OTTM_CODE_PDEPEND_PATH")

self.language = os.getenv("OTTM_LANGUAGE", "")

self.scm_path = self.__get_executable("OTTM_SCM_PATH")
self.scm_path = self.__get_executable("OTTM_SCM_PATH")
if self.language.lower() == "java":
self.java_path = self.__get_executable("OTTM_JAVA_PATH")
elif self.language.lower() == "php":
self.php_path = self.__get_executable("OTTM_PHP_PATH")

self.target_database = self.__get_required_value("OTTM_TARGET_DATABASE")

self.source_repo_scm = self.__get_repo_scm("OTTM_SOURCE_REPO_SCM")
self.use_all_tags = self.__get_bool("OTTM_SCM_USE_ALL_TAGS", False)
self.source_project = self.__get_required_value("OTTM_SOURCE_PROJECT")
self.source_repo = self.__get_required_value("OTTM_SOURCE_REPO")
self.current_branch = self.__get_required_value("OTTM_CURRENT_BRANCH")
self.source_repo_url = self.__get_required_value("OTTM_SOURCE_REPO_URL")
self.source_bugs = self.__get_str_list("OTTM_SOURCE_BUGS")
self.source_bugs = self.__get_str_list("OTTM_SOURCE_BUGS")

self.survey_back_api_url = os.getenv("SURVEY_BACK_API_URL", "")
self.survey_back_api_url = os.getenv("SURVEY_BACK_API_URL","")
self.survey_project_name = self.__get_str_list("SURVEY_PROJECT_NAME")
self.scm_base_url = os.getenv("OTTM_SCM_BASE_URL", "")
self.scm_token = os.getenv("OTTM_SCM_TOKEN", "")
self.scm_issues_labels = os.getenv("OTTM_SCM_ISSUES_LABELS", "")

self.jira_base_url = os.getenv("OTTM_JIRA_BASE_URL", "")
self.jira_project = os.getenv("OTTM_JIRA_PROJECT", "")
self.jira_email = os.getenv("OTTM_JIRA_EMAIL", "")
self.jira_token = os.getenv("OTTM_JIRA_TOKEN", "")
self.scm_base_url = os.getenv("OTTM_SCM_BASE_URL", "")
self.scm_token = os.getenv("OTTM_SCM_TOKEN", "")

self.jira_base_url = os.getenv("OTTM_JIRA_BASE_URL", "")
self.jira_project = os.getenv("OTTM_JIRA_PROJECT", "")
self.jira_email = os.getenv("OTTM_JIRA_EMAIL", "")
self.jira_token = os.getenv("OTTM_JIRA_TOKEN", "")
self.jira_issue_type = self.__get_str_list("OTTM_JIRA_ISSUE_TYPE")

self.glpi_categories = self.__get_str_list("OTTM_GLPI_CATEGORIES")
self.glpi_base_url = os.getenv("OTTM_GLPI_BASE_URL", "")
self.glpi_app_token = os.getenv("OTTM_GLPI_APP_TOKEN", "")
self.glpi_base_url = os.getenv("OTTM_GLPI_BASE_URL", "")
self.glpi_app_token = os.getenv("OTTM_GLPI_APP_TOKEN", "")
self.glpi_user_token = os.getenv("OTTM_GLPI_USER_TOKEN", "")
self.glpi_username = os.getenv("OTTM_GLPI_USERNAME", "")
self.glpi_password = os.getenv("OTTM_GLPI_PASSWORD", "")
self.glpi_username = os.getenv("OTTM_GLPI_USERNAME", "")
self.glpi_password = os.getenv("OTTM_GLPI_PASSWORD", "")

self.issue_tags = self.__get_str_list("OTTM_ISSUE_TAGS")
self.exclude_issuers = self.__get_str_list("OTTM_EXCLUDE_ISSUERS")
Expand All @@ -72,7 +71,7 @@ def __init__(self):
self.insignificant_commits_message = self.__get_str_list("OTTM_COMMIT_BAD_MSG")

self.retry_delay = self.__get_retry_delay("OTTM_RETRY_DELAY")

self.legacy_percent = self.__get_float("OTTM_LEGACY_PERCENT", 20)

self.legacy_minimum_days = self.__get_int("OTTM_LEGACY_MINIMUM_DAYS", 365)
Expand Down Expand Up @@ -101,37 +100,27 @@ def __get_log_level(env_var):
elif required_level == "NOTSET":
log_level = logging.NOTSET
else:
raise ConfigurationValidationException(
f"Invalid value for log level: {required_level}"
)
raise ConfigurationValidationException(f"Invalid value for log level: {required_level}")

return log_level

@staticmethod
def __get_external_tool(env_var):
if env_var not in os.environ:
raise ConfigurationValidationException(
f"No external tool specified for ${env_var}"
)
raise ConfigurationValidationException(f"No external tool specified for ${env_var}")
file_path = os.environ[env_var]
if not os.path.exists(file_path):
raise ConfigurationValidationException(
f"The following external tool was not found: {file_path}"
)
raise ConfigurationValidationException(f"The following external tool was not found: {file_path}")
return file_path

@staticmethod
def __get_executable(env_var):
if env_var not in os.environ:
raise ConfigurationValidationException(
f"No executable specified for ${env_var}"
)
raise ConfigurationValidationException(f"No executable specified for ${env_var}")
executable = os.environ[env_var]
executable_found = shutil.which(executable)
if not executable_found:
raise ConfigurationValidationException(
f"The following executable was not found: {executable}"
)
raise ConfigurationValidationException(f"The following executable was not found: {executable}")
return executable

@staticmethod
Expand All @@ -141,8 +130,8 @@ def __get_repo_scm(env_var) -> str:
raise ConfigurationValidationException(f"No source code manager specified")
if repo_scm not in AVAILABLE_SCM:
raise ConfigurationValidationException(
f"The following source code manager is not handled by OTTM : {repo_scm}."
+ f" Availables SCM are : {AVAILABLE_SCM}"
f"The following source code manager is not handled by OTTM : {repo_scm}." +\
f" Availables SCM are : {AVAILABLE_SCM}"
)
return repo_scm

Expand Down Expand Up @@ -175,7 +164,7 @@ def __get_float(env_var, default):
)
return parsed_float

@staticmethod
@staticmethod
def __get_int(env_var, default):
parsed_value = os.getenv(env_var)
if parsed_value is None:
Expand Down Expand Up @@ -205,18 +194,3 @@ def __get_required_value(env_var):
if not value:
raise ConfigurationValidationException(f"Value for {env_var} is required")
return value

@staticmethod
def __get_bool(env_var, default):
parsed_value = os.getenv(env_var)
if parsed_value is None:
return default
if parsed_value.lower() == "true":
parsed_bool = True
elif parsed_value.lower() == "false":
parsed_bool = False
else:
raise ConfigurationValidationException(
f"Incorrect value : {parsed_value}, {env_var} should be a boolean"
)
return parsed_bool
2 changes: 1 addition & 1 deletion connectors/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,5 @@ def _get_issues(self, since, labels):
raise NotImplementedError

@abstractmethod
def _get_git_versions(self, all, order_by, sort):
def _get_releases(self, all, order_by, sort):
raise NotImplementedError
46 changes: 14 additions & 32 deletions connectors/github.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from time import sleep, time
from typing import List, Union
import github

from sqlalchemy import desc, update
Expand All @@ -9,9 +8,6 @@
from models.issue import Issue
from models.version import Version
from github import Github
from github.GitRelease import GitRelease
from github.Tag import Tag
from github.PaginatedList import PaginatedList
import datetime
from connectors.git import GitConnector
from utils.timeit import timeit
Expand All @@ -36,14 +32,12 @@ def _get_issues(self, since=None, labels=None):
labels = github.GithubObject.NotSet

try:
return self.remote.get_issues(state="all", labels=labels)
return self.remote.get_issues(state="all", since=since, labels=labels)
except github.GithubException.RateLimitExceededException:
sleep(self.configuration.retry_delay)
self._get_issues(since, labels)

def _get_git_versions(
self, all=None, order_by=None, sort=None
) -> List[Union[GitRelease, Tag]]:
def _get_releases(self, all=None, order_by=None, sort=None):
if not all:
all = None
if not order_by:
Expand All @@ -52,13 +46,10 @@ def _get_git_versions(
sort = None

try:
if self.configuration.use_all_tags:
return self.remote.get_tags()
else:
return self.remote.get_releases()
return self.remote.get_releases()
except github.GithubException.RateLimitExceededException:
sleep(self.configuration.retry_delay)
self._get_git_versions(all, order_by, sort)
self._get_releases(all, order_by, sort)

@timeit
def create_issues(self):
Expand All @@ -77,7 +68,7 @@ def create_issues(self):
)
if last_issue is not None:
# Update existing database by fetching new issues
if len(self.configuration.issue_tags) == 0:
if not self.configuration.issue_tags:
git_issues = self._get_issues(
since=last_issue.updated_at + datetime.timedelta(seconds=1)
)
Expand All @@ -88,7 +79,7 @@ def create_issues(self):
) # e.g. Filter by labels=['bug']
else:
# Create a database with all issues
if len(self.configuration.issue_tags) == 0:
if not self.configuration.issue_tags:
git_issues = self._get_issues()
else:
git_issues = self._get_issues(
Expand Down Expand Up @@ -138,7 +129,7 @@ def create_versions(self):
Create versions into the database from GitHub tags
"""
logging.info("GitHubConnector: create_versions")
git_versions = self._get_git_versions()
releases = self._get_releases()
self._clean_project_existing_versions()

versions = []
Expand All @@ -148,34 +139,25 @@ def create_versions(self):
forks = list(self.remote.get_forks())
subscribers = list(self.remote.get_subscribers())

for v in git_versions.reversed:
if type(v) is GitRelease:
v_name = v.title
v_tag = v.tag_name
v_end_date = v.published_at
elif type(v) is Tag:
v_name = v.name
v_tag = v.name
v_end_date = v.commit.commit.committer.date

for release in releases.reversed:
# Set UTC Timezone for previous release and release published_at when they are None
if previous_release_published_at.tzinfo is None:
previous_release_published_at = (
previous_release_published_at.astimezone(datetime.timezone.utc)
)

if v_end_date.tzinfo is None:
release_published_at_timezone = v_end_date.astimezone(
if release.published_at.tzinfo is None:
release_published_at_timezone = release.published_at.astimezone(
datetime.timezone.utc
)

versions.append(
Version(
project_id=self.project_id,
name=v_name,
tag=v_tag,
name=release.title,
tag=release.tag_name,
start_date=previous_release_published_at,
end_date=v_end_date,
end_date=release.published_at,
stars=len(
list(
filter(
Expand Down Expand Up @@ -222,7 +204,7 @@ def create_versions(self):
),
)
)
previous_release_published_at = v_end_date
previous_release_published_at = release.published_at

# Put current branch at the end of the list
# Set UTC Timezone for previous release published_at when it's None
Expand Down
Loading

0 comments on commit 62fdcdc

Please sign in to comment.