Skip to content

Commit

Permalink
Remove support of tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Mar 6, 2024
1 parent 3cfd108 commit f019767
Show file tree
Hide file tree
Showing 18 changed files with 14 additions and 367 deletions.
4 changes: 0 additions & 4 deletions bert_e/bert_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def __init__(self, settings):
)
if settings.repository_host == 'bitbucket':
self.settings.robot.account_id = self.client.get_user_id()
if settings.repository_host == 'github':
if settings['tasks']:
LOG.warning("Disabling tasks on GitHub repo")
settings['tasks'] = []
self.project_repo = self.client.get_repository(
owner=settings.repository_owner,
slug=settings.repository_slug
Expand Down
22 changes: 0 additions & 22 deletions bert_e/git_host/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,8 @@ def key(self) -> str:
"""The build status key."""


class AbstractTask(metaclass=ABCMeta):
"""Abstract class defining a task's interface."""
# Empty, but used as a return value below


class AbstractComment(metaclass=ABCMeta):
"""Abstract class defining the interface of a pull requests's comment."""
@abstractmethod
def add_task(self, msg: str) -> AbstractTask:
"""Attach a new task attached to this comment.
Args:
- msg: the message of the task to attach.
Returns: the newly created task.
"""

@abstractmethod
def delete(self) -> None:
Expand Down Expand Up @@ -326,13 +311,6 @@ def get_approvals(self) -> Iterable[str]:
def get_participants(self) -> Iterable[str]:
"""Get the usernames of the participants to this pull request."""

@abstractmethod
def get_tasks(self) -> Iterable[AbstractTask]:
"""Get this pull request's tasks.
Returns: an iterable over the Task objects.
"""

@abstractmethod
def comment_review(self):
Expand Down
50 changes: 0 additions & 50 deletions bert_e/git_host/bitbucket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from . import schema
from .. import base, cache, factory
from bert_e.exceptions import TaskAPIError

MAX_PR_TITLE_LEN = 255

Expand Down Expand Up @@ -371,10 +370,6 @@ def get_comments(self, deleted=False):
key=lambda c: c.created_on
)

def get_tasks(self):
return Task.get_list(self.client, full_name=self.full_name(),
pull_request_id=self['id'])

def get_change_requests(self):
# Not supported by bitbucket, default to an empty tuple of usernames
return tuple()
Expand Down Expand Up @@ -489,11 +484,6 @@ def full_name(self):
p = Path(urlparse(self.data['links']['self']['href']).path).resolve()
return '%s/%s' % p.parts[3:5]

def add_task(self, msg):
return Task(self.client, content=msg, full_name=self.full_name(),
pull_request_id=self.data['pullrequest']['id'],
comment_id=self.id).create()

def delete(self):
return super().delete(self.client, full_name=self.full_name(),
pull_request_id=self.data['pullrequest']['id'],
Expand Down Expand Up @@ -524,46 +514,6 @@ def deleted(self):
return self.data['deleted']


class Task(BitBucketObject, base.AbstractTask):
get_url = 'https://bitbucket.org/!api/internal/repositories/$full_name/' \
'pullrequests/$pull_request_id/tasks/$task_id'
add_url = 'https://bitbucket.org/!api/internal/repositories/$full_name/' \
'pullrequests/$pull_request_id/tasks'
list_url = add_url + '?page=$page'

def __init__(self, client, **kwargs):
super().__init__(client, **kwargs)
if 'comment_id' in self._json_data:
self._json_data['comment'] = {'id': self._json_data['comment_id']}
if 'content' in self._json_data:
self._json_data['content'] = {'raw': self._json_data['content']}

def create(self, *args, **kwargs):
try:
return super().create(*args, **kwargs)
except Exception as err:
raise TaskAPIError('create', err)

def delete(self, *args, **kwargs):
try:
return super().delete(*args, **kwargs)
except Exception as err:
raise TaskAPIError('delete', err)

def get(self, *args, **kwargs):
try:
return super().get(*args, **kwargs)
except Exception as err:
raise TaskAPIError('get', err)

@classmethod
def get_list(self, *args, **kwargs):
try:
return list(super().get_list(*args, **kwargs))
except Exception as err:
raise TaskAPIError('get_list', err)


class BuildStatus(BitBucketObject, base.AbstractBuildStatus):
get_url = 'https://api.bitbucket.org/2.0/repositories/$owner/$repo_slug/' \
'commit/$revision/statuses/build/$key'
Expand Down
7 changes: 0 additions & 7 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from requests import HTTPError
from urllib.parse import quote_plus as quote

from bert_e.exceptions import TaskAPIError
from bert_e.lib.lru_cache import LRUCache
from . import schema
from .. import base, cache, factory
Expand Down Expand Up @@ -873,9 +872,6 @@ def comments(self):
def repo(self):
return Repository(**self.data['base']['repo'], client=self.client)

def get_tasks(self):
raise TaskAPIError("PullRequest.get_tasks", NotImplemented)

def get_reviews(self):
repo = self.repo
self._reviews = list(Review.list(
Expand Down Expand Up @@ -987,9 +983,6 @@ class Comment(base.AbstractGitHostObject, base.AbstractComment):
SCHEMA = schema.Comment
CREATE_SCHEMA = schema.CreateComment

def add_task(self, *args):
raise TaskAPIError("Comment.add_task", NotImplemented)

@property
def author(self) -> str:
return self.data['user']['login'].lower()
Expand Down
45 changes: 0 additions & 45 deletions bert_e/git_host/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import requests

from . import base
from ..exceptions import TaskAPIError
from ..lib.git import Branch as GitBranch
from ..lib.git import Repository as GitRepository
from .factory import api_client
Expand Down Expand Up @@ -181,7 +180,6 @@ def __init__(self, client, owner, repo_slug, scm='git', is_private=True):
def delete(self):
super().delete()
PullRequest.items = []
Task.items = []
Comment.items = []

def create(self):
Expand Down Expand Up @@ -280,11 +278,6 @@ def get_comments(self):
self.client, full_name=self.controlled.full_name(),
pull_request_id=self.controlled.id))

def get_tasks(self):
return [Controller(self.client, t) for t in Task.get_list(
self.client, full_name=self.controlled.full_name(),
pull_request_id=self.controlled.id)]

def merge(self):
raise NotImplementedError('Merge')

Expand Down Expand Up @@ -412,14 +405,6 @@ def comments(self):


class CommentController(Controller, base.AbstractComment):
def add_task(self, msg):
task = Task(self.client, content=msg,
full_name=self.controlled.full_name,
pr_id=self.controlled.pull_request_id,
comment_id=self.controlled.id).create()

PullRequest.items[self.controlled.pull_request_id - 1].task_count += 1
return task

def delete(self):
self.controlled.delete()
Expand Down Expand Up @@ -485,7 +470,6 @@ def __init__(self, repo, title, name, source, destination,
"commit": Branch(self.repo.gitrepo, source['branch']['name']),
"repository": fake_repository_dict("")
}
self.task_count = 0
self.title = title
self.type = "pullrequest"
self.updated_on = "2016-01-12T19:31:23.673329+00:00"
Expand Down Expand Up @@ -533,35 +517,6 @@ def get_list(client, full_name, pull_request_id):
c.pull_request_id == pull_request_id]


class Task(BitBucketObject, base.AbstractTask):
add_url = 'legit_add_url'
list_url = 'legit_list_url'
items = []

def __init__(self, client, content, pr_id, full_name, comment_id):
# URL params #
self.pull_request_id = pr_id
self.full_name = full_name
self.comment_id = comment_id

# JSON params #
self.content = {"raw": content}
self.id = len(Task.items)

def create(self):
if self.add_url != 'legit_add_url':
raise TaskAPIError('create', 'url does not work')
self.__class__.items.append(self)
return self

@staticmethod
def get_list(client, full_name, pull_request_id):
if Task.list_url != 'legit_list_url':
raise TaskAPIError('get_list', 'url does not work')
return [t for t in Task.items if t.full_name == full_name and
t.pull_request_id == pull_request_id]


class BuildStatus(BitBucketObject, base.AbstractBuildStatus):
pass

Expand Down
1 change: 0 additions & 1 deletion bert_e/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class Meta:
UserSettingSchema, many=True, load_default=[])
project_leaders = fields.Nested(
UserSettingSchema, many=True, load_default=[])
tasks = fields.List(fields.Str(), load_default=[])

max_commit_diff = fields.Int(required=False, load_default=0)

Expand Down
6 changes: 0 additions & 6 deletions bert_e/templates/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ pull request. {% if frontend_url
on this process, or consult the [user documentation](
{{ frontend_url }}/doc/user).{% endif %}

{% if tasks %}
I have created below the minimum set of tasks expected to be performed during
this review.
{% endif%}


{% if options %}
<details>
<summary><b>Available options</b></summary>
Expand Down
4 changes: 0 additions & 4 deletions bert_e/tests/assets/settings-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ admins:
- username_admin_1
- username_admin_2@557042:08898ca4-5f12-4042-9942-87e167728afd

tasks:
- do this
- do that

max_commit_diff: 100

always_create_integration_pull_requests: true
Expand Down
Loading

0 comments on commit f019767

Please sign in to comment.