Skip to content

Commit

Permalink
Merge pull request #2646 from danswer-ai/slack-fix
Browse files Browse the repository at this point in the history
Added quotes to project name to handle reserved words (#2639)
  • Loading branch information
rkuo-danswer authored Oct 1, 2024
2 parents cdace77 + dc35e9f commit acaff41
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr-python-connector-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ env:
CONFLUENCE_TEST_PAGE_ID: ${{ secrets.CONFLUENCE_TEST_PAGE_ID }}
CONFLUENCE_USER_NAME: ${{ secrets.CONFLUENCE_USER_NAME }}
CONFLUENCE_ACCESS_TOKEN: ${{ secrets.CONFLUENCE_ACCESS_TOKEN }}
# Jira
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}

jobs:
connectors-check:
Expand Down
8 changes: 6 additions & 2 deletions backend/danswer/connectors/danswer_jira/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,12 @@ def load_from_state(self) -> GenerateDocumentsOutput:
if self.jira_client is None:
raise ConnectorMissingCredentialError("Jira")

# Quote the project name to handle reserved words
quoted_project = f'"{self.jira_project}"'
start_ind = 0
while True:
doc_batch, fetched_batch_size = fetch_jira_issues_batch(
jql=f"project = {self.jira_project}",
jql=f"project = {quoted_project}",
start_index=start_ind,
jira_client=self.jira_client,
batch_size=self.batch_size,
Expand Down Expand Up @@ -276,8 +278,10 @@ def poll_source(
"%Y-%m-%d %H:%M"
)

# Quote the project name to handle reserved words
quoted_project = f'"{self.jira_project}"'
jql = (
f"project = {self.jira_project} AND "
f"project = {quoted_project} AND "
f"updated >= '{start_date_str}' AND "
f"updated <= '{end_date_str}'"
)
Expand Down
48 changes: 48 additions & 0 deletions backend/tests/daily/connectors/jira/test_jira_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import time

import pytest

from danswer.configs.constants import DocumentSource
from danswer.connectors.danswer_jira.connector import JiraConnector


@pytest.fixture
def jira_connector() -> JiraConnector:
connector = JiraConnector(
"https://danswerai.atlassian.net/jira/software/c/projects/AS/boards/6",
comment_email_blacklist=[],
)
connector.load_credentials(
{
"jira_user_email": os.environ["JIRA_USER_EMAIL"],
"jira_api_token": os.environ["JIRA_API_TOKEN"],
}
)
return connector


def test_jira_connector_basic(jira_connector: JiraConnector) -> None:
doc_batch_generator = jira_connector.poll_source(0, time.time())

doc_batch = next(doc_batch_generator)
with pytest.raises(StopIteration):
next(doc_batch_generator)

assert len(doc_batch) == 1

doc = doc_batch[0]

assert doc.id == "https://danswerai.atlassian.net/browse/AS-2"
assert doc.semantic_identifier == "test123small"
assert doc.source == DocumentSource.JIRA
assert doc.metadata == {"priority": "Medium", "status": "Backlog"}
assert doc.secondary_owners is None
assert doc.title is None
assert doc.from_ingestion_api is False
assert doc.additional_info is None

assert len(doc.sections) == 1
section = doc.sections[0]
assert section.text == "example_text\n"
assert section.link == "https://danswerai.atlassian.net/browse/AS-2"

0 comments on commit acaff41

Please sign in to comment.