-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from CitoEngine/develop
Develop
- Loading branch information
Showing
24 changed files
with
18,275 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ after_success: | |
notifications: | ||
email: | ||
- sysadmin@citoengine.org | ||
|
||
sudo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.0.0" | ||
__version__ = "1.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals, absolute_import | ||
import logging | ||
from django import forms | ||
from django.conf import settings | ||
from jira import JIRA | ||
import jira.resources | ||
|
||
logger = logging.getLogger('main') | ||
|
||
|
||
class JIRAForm(forms.Form): | ||
|
||
project = forms.ChoiceField(label='JIRA Project', required=True) | ||
summary = forms.CharField(label='Ticket Summary', max_length=100) | ||
description = forms.CharField(widget=forms.Textarea) | ||
issue_type = forms.ChoiceField(label='Issue Type', required=True) | ||
component = forms.ChoiceField(label='Component', required=True) | ||
incident_id = forms.IntegerField() | ||
confirm = forms.BooleanField(label='Confirm', required=True) | ||
|
||
def get_choice_fields(self, opt): | ||
opt_string = settings.JIRA_OPTS.get(opt) | ||
if ',' in opt_string: | ||
opt_string = opt_string.split(',') | ||
else: | ||
opt_string = [opt_string] | ||
|
||
CHOICES = [] | ||
for p in opt_string: | ||
CHOICES.append([p.strip(), p.strip()]) | ||
|
||
return CHOICES | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(JIRAForm, self).__init__(*args, **kwargs) | ||
# Create choicefield for projects | ||
self.fields['project'].choices = self.get_choice_fields('PROJECTS') | ||
self.fields['component'].choices = self.get_choice_fields('COMPONENTS') | ||
self.fields['issue_type'].choices = self.get_choice_fields('ISSUE_TYPES') | ||
|
||
def create_jira(self, username): | ||
options = { | ||
'server': '%s' % settings.JIRA_OPTS['URL'], | ||
'verify': settings.JIRA_OPTS.get('VERIFY_SSL', False) | ||
} | ||
project = self.cleaned_data.get('project') | ||
summary = self.cleaned_data.get('summary') | ||
issue_type = self.cleaned_data.get('issue_type') | ||
component = self.cleaned_data.get('component') | ||
description = self.cleaned_data.get('description') | ||
description += '*JIRA Created by:* %s' % username | ||
|
||
try: | ||
jconn = JIRA(options, basic_auth=(settings.JIRA_OPTS['USER'], settings.JIRA_OPTS['PASSWORD'])) | ||
except Exception as e: | ||
logger.error('Error creating JIRA ticket :%s' % e) | ||
raise forms.ValidationError(u"Error connecting to JIRA ticket, please check the server logs") | ||
|
||
try: | ||
jira_ticket = jconn.create_issue(project=project, summary=summary, description=description, | ||
issuetype={'name': issue_type}, components=[{'name': component}]) | ||
except Exception as e: | ||
logger.error('Error creating JIRA ticket project=%s, summary=%s, issue_type=%s, description=%s,' % (project, | ||
summary, | ||
issue_type, | ||
description)) | ||
logger.error('Server message %s' % e) | ||
msg = u"Error creating JIRA ticket, please check the project name and issue type. If that doesn't work then check the server logs" | ||
raise forms.ValidationError(msg) | ||
|
||
if isinstance(jira_ticket, jira.resources.Issue): | ||
return jira_ticket.key | ||
else: | ||
raise forms.ValidationError(u"Error creating JIRA ticket, JIRA server did not return a ticket key.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from django.conf import settings | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('cito_engine', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='JIRATickets', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('ticket', models.CharField(max_length=64, verbose_name=b'JIRA Ticket ID')), | ||
('creation_time', models.DateTimeField(auto_now_add=True)), | ||
('incident', models.ForeignKey(to='cito_engine.Incident')), | ||
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals, absolute_import | ||
import logging | ||
from django.views.generic.edit import FormView, View | ||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.shortcuts import redirect | ||
from cito_engine.forms.jira_form import JIRAForm | ||
from cito_engine.models import JIRATickets, Incident | ||
from braces.views import LoginRequiredMixin | ||
|
||
|
||
class JIRAAddView(LoginRequiredMixin, FormView): | ||
""" | ||
View to add Supression | ||
""" | ||
template_name = 'generic_form.html' | ||
form_class = JIRAForm | ||
success_url = '/incidents/' | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(JIRAAddView, self).get_context_data(**kwargs) | ||
context['page_title'] = context['box_title'] = 'Add JIRA' | ||
return context | ||
|
||
def form_valid(self, form): | ||
try: | ||
incident = Incident.objects.get(pk=form.cleaned_data.get('incident_id')) | ||
except Incident.DoesNotExist, Incident.MultipleObjectsReturned: | ||
redirect('/incidents/') | ||
return | ||
try: | ||
ticket = form.create_jira(username=self.request.user.username) | ||
except Exception as e: | ||
return HttpResponse(status=500, content=e) | ||
JIRATickets.objects.create(user=self.request.user, incident=incident, ticket=ticket) | ||
return redirect('/incidents/view/%s/' % incident.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.