Closed caffeineaddiction closed 1 year ago
The code you're showing is yours and not from the python-redmine library, so I assume the bug is there and not in the library, because we don't hardcode any Redmine fields in methods and it accepts basically everything.
I suggest you try the vanilla python-redmine code from the docs first and check that it works and only then try to create any custom wrappers around it, i.e. do the following first:
from redminelib import Redmine
redmine = Redmine('https://XXX.com', username='XXX', password='XXX')
issue = redmine.issue.create(
project_id=project_id,
subject=issue_title,
tracker_id=tracker_id,
description=issue_description,
priority_id=priority_id,
assigned_to_id=user_id
)
print(list(issue))
Pretty sure I am not wrapping anything. I have a class SlackApp
where the redmine client is set like:
from redmine import RedmineClient
from redmine import SlackModalForm
class SlackApp:
def __init__(self, config, app, handler):
# ... snip ...
self.__redmineClient__ = RedmineClient(self.__redmine_url__, self.redmine_api_key, self.redmine_cert_path)
from there I am making the api call as shown in the orig post:
newissue = self.__redmineClient__.create_issue(
project_id=project_id,
subject=issue_title,
tracker_id=tracker_id,
description=issue_description,
priority_id=priority_id,
assigned_to_id=user_id
)
this happens in a diff part of the SlackApp
class on return from a form modal but that shouldn't matter.
Further, I took the exact same block of code and implemented it via the raw Redmine REST API and it worked as intended:
def __handle_view_submission__(self, ack, body, logger):
ack()
view = body.get("view")
state = view.get("state")
values = state.get("values")
# Extract the input values
project_id = values["project"]["ssb_redmine_project_select_action"]["selected_option"]["value"]
tracker_id = 1 # Severity ID (1: Bug, 2: Feature, etc.)
user_id = values["assignee"]["ssb_redmine_assignee_select"]["selected_option"]["value"]
issue_title = values["subject"]["ssb_redmine_subject_input"]["value"]
form_issue_description = values["description"]["ssb_redmine_description_input"]["value"]
priority_id = values["priority"]["ssb_redmine_priority_select"]["selected_option"]["value"]
# trigger_metadata = json.loads(body["view"]["private_metadata"])
trigger_metadata = self.__get_shortcut_trigger_metadata__(body)
channel_id = trigger_metadata["channel_id"]
slack_user_id = trigger_metadata["user_id"]
issue_description = self.__format_issue_description__(form_issue_description, trigger_metadata)
issue_data = {
"issue": {
"project_id": project_id,
"subject": issue_title,
"tracker_id": tracker_id,
"description": issue_description,
"priority_id": priority_id,
"assigned_to_id": user_id
}
}
headers = {
"Content-Type": "application/json",
"X-Redmine-API-Key": self.redmine_api_key
}
try:
response = requests.post(
f"{self.__redmine_url__}/issues.json",
headers=headers,
data=json.dumps(issue_data),
verify=False
)
response.raise_for_status() # Raises a HTTPError if the status is 4xx, 5xx
newissue = response.json()["issue"]
not sure if the issue is with my understanding of your api, or your implementation of the api ... but their is a disconnect somewhere.
Have you checked that the code I showed you works ?
I don't know where you got that SlackApp class from, but the method create_issue
doesn't exist in python-redmine library, so it's a wrapper around library's code for sure and the problem is there and not in the library.
Ah wait, I think I know where this problem comes from, it should be
self.__redmineClient__.issue.create(
project_id=project_id,
subject=issue_title,
tracker_id=tracker_id,
description=issue_description,
priority_id=priority_id,
assigned_to_id=user_id
)
Does that work for you ?
nm, your correct.
Implemented somewhere else in the codebase I inherited:
class RedmineClient:
def create_issue(self, project_id, tracker_id, subject, description, assigned_to_id):
issue = self.redmine.issue.new()
issue.project_id = project_id
issue.tracker_id = tracker_id
issue.subject = subject
issue.description = description
issue.assigned_to_id = assigned_to_id
issue.save()
return issue
Sorry for the trouble
Documentation here: https://python-redmine.com/resources/issue.html says that I should be able to either:
.create_issue()
with named arguments like:but gives the following error:
and if I instead try to use
newissue.update()
like:I get the following error:
current redmine setup: