Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
add which_user method which detects pagure/github user based on ogr s…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
marusinm committed Jul 16, 2019
1 parent 38b14a0 commit cc9a4d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
23 changes: 15 additions & 8 deletions release_bot/releasebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def which_service(self):
return "Pagure"
return None

def which_username(self):
"""
Returns Github/Pagure username based on current project service
:return: str
"""
if self.which_service() == "Github":
return self.conf.github_username
elif self.which_service() == "Pagure":
return self.conf.pagure_username
return None

def find_open_release_issues(self):
"""
Looks for opened release issues on github
Expand All @@ -114,17 +126,12 @@ def find_open_release_issues(self):
for issue in opened_issues:
match, version = process_version_from_title(issue.title, latest_version)
if match:
if (self.project.can_close_issue(self.conf.github_username, issue)
or self.project.can_close_issue(self.conf.pagure_username, issue)):
if self.project.can_close_issue(self.which_username(), issue):
release_issues[version] = issue
self.logger.info(f'Found new release issue with version: {version}')
else:
if self.which_service() == "Github":
self.logger.warning(f"User {self.conf.github_username } "
f"has no permission to modify issue")
else:
self.logger.warning(f"User {self.conf.pagure_username} "
f"has no permission to modify issue")
self.logger.warning(f"User {self.which_username()} "
f"has no permission to modify issue")

if len(release_issues) > 1:
msg = f'Multiple release issues are open {release_issues}, please reduce them to one'
Expand Down
9 changes: 9 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ def test_git_service(self):
git_service = self.release_bot.git_service
assert git_service == "Github"

def test_which_service(self):
git_service = self.release_bot.which_service()
assert git_service == "Github"

def test_which_username(self):
git_username = self.release_bot.which_username()
assert git_username == self.github_user
assert git_username == self.release_bot.conf.github_username

def test_find_open_rls_issue(self, open_issue):
"""Tests if bot can find opened release issue"""
assert self.release_bot.find_open_release_issues()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def setup_method(self):
# set conf
configuration.repository_name = self.g_utils.repo
configuration.github_username = self.g_utils.github_user
configuration.clone_url = f"https://github.com/{self.g_utils.github_user}/{self.g_utils.repo}.git"
configuration.refresh_interval = 1
configuration.project = configuration.get_project()

repo_url = f"https://github.com/{self.g_utils.github_user}/{self.g_utils.repo}"
git = Git(repo_url, configuration)
Expand Down

0 comments on commit cc9a4d6

Please sign in to comment.