Confluence added (#6432)

Adding Confluence to Jira tool. Can create a page in Confluence with
this PR. If accepted, will extend functionality to Bitbucket and
additional Confluence features.



---------

Co-authored-by: Ethan Bowen <ethan.bowen@slalom.com>
pull/6755/head
Ethan Bowen 1 year ago committed by GitHub
parent 2aeb8e7dbc
commit cc33bde74f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
"""Zapier Tool."""
"""Jira Tool."""

@ -32,3 +32,10 @@ JIRA_CATCH_ALL_PROMPT = """
self.jira.projects()
For more information on the Jira API, refer to https://atlassian-python-api.readthedocs.io/jira.html
"""
JIRA_CONFLUENCE_PAGE_CREATE_PROMPT = """This tool is a wrapper around atlassian-python-api's Confluence
atlassian-python-api API, useful when you need to create a Confluence page. The input to this tool is a dictionary
specifying the fields of the Confluence page, and will be passed into atlassian-python-api's Confluence `create_page`
function. For example, to create a page in the DEMO space titled "This is the title" with body "This is the body. You can use
<strong>HTML tags</strong>!", you would pass in the following dictionary: {{"space": "DEMO", "title":"This is the
title","body":"This is the body. You can use <strong>HTML tags</strong>!"}} """

@ -5,6 +5,7 @@ from pydantic import BaseModel, Extra, root_validator
from langchain.tools.jira.prompt import (
JIRA_CATCH_ALL_PROMPT,
JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
JIRA_GET_ALL_PROJECTS_PROMPT,
JIRA_ISSUE_CREATE_PROMPT,
JIRA_JQL_PROMPT,
@ -17,6 +18,7 @@ class JiraAPIWrapper(BaseModel):
"""Wrapper for Jira API."""
jira: Any #: :meta private:
confluence: Any
jira_username: Optional[str] = None
jira_api_token: Optional[str] = None
jira_instance_url: Optional[str] = None
@ -42,6 +44,11 @@ class JiraAPIWrapper(BaseModel):
"name": "Catch all Jira API call",
"description": JIRA_CATCH_ALL_PROMPT,
},
{
"mode": "create_page",
"name": "Create confluence page",
"description": JIRA_CONFLUENCE_PAGE_CREATE_PROMPT,
},
]
class Config:
@ -69,7 +76,7 @@ class JiraAPIWrapper(BaseModel):
values["jira_instance_url"] = jira_instance_url
try:
from atlassian import Jira
from atlassian import Confluence, Jira
except ImportError:
raise ImportError(
"atlassian-python-api is not installed. "
@ -82,7 +89,16 @@ class JiraAPIWrapper(BaseModel):
password=jira_api_token,
cloud=True,
)
confluence = Confluence(
url=jira_instance_url,
username=jira_username,
password=jira_api_token,
cloud=True,
)
values["jira"] = jira
values["confluence"] = confluence
return values
@ -151,7 +167,7 @@ class JiraAPIWrapper(BaseModel):
)
return parsed_projects_str
def create(self, query: str) -> str:
def issue_create(self, query: str) -> str:
try:
import json
except ImportError:
@ -161,6 +177,16 @@ class JiraAPIWrapper(BaseModel):
params = json.loads(query)
return self.jira.issue_create(fields=dict(params))
def page_create(self, query: str) -> str:
try:
import json
except ImportError:
raise ImportError(
"json is not installed. Please install it with `pip install json`"
)
params = json.loads(query)
return self.confluence.create_page(**dict(params))
def other(self, query: str) -> str:
context = {"self": self}
exec(f"result = {query}", context)
@ -173,8 +199,10 @@ class JiraAPIWrapper(BaseModel):
elif mode == "get_projects":
return self.project()
elif mode == "create_issue":
return self.create(query)
return self.issue_create(query)
elif mode == "other":
return self.other(query)
elif mode == "create_page":
return self.page_create(query)
else:
raise ValueError(f"Got unexpected mode {mode}")

@ -27,3 +27,17 @@ def test_create_ticket() -> None:
output = jira.run("create_issue", issue_string)
assert "id" in output
assert "key" in output
def test_create_confluence_page() -> None:
"""Test for getting projects on JIRA"""
jira = JiraAPIWrapper()
create_page_dict = (
'{"space": "ROC", "title":"This is the title",'
'"body":"This is the body. You can use '
'<strong>HTML tags</strong>!"}'
)
output = jira.run("create_page", create_page_dict)
assert "type" in output
assert "page" in output

Loading…
Cancel
Save