diff --git a/README.md b/README.md index e66b16c..37d62ff 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,14 @@ ## How to Use -# via Bundle URLs +### Via prebuilt docker image +You can use the prebuilt docker image that is based on the official langflow image but include the ClearPoint langflow-lib and the required dependencies. + +```bash +docker run --rm -it -p 7860:7860 ghcr.io/clearpointnz/langflow-lib:v0.1.0 +``` + +### via Bundle URLs Components can be pulled into your Langflow instance by setting the `LANGFLOW_BUNDLE_URLS` environment variable to the URL of this repository. For example: @@ -13,8 +20,9 @@ Note: The command above will not persist any workflows or configuration. Use for Many of these components require additional Python packages to be installed. These will need to be available in your Langflow instance. See the `comps_requirements.txt` file for a list of dependencies. -# Via custom docker image -Alternatively you can build a custom docker container with the depencies and the components installed. For example: + +### Via custom docker image +Alternatively you can build a custom docker container with the dependencies and the components installed. For example: ``` dockerfile FROM langflowai/langflow:latest @@ -33,4 +41,8 @@ COPY components/ /app/components/ ENV LANGFLOW_COMPONENTS_PATH=/app/components CMD ["langflow", "run"] -``` \ No newline at end of file +``` + +## Development +You can use the included Docker compose file to build and run langflow with the components for testing and development. It includes creation of a volume for persisting data and configuration. + diff --git a/components/ClearPoint Jira/jira_add_comment.py b/components/ClearPoint Jira/jira_add_comment.py index 8b4c2a0..7a1e8da 100644 --- a/components/ClearPoint Jira/jira_add_comment.py +++ b/components/ClearPoint Jira/jira_add_comment.py @@ -47,16 +47,25 @@ class JiraAddCommentComponent(Component): Output( name="results", display_name="Results", - method="add_issue", + method="add_comment_to_issue", info="The results of the Jira comment add operation." ) ] - def add_issue(self) -> Data: + def add_comment_to_issue(self) -> Data: + # HACK: make copy of inputs to avoid race condition. not guareenteed to work. See https://github.com/langflow-ai/langflow/issues/8791 + issue_key = self.issue_key + comment_text = self.comment_text + + # create the JIRA client jira = JIRA(server=self.JIRA_SERVER_URL, basic_auth=(self.JIRA_USERNAME, self.JIRA_API_KEY)) - results = jira.add_comment(self.issue_key,self.comment_text) + # add the comment to the issue + response = jira.add_comment(issue_key, comment_text) + + # build a results payload + results = {"comment_id": response["id"], "status": "Comment added successfully"} - self.status = results.raw - return Data(data=results.raw) + self.status = results.results + return Data(data=results.results) \ No newline at end of file diff --git a/components/ClearPoint Jira/jira_add_label.py b/components/ClearPoint Jira/jira_add_label.py index b6d2ff0..bd9cd10 100644 --- a/components/ClearPoint Jira/jira_add_label.py +++ b/components/ClearPoint Jira/jira_add_label.py @@ -55,18 +55,25 @@ class JiraAddLabelToIssueComponent(Component): ] def add_label(self) -> Data: + # HACK: make copy of inputs to avoid race condition. not guareenteed to work. See https://github.com/langflow-ai/langflow/issues/8791 + issue_key = self.issue_key + label = self.label + + # create the JIRA client jira = JIRA(server=self.JIRA_SERVER_URL, basic_auth=(self.JIRA_USERNAME, self.JIRA_API_KEY)) - # grab the issue - issue = jira.issue(self.issue_key) + # grab the current labels for the issue + issue = jira.issue(issue_key, fields='labels') # add the label to the issue - issue.fields.labels.append(self.label) + issue.fields.labels.append(label) + # update issue with the new label issue.update(fields={"labels": issue.fields.labels}) - issue = jira.issue(self.issue_key) # load the updated issue so we can get raw data TODO: add logic to avoid this second call + # build a results payload + results = {"issue_key": issue_key, "labels": issue.fields.labels, "status": "Label added successfully"} - self.status = issue.raw - return Data(data=issue.raw) + self.status = results + return Data(data=results) \ No newline at end of file diff --git a/components/ClearPoint Jira/jira_search_issues_component.py b/components/ClearPoint Jira/jira_search_issues_component.py index 0eacd3a..7aa21be 100644 --- a/components/ClearPoint Jira/jira_search_issues_component.py +++ b/components/ClearPoint Jira/jira_search_issues_component.py @@ -65,11 +65,17 @@ class JiraSearchIssuesComponent(Component): ] def search_issues(self) -> List[Data]: + # HACK: make copy of inputs to avoid race condition. not guareenteed to work. See https://github.com/langflow-ai/langflow/issues/8791 + jql_query = self.jql_query + issue_fields = self.issue_fields + + # create the JIRA client jira = JIRA(server=self.JIRA_SERVER_URL, basic_auth=(self.JIRA_USERNAME, self.JIRA_API_KEY)) - - issues = jira.search_issues(self.jql_query, fields=self.issue_fields,json_result=True) + # do the search + issues = jira.search_issues(jql_query, fields=self.issue_fields,json_result=True) + # build list of issues, flattening fields if requested issues_list = [] for issue in issues["issues"]: @@ -85,11 +91,16 @@ def search_issues(self) -> List[Data]: return issues_list def build_dataframe(self) -> DataFrame: + # trigger the saerch issues = self.search_issues() + + # convert results to list of dict rows = [] for issue in issues: rows.append(dict(issue.data)) + # convert list of dict to DataFrame df_result = DataFrame(rows) - self.status = df_result # store in self.status for logs + + self.status = df_result return df_result diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..44c094c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,18 @@ +# Docker compose file for local dev/testing of langflow-lib with peristence of config/flows +services: + langflow: + build: . + # container is set up to run as user so need to run as root so that can write to config dir + user: root + # tty true so taht all logs are printed + tty: true + ports: + - "7860:7860" + environment: + - LANGFLOW_CONFIG_DIR=/app/langflow + - LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true + - DO_NOT_TRACK=true + volumes: + - langflowlib-dev-data:/app/langflow +volumes: + langflowlib-dev-data: \ No newline at end of file