如何为 Jira 动态使用用户输入 Python

How To Dynamically Use User Input for Jira Python

所以我正在尝试制作一种基于 Jira Key 的交互式提取 Jira 信息的方法。

完整代码:

import os
from atlassian import Jira

import json
with open('secrets.json','r') as f:
      config = json.load(f)

jira_instance = Jira(
    url = "https://mirantis.jira.com",
    username = (config['user']['username']),
    password = (config['user']['password'])
)

projects = jira_instance.get_all_projects(included_archived=None)

value = input("Please enter your Jira Key and the Issue ID:\n")
jira_key = (value)

issue = jira_instance.issue('(jira_key)', fields='summary,history,created,updated')
#issue = jira_instance.issue('DESDI-212', fields='summary,history,created,updated')
print(issue)

坏掉的主要是这个:

issue = jira_instance.issue('(jira_key)', fields='summary,history,created,updated')

出于某些奇怪的原因,它不喜欢我为 jira_key 使用用户输入的方式,尽管如果我使用 print(jira_key)

它会打印出我想要的内容

我是不是调用错了?

我基本上需要这个:

issue = jira_instance.issue('DESDI-212', fields='summary,history,created,updated')

由此,DESDI-212 将是用户输入。 当我使用 '(jira_key)' 尝试它时,它返回此错误:

 rbarrett@MacBook-Pro-2  ~/Projects/Mirantis/Dataeng/Python  python test_single.py                                                             ✔  10422  22:03:34
Please enter your Jira Key and the Issue ID:
DESDI-212
Traceback (most recent call last):
  File "/Users/rbarrett/Projects/Mirantis/Dataeng/Python/test_single.py", line 19, in <module>
    issue = jira_instance.issue('(jira_key)', fields='summary,history,created,updated')
  File "/usr/local/lib/python3.9/site-packages/atlassian/jira.py", line 676, in issue
    return self.get("rest/api/2/issue/{0}?fields={1}".format(key, fields), params=params)
  File "/usr/local/lib/python3.9/site-packages/atlassian/rest_client.py", line 264, in get
    response = self.request(
  File "/usr/local/lib/python3.9/site-packages/atlassian/rest_client.py", line 236, in request
    self.raise_for_status(response)
  File "/usr/local/lib/python3.9/site-packages/atlassian/jira.py", line 3715, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError: Issue does not exist or you do not have permission to see it.

我希望看到这个,如果我使用 'DESDI-212' 而不是 '(jira_key)' 它确实有效:

{'expand': 'renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations', 'id': '372744', 'self': 'https://mirantis.jira.com/rest/api/2/issue/372744', 'key': 'DESDI-212', 'fields': {'summary': 'Add the MSR version to be parsed into Loadstone', 'updated': '2021-06-23T17:33:21.206-0700', 'created': '2021-06-01T12:54:06.136-0700'}}

原来是我调用错了。 我需要将 '' 放在 '(jira_key)' 周围,然后用 (jira_key) 调用它:

import os
from atlassian import Jira

import json
with open('secrets.json','r') as f:
      config = json.load(f)

jira_instance = Jira(
    url = "https://mirantis.jira.com",
    username = (config['user']['username']),
    password = (config['user']['password'])
)

projects = jira_instance.get_all_projects(included_archived=None)

value = input("Please enter your Jira Key and the Issue ID:\n")
jira_key = (value)

issue = jira_instance.issue((jira_key), fields='summary,history,created,updated')
#issue = jira_instance.issue('DESDI-212', fields='summary,history,created,updated')
print(issue)

因此我得到了我需要的预期输出,但没有按预期工作:

 rbarrett@MacBook-Pro-2  ~/Projects/Mirantis/Dataeng/Python  python test_single.py                                                             ✔  10428  22:22:17
Please enter your Jira Key and the Issue ID:
DESDI-212
{'expand': 'renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations', 'id': '372744', 'self': 'https://mirantis.jira.com/rest/api/2/issue/372744', 'key': 'DESDI-212', 'fields': {'summary': 'Add the MSR version to be parsed into Loadstone', 'updated': '2021-06-23T17:33:21.206-0700', 'created': '2021-06-01T12:54:06.136-0700'}}