Minor fixes
parent
1822198549
commit
25bcb855c1
|
@ -66,7 +66,7 @@ def is_user_already_registered(*, username:str, email:str, github_id:int=None) -
|
|||
return (True, _("Email is already in use."))
|
||||
|
||||
if github_id and user_model.objects.filter(github_id=github_id):
|
||||
return (True, _("Github id is already in use"))
|
||||
return (True, _("GitHub id is already in use"))
|
||||
|
||||
return (False, None)
|
||||
|
||||
|
|
|
@ -14,26 +14,19 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import hmac
|
||||
import hashlib
|
||||
|
||||
from rest_framework.exceptions import ParseError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from taiga.base.api.viewsets import GenericViewSet
|
||||
from taiga.base import exceptions as exc
|
||||
from taiga.base.utils import json
|
||||
from taiga.projects.models import Project
|
||||
|
||||
from . import event_hooks
|
||||
from .exceptions import ActionSyntaxException
|
||||
|
||||
|
||||
class Http400(APIException):
|
||||
status_code = 400
|
||||
import hmac
|
||||
import hashlib
|
||||
|
||||
|
||||
class GitHubViewSet(GenericViewSet):
|
||||
|
@ -79,17 +72,17 @@ class GitHubViewSet(GenericViewSet):
|
|||
def create(self, request, *args, **kwargs):
|
||||
project = self._get_project(request)
|
||||
if not project:
|
||||
raise Http400(_("The project doesn't exist"))
|
||||
raise exc.BadRequest(_("The project doesn't exist"))
|
||||
|
||||
if not self._validate_signature(project, request):
|
||||
raise Http400(_("Bad signature"))
|
||||
raise exc.BadRequest(_("Bad signature"))
|
||||
|
||||
event_name = request.META.get("HTTP_X_GITHUB_EVENT", None)
|
||||
|
||||
try:
|
||||
payload = json.loads(request.body.decode("utf-8"))
|
||||
except ValueError as e:
|
||||
raise Http400(_("The payload is not a valid json"))
|
||||
except ValueError:
|
||||
raise exc.BadRequest(_("The payload is not a valid json"))
|
||||
|
||||
event_hook_class = self.event_hook_classes.get(event_name, None)
|
||||
if event_hook_class is not None:
|
||||
|
@ -97,6 +90,6 @@ class GitHubViewSet(GenericViewSet):
|
|||
try:
|
||||
event_hook.process_event()
|
||||
except ActionSyntaxException as e:
|
||||
raise Http400(e)
|
||||
raise exc.BadRequest(e)
|
||||
|
||||
return Response({})
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import re
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from taiga.projects.models import Project, IssueStatus, TaskStatus, UserStoryStatus
|
||||
|
@ -29,8 +27,10 @@ from taiga.projects.notifications.services import send_notifications
|
|||
from .exceptions import ActionSyntaxException
|
||||
from .services import get_github_user
|
||||
|
||||
class BaseEventHook(object):
|
||||
import re
|
||||
|
||||
|
||||
class BaseEventHook:
|
||||
def __init__(self, project, payload):
|
||||
self.project = project
|
||||
self.payload = payload
|
||||
|
@ -40,7 +40,6 @@ class BaseEventHook(object):
|
|||
|
||||
|
||||
class PushEventHook(BaseEventHook):
|
||||
|
||||
def process_event(self):
|
||||
if self.payload is None:
|
||||
return
|
||||
|
@ -93,12 +92,14 @@ class PushEventHook(BaseEventHook):
|
|||
element.status = status
|
||||
element.save()
|
||||
|
||||
snapshot = take_snapshot(element, comment="Status changed from Github commit", user=get_github_user(github_user))
|
||||
snapshot = take_snapshot(element,
|
||||
comment="Status changed from GitHub commit",
|
||||
user=get_github_user(github_user))
|
||||
send_notifications(element, history=snapshot)
|
||||
|
||||
|
||||
def replace_github_references(project_url, wiki_text):
|
||||
template = "\g<1>[Github#\g<2>]({}/issues/\g<2>)\g<3>".format(project_url)
|
||||
template = "\g<1>[GitHub#\g<2>]({}/issues/\g<2>)\g<3>".format(project_url)
|
||||
return re.sub(r"(\s|^)#(\d+)(\s|$)", template, wiki_text, 0, re.M)
|
||||
|
||||
|
||||
|
@ -129,9 +130,10 @@ class IssuesEventHook(BaseEventHook):
|
|||
)
|
||||
take_snapshot(issue, user=get_github_user(github_user))
|
||||
|
||||
snapshot = take_snapshot(issue, comment="Created from Github", user=get_github_user(github_user))
|
||||
snapshot = take_snapshot(issue, comment="Created from GitHub", user=get_github_user(github_user))
|
||||
send_notifications(issue, history=snapshot)
|
||||
|
||||
|
||||
class IssueCommentEventHook(BaseEventHook):
|
||||
def process_event(self):
|
||||
if self.payload.get('action', None) != "created":
|
||||
|
@ -151,5 +153,7 @@ class IssueCommentEventHook(BaseEventHook):
|
|||
uss = UserStory.objects.filter(external_reference=["github", github_reference])
|
||||
|
||||
for item in list(issues) + list(tasks) + list(uss):
|
||||
snapshot = take_snapshot(item, comment="From Github:\n\n{}".format(comment_message), user=get_github_user(github_user))
|
||||
snapshot = take_snapshot(item,
|
||||
comment="From GitHub:\n\n{}".format(comment_message),
|
||||
user=get_github_user(github_user))
|
||||
send_notifications(item, history=snapshot)
|
||||
|
|
|
@ -15,7 +15,7 @@ def create_github_system_user(apps, schema_editor):
|
|||
user = User.objects.using(db_alias).create(
|
||||
username="github-{}".format(random_hash),
|
||||
email="github-{}@taiga.io".format(random_hash),
|
||||
full_name="Github",
|
||||
full_name="GitHub",
|
||||
is_active=False,
|
||||
is_system=True,
|
||||
bio="",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# This file is needed to load migrations
|
|
@ -21,7 +21,7 @@ class SemiSaneListExtension(markdown.Extension):
|
|||
the sane_lists extension, GitHub will mix list types if they're not
|
||||
separated by multiple newlines.
|
||||
|
||||
Github also recognizes lists that start in the middle of a paragraph. This
|
||||
GitHub also recognizes lists that start in the middle of a paragraph. This
|
||||
is currently not supported by this extension, since the Python parser has a
|
||||
deeply-ingrained belief that blocks are always separated by multiple
|
||||
newlines.
|
||||
|
|
|
@ -131,7 +131,7 @@ from taiga.projects.notifications.api import NotifyPolicyViewSet
|
|||
|
||||
router.register(r"notify-policies", NotifyPolicyViewSet, base_name="notifications")
|
||||
|
||||
# Github webhooks
|
||||
# GitHub webhooks
|
||||
from taiga.github_hook.api import GitHubViewSet
|
||||
router.register(r"github-hook", GitHubViewSet, base_name="github-hook")
|
||||
|
||||
|
|
Loading…
Reference in New Issue