-
-
Notifications
You must be signed in to change notification settings - Fork 64
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 #485 from hackforla/dev
Release update
- Loading branch information
Showing
8 changed files
with
3,192 additions
and
362 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,81 @@ | ||
from json import dumps, loads | ||
import requests_async as requests | ||
|
||
|
||
class FeedbackService(object): | ||
def __init__(self, config=None): | ||
self.config = config | ||
self.token = None if not self.config \ | ||
else self.config['Github']['GITHUB_TOKEN'] | ||
self.issues_url = None if not self.config \ | ||
else self.config['Github']['ISSUES_URL'] | ||
self.project_url = None if not self.config \ | ||
else self.config['Github']['PROJECT_URL'] | ||
|
||
async def create_issue(self, title, body, labels=['feedback'], milestone=None, assignees=[]): | ||
""" | ||
Creates a Github issue via Github API v3 and returns the new issue id. | ||
Note: Per Github, the API (and required 'Accept' headers) may change without notice. | ||
See https://developer.github.com/v3/issues/ | ||
""" | ||
headers = { | ||
"Authorization": "token {}".format(self.token), | ||
"Accept": "application/vnd.github.v3+json" | ||
} | ||
data = { | ||
'title': title, | ||
'body': body, | ||
'labels': labels, | ||
'milestone': milestone, | ||
'assignees': assignees | ||
} | ||
payload = dumps(data) | ||
|
||
async with requests.Session() as session: | ||
try: | ||
response = await session.post(self.issues_url, data=payload, headers=headers) | ||
response_content = loads(response.content) | ||
issue_id = response_content['id'] | ||
response.raise_for_status() | ||
return issue_id | ||
except requests.exceptions.HTTPError as errh: | ||
return "An Http Error occurred:" + repr(errh) | ||
except requests.exceptions.ConnectionError as errc: | ||
return "An Error Connecting to the API occurred:" + repr(errc) | ||
except requests.exceptions.Timeout as errt: | ||
return "A Timeout Error occurred:" + repr(errt) | ||
except requests.exceptions.RequestException as err: | ||
return "An Unknown Error occurred" + repr(err) | ||
|
||
async def add_issue_to_project(self, issue_id, content_type='Issue'): | ||
""" | ||
Takes a Github issue id and adds the issue to a project board card. | ||
Returns the response from Github API. | ||
Note: Per Github, the API (and required 'Accept' headers) may change without notice. | ||
See https://developer.github.com/v3/projects/cards/ | ||
""" | ||
headers = { | ||
"Authorization": "token {}".format(self.token), | ||
"Accept": "application/vnd.github.inertia-preview+json" | ||
} | ||
data = { | ||
'content_id': issue_id, | ||
'content_type': content_type | ||
} | ||
payload = dumps(data) | ||
|
||
async with requests.Session() as session: | ||
try: | ||
response = await session.post(self.project_url, data=payload, headers=headers) | ||
response.raise_for_status() | ||
return response.status_code | ||
except requests.exceptions.HTTPError as errh: | ||
return "An Http Error occurred:" + repr(errh) | ||
except requests.exceptions.ConnectionError as errc: | ||
return "An Error Connecting to the API occurred:" + repr(errc) | ||
except requests.exceptions.Timeout as errt: | ||
return "A Timeout Error occurred:" + repr(errt) | ||
except requests.exceptions.RequestException as err: | ||
return "An Unknown Error occurred" + repr(err) |
Oops, something went wrong.