Source code for cgl.plugins.jira.query

from __future__ import annotations

from cgl.plugins.jira.session import jira_config, JIRA as JIRAClient
import os
from typing import Optional


_JIRA: Optional[JIRAClient] = None


[docs] def get_jira() -> Optional[JIRAClient]: """ Lazy Jira accessor. Returns None during docs builds / offline mode. """ global _JIRA if _JIRA is not None: return _JIRA if os.environ.get("ALCHEMY_DOCS_BUILD") == "1": return None _JIRA = JIRAClient() return _JIRA
[docs] def project_by_name(project_name): """ Returns the project object from the project name. Args: project_name: Returns: """ jira = get_jira() if not jira: return [] # or raise a controlled exception return jira.session.project(project_name)
[docs] def issue_by_name(project_name, issue_name, issue_type="Epic"): """ Returns the issue object from the issue name. Args: issue_name: Returns: """ jira = get_jira() if not jira: return [] # or raise a controlled exception jql_str = f'project = "{project_name}" AND issuetype = "{issue_type}" AND summary ~ "{issue_name}"' # project = project_by_name(project_name) issues = jira.session.search_issues(jql_str) print("issues", issues) if len(issues) == 1: return issues[0] elif not issues: return None elif len(issues) > 1: raise Exception( f"Multiple issues found with name {issue_name} in project {project_name}" )
[docs] def asset(project_name, asset_name, issue_type="Epic"): """ Returns the asset object from the asset name. Args: project_name: asset_name: Returns: """ return issue_by_name(project_name, asset_name, issue_type)
[docs] def asset_dict(jira_issue): """ Returns the asset details from the jira issue object. Args: jira_issue: Returns: """ # print(f"Issue Key: {issue.key}") # print(f"Summary: {issue.fields.summary}") # print(f"Description: {issue.fields.description}") # print(f"Reporter: {issue.fields.reporter.displayName}") # print(f"Assignee: {issue.fields.assignee.displayName if issue.fields.assignee else 'Unassigned'}") # print(f"Status: {issue.fields.status.name}") shot = jira_issue.fields.summary print(shot) # sequence = jira_issue.fields.category entity_type = jira_issue.fields.customfield_10057 category = jira_issue.fields.customfield_10058 print(f"Asset: {shot}") print(f"Entity Type: {entity_type}") print(f"Category: {category}") return jira_issue.fields
# def cgl_helpdesk(): # """ # this is hard coded since we'll be using this for submitting tickets from Alchemy to the helpdesk for cgl. # Args: # # Returns: # # """ # project_name = "Alchemy Help Menu" # project_code = "AHM" # api_key = "ATATT3xFfGF06fwvbR_T1kdYaC7l_EHIw5GB5gtPcsNEbU_bD_I1R4ZUaPBmkGO3lxYlML-53CdKdZlsOrbHG53w8Ufl2HIo4I6727yrLuyIBileMuTsOweiVqV_a_G0BNVGx3lq9JJgyBEWpFsEpBe8UGoco0TaqoogimXYmVTmJttinlJRme0=AD0DFA9F" # documentation = "https://cglumberjack.atlassian.net/wiki/x/3QCF" # url = "https://cglumberjack.atlassian.net" # user = "tom@cglumberjack.com" if __name__ == "__main__": # this = issue_by_name("TF", "Jesus") print(jira_config("CGL", "default"))