##// END OF EJS Templates
setup: change url to github
setup: change url to github

File last commit:

r153:32f4b641
r196:472d1df0 master
Show More
hipchat.py
77 lines | 2.7 KiB | text/x-python | PythonLexer
project: initial commit
r0 # -*- coding: utf-8 -*-
license: change the license to Apache 2.0
r112 # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # http://www.apache.org/licenses/LICENSE-2.0
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
project: initial commit
r0
import logging
from datetime import datetime
from appenlight.models import DBSession
from appenlight.models.integrations.hipchat import HipchatIntegration
from pyramid.httpexceptions import HTTPUnprocessableEntity
from pyramid.view import view_config
from appenlight import forms
from webob.multidict import MultiDict
log = logging.getLogger(__name__)
from . import IntegrationView
class HipchatView(IntegrationView):
black: reformat source
r153 @view_config(
route_name="integrations_id",
match_param=["action=info", "integration=hipchat"],
renderer="json",
)
project: initial commit
r0 def get_info(self):
pass
black: reformat source
r153 @view_config(
route_name="integrations_id",
match_param=["action=setup", "integration=hipchat"],
renderer="json",
permission="edit",
)
project: initial commit
r0 def setup(self):
"""
Validates and creates integration between application and hipchat
"""
resource = self.request.context.resource
black: reformat source
r153 self.create_missing_channel(resource, "hipchat")
project: initial commit
r0 form = forms.IntegrationHipchatForm(
MultiDict(self.request.safe_json_body or {}),
black: reformat source
r153 csrf_context=self.request,
**self.integration_config
)
if self.request.method == "POST" and form.validate():
project: initial commit
r0 integration_config = {
black: reformat source
r153 "api_token": form.api_token.data,
"rooms": form.rooms.data,
project: initial commit
r0 }
if not self.integration:
# add new integration
black: reformat source
r153 self.integration = HipchatIntegration(modified_date=datetime.utcnow())
self.request.session.flash("Integration added")
project: initial commit
r0 resource.integrations.append(self.integration)
else:
black: reformat source
r153 self.request.session.flash("Integration updated")
project: initial commit
r0 self.integration.config = integration_config
DBSession.flush()
black: reformat source
r153 self.create_missing_channel(resource, "hipchat")
project: initial commit
r0 return integration_config
black: reformat source
r153 elif self.request.method == "POST":
project: initial commit
r0 return HTTPUnprocessableEntity(body=form.errors_json)
return self.integration_config