create issue
This commit is contained in:
parent
e249fd54d2
commit
2773962b43
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2019-04-07 17:45
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('github', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='githubconnector',
|
||||
name='github_user',
|
||||
field=models.CharField(max_length=400, verbose_name='Github user'),
|
||||
),
|
||||
]
|
|
@ -23,11 +23,31 @@ from passerelle.utils.api import endpoint
|
|||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
||||
SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-03/schema#",
|
||||
"title": "Planitech create issue",
|
||||
"description": "",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"description": "title",
|
||||
"type": "string",
|
||||
"required": True
|
||||
},
|
||||
"description": {
|
||||
"description": "Description",
|
||||
"type": "string",
|
||||
"required": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GithubConnector(BaseResource):
|
||||
api_url = models.URLField(
|
||||
max_length=400, verbose_name=_('Github API endpoint'),
|
||||
help_text=_('Github API endpoint'))
|
||||
github_user = models.URLField(
|
||||
github_user = models.CharField(
|
||||
max_length=400, verbose_name=_('Github user'))
|
||||
github_repo = models.CharField(max_length=128, verbose_name=_('Github repo'))
|
||||
github_token = models.CharField(max_length=128, verbose_name=_('Github token'))
|
||||
|
@ -41,7 +61,7 @@ class GithubConnector(BaseResource):
|
|||
def getissue(self, request, issue_num):
|
||||
url = '%s/repos/%s/%s/issues/%s' % (
|
||||
self.api_url, self.github_user, self.github_repo, issue_num)
|
||||
response = self.requests(url, auth=(self.github_user, self.github_token))
|
||||
response = self.requests.get(url, auth=(self.github_user, self.github_token))
|
||||
|
||||
try:
|
||||
response.raise_for_status()
|
||||
|
@ -50,45 +70,37 @@ class GithubConnector(BaseResource):
|
|||
|
||||
data = response.json()
|
||||
res = {
|
||||
'title': data['title'],
|
||||
'state': data['state']
|
||||
'data': {
|
||||
'title': data['title'],
|
||||
'state': data['state']
|
||||
}
|
||||
}
|
||||
return res
|
||||
|
||||
@endpoint(perm='can_access',
|
||||
post={
|
||||
'description': _('Create github issue'),
|
||||
'request_body': {
|
||||
'schema': {
|
||||
'application/json': SCHEMA
|
||||
}
|
||||
}
|
||||
})
|
||||
def createissue(self, request, post_data):
|
||||
url = '%s/repos/%s/%s/issues' % (
|
||||
self.api_url, self.github_user, self.github_repo)
|
||||
|
||||
# @endpoint(perm='can_access',
|
||||
# post={
|
||||
# 'description': _('Blah'),
|
||||
# 'request_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': BOOKDATE_SCHEMA
|
||||
# }
|
||||
# }
|
||||
# })
|
||||
# def bookdate(self, request, post_data):
|
||||
# data = post_data
|
||||
# iws_data = {
|
||||
# 'NO_APPEL': data['token'],
|
||||
# 'I_APP_DEMANDEUR': '%s, %s' % (data['lastname'], data['firstname']),
|
||||
# 'I_AP_DATRDVAGENDA': data['date'],
|
||||
# 'C_STAPPEL': 'E',
|
||||
# 'I_AP_SERVICE': 'OFFICE',
|
||||
# 'I_AP_SOURCE': 'USAGER',
|
||||
# 'C_ORIGINE': 'TELESERVICE',
|
||||
# 'C_BLOCAGE': 2,
|
||||
# 'I_AP_EMAIL': 'NON',
|
||||
# 'I_AP_ADRESSEMAIL': '',
|
||||
# 'I_AP_CNIL': 1,
|
||||
# 'I_AP_SMS': 'NON',
|
||||
# 'I_AP_TEL_DEMANDEU': '',
|
||||
# 'DE_SYMPAPPEL': data['description'] or '',
|
||||
# 'C_QUALIFICATIF': 'INTERVENTION',
|
||||
# }
|
||||
# if 'email' in data:
|
||||
# iws_data['I_AP_ADRESSEMAIL'] = data['email']
|
||||
# iws_data['I_AP_EMAIL'] = 'OUI' if data['email_notif'] else 'NON'
|
||||
# if 'tel_number' in data:
|
||||
# iws_data['I_AP_TEL_DEMANDEU'] = data['tel_number']
|
||||
# iws_res = self._soap_call(iws_data, 'IsiUpdateAndGetCall')
|
||||
# self._check_status(iws_res)
|
||||
# return {'data': iws_res['fields']}
|
||||
to_send = {
|
||||
'title': post_data['title'],
|
||||
'body': post_data['description']
|
||||
}
|
||||
response = self.requests.post(
|
||||
url, auth=(self.github_user, self.github_token), json=to_send)
|
||||
res = response.json()
|
||||
|
||||
return {
|
||||
'data': {
|
||||
'number': res['number'],
|
||||
'state': res['state']
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue