-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
I'm not sure this is necessary it just makes the description output cleaner answers = json.dumps(response["answers"], indent=2) example of description output is [here](https://autokitteh.atlassian.net/jira/software/projects/PK/issues/?jql=project%20%3D%20%22PK%22%20ORDER%20BY%20created%20DESC)
- Loading branch information
1 parent
e04e0eb
commit e1d4811
Showing
2 changed files
with
90 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This YAML file is a declarative manifest that describes the setup of | ||
# an AutoKitteh sample project that demonstrates integration with | ||
# Google Forms and Jira. | ||
# | ||
# After applying this file, initialize this AutoKitteh project's | ||
# Google Forms and Jira connections. | ||
|
||
version: v1 | ||
|
||
project: | ||
name: google_forms_to_jira | ||
vars: | ||
- name: FORM_ID | ||
value: <Google Form ID> # TODO: Replace with Google Form ID | ||
- name: JIRA_PROJECT_KEY | ||
value: <Jira Project Key> # TODO: Replace with Jira Project Key | ||
- name: POLL_INTERVAL | ||
value: 10 | ||
connections: | ||
- name: jira_connection | ||
integration: jira | ||
- name: google_forms_connection | ||
integration: googleforms | ||
- name: http_connection | ||
integration: http | ||
triggers: | ||
- name: http_request | ||
connection: http_connection | ||
event_type: get | ||
# Triggered by GET request to http://localhost:9980/http/google_forms_to_jira/ | ||
call: program.py:on_http_get |
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,59 @@ | ||
"""This program polls a Google Form for new responses and creates a Jira issue for each new response. | ||
Workflow: | ||
1. Trigger: HTTP GET request. | ||
2. Poll Forms: Poll the Google Form for new responses. | ||
3. Create Jira Issue: For each new response, create a Jira issue with the response data. | ||
""" | ||
|
||
import json | ||
import os | ||
import time | ||
|
||
import autokitteh | ||
from autokitteh import google | ||
from autokitteh.atlassian import atlassian_jira_client | ||
|
||
|
||
POLL_INTERVAL = os.getenv("POLL_INTERVAL") | ||
|
||
|
||
def on_http_get(event): | ||
form_id = os.getenv("FORM_ID") | ||
form_data = _get_form_data(form_id) | ||
total_responses = None | ||
while True: | ||
total_responses = _poll_forms(form_data, form_id, total_responses) | ||
time.sleep(float(POLL_INTERVAL)) | ||
|
||
|
||
@autokitteh.activity | ||
def _poll_forms(form_data, form_id, prev_total): | ||
google_forms = google.google_forms_client("google_forms_connection") | ||
result = google_forms.forms().responses().list(formId=form_id).execute() | ||
responses = result.get("responses", []) | ||
curr_total = len(responses) | ||
if prev_total and curr_total > prev_total: | ||
new_responses = curr_total - prev_total | ||
for response in responses[-new_responses:]: | ||
_create_jira_issue(form_data["info"]["title"], response) | ||
return curr_total | ||
|
||
|
||
def _create_jira_issue(title, response): | ||
jira = atlassian_jira_client("jira_connection") | ||
answers = json.dumps(response["answers"], indent=2) | ||
fields = { | ||
"project": {"key": os.getenv("JIRA_PROJECT_KEY")}, | ||
"summary": "New Google Form Response for form: " + title, | ||
"description": f"{{code:|language=python}} {answers} {{code}}", | ||
"issuetype": {"name": "Task"}, | ||
} | ||
new_issue = jira.create_issue(fields=fields) | ||
print(f"Created Jira issue: {new_issue["key"]}") | ||
|
||
|
||
@autokitteh.activity | ||
def _get_form_data(form_id): | ||
google_forms = google.google_forms_client("google_forms_connection") | ||
return google_forms.forms().get(formId=form_id).execute() |