Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#148] Add try/except block around code adding labels to already existing issues #149

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ Thank you for your interest in the firewatch project! Please find some informati

## Getting Started

### Jira User Permissions

Firewatch can be used with any user in a Jira instance, but that user will need to have proper permissions in the project
they are reporting to. The user should be able to:

- Create issues
- Add comments to issues
- Add attachments to issues
- Edit issues
- Transition issues (this only happens when a "success" issue is created, then immediately closed)

If you are using firewatch in the Red Hat Jira instance, the default user is `firewatch-tool`.

If you are encountering permissions issues, please add the user to the project you are reporting to under the role you
would like to choose. Typically, if you add the user in the `Developer` role, the tool will work as expected.

### Usage in OpenShift CI

Reporting issues using this tool in OpenShift CI is very simple, you can do one of the following:
Expand Down
16 changes: 15 additions & 1 deletion cli/objects/jira_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,19 @@ def add_labels_to_issue(self, issue_id_or_key: str, labels: list[str]) -> Issue:
Issue: A Jira Issue object.
"""
issue = self.get_issue_by_id_or_key(issue_id_or_key)
issue.update(update={"labels": [{"add": label} for label in labels]})
try:
issue.update(update={"labels": [{"add": label} for label in labels]})

# Check if the error is a 400 code and potentially due to user permissions.
except JIRAError as error:
if error.status_code == 400:
self.logger.error(
f"Failed to add labels to issue {issue_id_or_key}. Error: {error.text}",
)
self.logger.info(
"This error could be caused by missing permissions on the Jira user."
'Please see the "Jira User Permissions" section in the README for more information.',
)
else:
raise
return issue
Loading