跳至内容

Jira

Jira工具规范 #

基类: BaseToolSpec

Atlassian Jira 工具规范。

Source code in llama-index-integrations/tools/llama-index-tools-jira/llama_index/tools/jira/base.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
class JiraToolSpec(BaseToolSpec):
    """Atlassian Jira Tool Spec."""

    spec_functions = [
        "jira_issues_query",
        "jira_issue_query",
        "jira_comments_query",
        "jira_all_projects",
    ]

    def __init__(
        self,
        email: Optional[str] = None,
        api_token: Optional[str] = None,
        server_url: Optional[str] = None,
    ) -> None:
        """Initialize the Atlassian Jira tool spec."""
        from jira import JIRA

        if email and api_token and server_url:
            self.jira = JIRA(
                basic_auth=(email, api_token),
                server=server_url,
            )
        else:
            raise Exception("Error: Please provide Jira api credentials to continue")

    def jira_all_projects(self) -> dict:
        """
        Retrieve all projects from the Atlassian Jira account.

        This method fetches a list of projects from Jira and returns them in a structured
        format, including the project ID, key, and name. If an error occurs during
        retrieval, an error message is returned.

        Returns:
            dict: A dictionary containing:
                - 'error' (bool): Indicates whether the request was successful.
                - 'message' (str): A description of the result.
                - 'projects' (list, optional): A list of projects with their details
                  (ID, key, name) if retrieval is successful.

        """
        try:
            projects = self.jira.projects()

            if projects:
                return {
                    "error": False,
                    "message": "All Projects from the account",
                    "projects": [
                        {"id": project.id, "key": project.key, "name": project.name}
                        for project in projects
                    ],
                }
        except Exception:
            pass

        return {"error": True, "message": "Unable to fetch projects"}

    def jira_comments_query(
        self, issue_key: str, author_email: Optional[str] = None
    ) -> dict:
        """
        Retrieve all comments for a given Jira issue, optionally filtering by the author's email.

        This function fetches comments from a specified Jira issue and returns them as a structured
        JSON response. If an `author_email` is provided, only comments from that specific author
        will be included.

        Args:
            issue_key (str): The Jira issue key for which to retrieve comments.
            author_email (str, Optional): filters comments by the author's email.

        Returns:
            dict: A dictionary containing:
                - 'error' (bool): Indicates whether the request was successful.
                - 'message' (str): A descriptive message about the result.
                - 'comments' (list, optional): A list of comments, where each comment includes:
                    - 'id' (str): The unique identifier of the comment.
                    - 'author' (str): The display name of the comment's author.
                    - 'author_email' (str): The author's email address.
                    - 'body' (str): The content of the comment.
                    - 'created_at' (str): The timestamp when the comment was created.
                    - 'updated_at' (str): The timestamp when the comment was last updated.

        """
        error = False

        try:
            issue = self.jira.issue(issue_key)

            all_comments = list(issue.fields.comment.comments)
            filtered_results = []

            for comment in all_comments:
                if (
                    author_email is not None
                    and author_email not in comment.author.emailAddress
                ):
                    continue

                filtered_results.append(
                    {
                        "id": comment.id,
                        "author": comment.author.displayName,
                        "author_email": comment.author.emailAddress,
                        "body": comment.body,
                        "created_at": comment.created,
                        "updated_at": comment.updated,
                    }
                )

            message = f'All the comments in the issue key "{issue_key}"'
        except Exception:
            error = True
            message = "Unable to fetch comments due to some error"

        response = {"error": error, "message": message}

        if error is False:
            response["comments"] = filtered_results

        return response

    def jira_issue_query(
        self, issue_key: str, just_payload: bool = False
    ) -> Union[None, dict]:
        """
        Retrieves detailed information about a specific Jira issue.

        This method fetches issue details such as summary, description, type, project, priority, status,
        reporter, assignee, labels, and timestamps. The response structure can be adjusted using the
        `just_payload` flag.

        Args:
            issue_key (str): The unique key or ticket number of the Jira issue.
            just_payload (bool, optional): If True, returns only the issue payload without the response
                                           metadata. Defaults to False.

        Returns:
            Union[None, dict]: A dictionary containing issue details if found, or an error response if the issue
                               cannot be retrieved.

        Example:
            > jira_client.load_issue("JIRA-123", just_payload=True)
            {
                'key': 'JIRA-123',
                'summary': 'Fix login bug',
                'description': 'Users unable to log in under certain conditions...',
                'type': 'Bug',
                'project_name': 'Web App',
                'priority': 'High',
                'status': 'In Progress',
                'reporter': 'John Doe',
                'reporter_email': '[email protected]',
                'labels': ['authentication', 'urgent'],
                'created_at': '2024-02-01T10:15:30.000Z',
                'updated_at': '2024-02-02T12:20:45.000Z',
                'assignee': 'Jane Smith',
                'assignee_email': '[email protected]'
            }

        """
        error = False
        try:
            issue = self.jira.issue(issue_key)

            payload = {
                "key": issue.key,
                "summary": issue.fields.summary,
                "description": issue.fields.description,
                "type": issue.fields.issuetype.name,
                "project_name": issue.fields.project.name,
                "priority": issue.fields.priority.name,
                "status": issue.fields.status.name,
                "reporter": issue.fields.reporter.displayName
                if issue.fields.reporter
                else None,
                "reporter_email": issue.fields.reporter.emailAddress
                if issue.fields.reporter
                else None,
                "labels": issue.fields.labels,
                "created_at": issue.fields.created,
                "updated_at": issue.fields.updated,
                "assignee": issue.fields.assignee.displayName
                if issue.fields.assignee
                else None,
                "assignee_email": issue.fields.assignee.emailAddress
                if issue.fields.assignee
                else None,
            }

            message = f"Details of the issue: {issue.key}"

        except Exception:
            error = True
            message = "Unable to fetch issue due to some error"

        if error is False and just_payload:
            return payload

        response = {"error": error, "message": message}

        if error is False:
            response["result"] = payload

        return response

    def jira_issues_query(self, keyword: str, max_results: int = 10) -> dict:
        """
        Search for Jira issues containing a specific keyword.

        This function searches for Jira issues where the specified `keyword` appears in the summary, description, or comments.
        The results are sorted by creation date in descending order.

        Args:
            keyword (str): The keyword to search for within issue summaries, descriptions, or comments.
            max_results (int, optional): The maximum number of issues to return. Defaults to 10. If set higher than 100, it will be limited to 100.

        Returns:
            dict: A dictionary with the following structure:
                - 'error' (bool): Indicates if an error occurred during the fetch operation.
                - 'message' (str): Describes the outcome of the operation.
                - 'results' (list, optional): A list of issues matching the search criteria, present only if no error occurred.

        """
        error = False

        max_results = min(max_results, 100)

        # if custom_query is not None:
        #     jql = custom_query
        # else:
        jql = f'summary ~ "{keyword}" or description ~ "{keyword}" or text ~ "{keyword}" order by created desc'

        try:
            issues = [
                self.jira_issue_query(issue.key, just_payload=True)
                for issue in self.jira.search_issues(jql, maxResults=max_results)
            ]

            message = "All the issues with specific matching conditions"
        except Exception:
            error = True
            message = "Unable to fetch issue due to some error"

        response = {"error": error, "message": message}

        if error is False:
            response["results"] = issues

        return response

所有Jira项目 #

jira_all_projects() -> dict

从Atlassian Jira账户中检索所有项目。

该方法从Jira获取项目列表并以结构化格式返回,包括项目ID、键和名称。如果在检索过程中发生错误,将返回错误信息。

返回:

名称 类型 描述
dict dict

一个包含以下内容的字典: - 'error' (bool): 表示请求是否成功。 - 'message' (str): 对结果的描述。 - 'projects' (list, 可选): 如果检索成功,则包含项目详情(ID、key、名称)的项目列表。

Source code in llama-index-integrations/tools/llama-index-tools-jira/llama_index/tools/jira/base.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def jira_all_projects(self) -> dict:
    """
    Retrieve all projects from the Atlassian Jira account.

    This method fetches a list of projects from Jira and returns them in a structured
    format, including the project ID, key, and name. If an error occurs during
    retrieval, an error message is returned.

    Returns:
        dict: A dictionary containing:
            - 'error' (bool): Indicates whether the request was successful.
            - 'message' (str): A description of the result.
            - 'projects' (list, optional): A list of projects with their details
              (ID, key, name) if retrieval is successful.

    """
    try:
        projects = self.jira.projects()

        if projects:
            return {
                "error": False,
                "message": "All Projects from the account",
                "projects": [
                    {"id": project.id, "key": project.key, "name": project.name}
                    for project in projects
                ],
            }
    except Exception:
        pass

    return {"error": True, "message": "Unable to fetch projects"}

jira_comments_query #

jira_comments_query(issue_key: str, author_email: Optional[str] = None) -> dict

检索给定Jira问题的所有评论,可选择按作者邮箱进行筛选。

此函数从指定的Jira问题中获取评论,并以结构化的JSON响应形式返回。如果提供了author_email参数,则仅包含该特定作者的评论。

参数:

名称 类型 描述 默认值
issue_key str

要获取评论的Jira问题键。

required
author_email (str, Optional)

根据作者的电子邮件过滤评论。

None

返回:

名称 类型 描述
dict dict

包含以下内容的字典: - 'error' (bool): 表示请求是否成功。 - 'message' (str): 关于结果的描述性信息。 - 'comments' (list, 可选): 评论列表,其中每条评论包含: - 'id' (str): 评论的唯一标识符。 - 'author' (str): 评论作者的显示名称。 - 'author_email' (str): 作者的电子邮件地址。 - 'body' (str): 评论内容。 - 'created_at' (str): 评论创建时的时间戳。 - 'updated_at' (str): 评论最后更新时间的时间戳。

Source code in llama-index-integrations/tools/llama-index-tools-jira/llama_index/tools/jira/base.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def jira_comments_query(
    self, issue_key: str, author_email: Optional[str] = None
) -> dict:
    """
    Retrieve all comments for a given Jira issue, optionally filtering by the author's email.

    This function fetches comments from a specified Jira issue and returns them as a structured
    JSON response. If an `author_email` is provided, only comments from that specific author
    will be included.

    Args:
        issue_key (str): The Jira issue key for which to retrieve comments.
        author_email (str, Optional): filters comments by the author's email.

    Returns:
        dict: A dictionary containing:
            - 'error' (bool): Indicates whether the request was successful.
            - 'message' (str): A descriptive message about the result.
            - 'comments' (list, optional): A list of comments, where each comment includes:
                - 'id' (str): The unique identifier of the comment.
                - 'author' (str): The display name of the comment's author.
                - 'author_email' (str): The author's email address.
                - 'body' (str): The content of the comment.
                - 'created_at' (str): The timestamp when the comment was created.
                - 'updated_at' (str): The timestamp when the comment was last updated.

    """
    error = False

    try:
        issue = self.jira.issue(issue_key)

        all_comments = list(issue.fields.comment.comments)
        filtered_results = []

        for comment in all_comments:
            if (
                author_email is not None
                and author_email not in comment.author.emailAddress
            ):
                continue

            filtered_results.append(
                {
                    "id": comment.id,
                    "author": comment.author.displayName,
                    "author_email": comment.author.emailAddress,
                    "body": comment.body,
                    "created_at": comment.created,
                    "updated_at": comment.updated,
                }
            )

        message = f'All the comments in the issue key "{issue_key}"'
    except Exception:
        error = True
        message = "Unable to fetch comments due to some error"

    response = {"error": error, "message": message}

    if error is False:
        response["comments"] = filtered_results

    return response

jira问题查询 #

jira_issue_query(issue_key: str, just_payload: bool = False) -> Union[None, dict]

获取特定Jira问题的详细信息。

该方法获取问题详情,如摘要、描述、类型、项目、优先级、状态、报告人、经办人、标签和时间戳。可以通过just_payload标志调整响应结构。

参数:

名称 类型 描述 默认值
issue_key str

Jira问题的唯一键或工单编号。

required
just_payload bool

如果为True,仅返回问题负载而不包含响应元数据。默认为False。

False

返回:

类型 描述
Union[None, dict]

Union[None, dict]: 如果找到问题,则返回包含问题详情的字典;如果无法获取问题,则返回错误响应。

Example

jira_client.load_issue("JIRA-123", just_payload=True) { 'key': 'JIRA-123', 'summary': '修复登录问题', 'description': '用户在某些情况下无法登录...', 'type': 'Bug', 'project_name': 'Web应用', 'priority': '高优先级', 'status': '处理中', 'reporter': '约翰·多伊', 'reporter_email': '[email protected]', 'labels': ['authentication', 'urgent'], 'created_at': '2024-02-01T10:15:30.000Z', 'updated_at': '2024-02-02T12:20:45.000Z', 'assignee': '简·史密斯', 'assignee_email': '[email protected]' }

Source code in llama-index-integrations/tools/llama-index-tools-jira/llama_index/tools/jira/base.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def jira_issue_query(
    self, issue_key: str, just_payload: bool = False
) -> Union[None, dict]:
    """
    Retrieves detailed information about a specific Jira issue.

    This method fetches issue details such as summary, description, type, project, priority, status,
    reporter, assignee, labels, and timestamps. The response structure can be adjusted using the
    `just_payload` flag.

    Args:
        issue_key (str): The unique key or ticket number of the Jira issue.
        just_payload (bool, optional): If True, returns only the issue payload without the response
                                       metadata. Defaults to False.

    Returns:
        Union[None, dict]: A dictionary containing issue details if found, or an error response if the issue
                           cannot be retrieved.

    Example:
        > jira_client.load_issue("JIRA-123", just_payload=True)
        {
            'key': 'JIRA-123',
            'summary': 'Fix login bug',
            'description': 'Users unable to log in under certain conditions...',
            'type': 'Bug',
            'project_name': 'Web App',
            'priority': 'High',
            'status': 'In Progress',
            'reporter': 'John Doe',
            'reporter_email': '[email protected]',
            'labels': ['authentication', 'urgent'],
            'created_at': '2024-02-01T10:15:30.000Z',
            'updated_at': '2024-02-02T12:20:45.000Z',
            'assignee': 'Jane Smith',
            'assignee_email': '[email protected]'
        }

    """
    error = False
    try:
        issue = self.jira.issue(issue_key)

        payload = {
            "key": issue.key,
            "summary": issue.fields.summary,
            "description": issue.fields.description,
            "type": issue.fields.issuetype.name,
            "project_name": issue.fields.project.name,
            "priority": issue.fields.priority.name,
            "status": issue.fields.status.name,
            "reporter": issue.fields.reporter.displayName
            if issue.fields.reporter
            else None,
            "reporter_email": issue.fields.reporter.emailAddress
            if issue.fields.reporter
            else None,
            "labels": issue.fields.labels,
            "created_at": issue.fields.created,
            "updated_at": issue.fields.updated,
            "assignee": issue.fields.assignee.displayName
            if issue.fields.assignee
            else None,
            "assignee_email": issue.fields.assignee.emailAddress
            if issue.fields.assignee
            else None,
        }

        message = f"Details of the issue: {issue.key}"

    except Exception:
        error = True
        message = "Unable to fetch issue due to some error"

    if error is False and just_payload:
        return payload

    response = {"error": error, "message": message}

    if error is False:
        response["result"] = payload

    return response

jira问题查询 #

jira_issues_query(keyword: str, max_results: int = 10) -> dict

搜索包含特定关键词的Jira问题。

该函数用于搜索Jira问题单,其中指定的keyword出现在摘要、描述或评论中。 结果按创建日期降序排列。

参数:

名称 类型 描述 默认值
keyword str

用于在问题摘要、描述或评论中搜索的关键词。

required
max_results int

返回的最大问题数量。默认为10。如果设置超过100,将被限制为100。

10

返回:

名称 类型 描述
dict dict

一个包含以下结构的字典: - 'error' (bool): 表示在获取操作期间是否发生错误。 - 'message' (str): 描述操作的结果。 - 'results' (list, 可选): 符合搜索条件的问题列表,仅在未发生错误时存在。

Source code in llama-index-integrations/tools/llama-index-tools-jira/llama_index/tools/jira/base.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
def jira_issues_query(self, keyword: str, max_results: int = 10) -> dict:
    """
    Search for Jira issues containing a specific keyword.

    This function searches for Jira issues where the specified `keyword` appears in the summary, description, or comments.
    The results are sorted by creation date in descending order.

    Args:
        keyword (str): The keyword to search for within issue summaries, descriptions, or comments.
        max_results (int, optional): The maximum number of issues to return. Defaults to 10. If set higher than 100, it will be limited to 100.

    Returns:
        dict: A dictionary with the following structure:
            - 'error' (bool): Indicates if an error occurred during the fetch operation.
            - 'message' (str): Describes the outcome of the operation.
            - 'results' (list, optional): A list of issues matching the search criteria, present only if no error occurred.

    """
    error = False

    max_results = min(max_results, 100)

    # if custom_query is not None:
    #     jql = custom_query
    # else:
    jql = f'summary ~ "{keyword}" or description ~ "{keyword}" or text ~ "{keyword}" order by created desc'

    try:
        issues = [
            self.jira_issue_query(issue.key, just_payload=True)
            for issue in self.jira.search_issues(jql, maxResults=max_results)
        ]

        message = "All the issues with specific matching conditions"
    except Exception:
        error = True
        message = "Unable to fetch issue due to some error"

    response = {"error": error, "message": message}

    if error is False:
        response["results"] = issues

    return response
优云智算