-
-
Notifications
You must be signed in to change notification settings - Fork 892
Remove internal user lookup #1874
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
Open
dimitarOnGithub
wants to merge
15
commits into
pycontribs:main
Choose a base branch
from
dimitarOnGithub:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
48cd70b
Remove lookup from watcher methods
dimitarOnGithub c12a221
Remove internal lookup from assign_issue
dimitarOnGithub b4e4aee
Update relevant code
dimitarOnGithub 59d2376
Allow User as param for watcher methods
dimitarOnGithub 77d3480
Test cases
dimitarOnGithub d6e15ce
Update examples.rst
dimitarOnGithub b0b552e
Docs & doc string fixes
dimitarOnGithub 974296e
Merge branch 'main' into main
dimitarOnGithub 790732d
Make auto lookup optional
dimitarOnGithub 6397dce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e732ab5
Merge branch 'main' into main
dimitarOnGithub 46265fc
Merge branch 'main' into main
dimitarOnGithub f1c46cf
Fix linter errors
dimitarOnGithub 35abeb9
Merge branch 'main' into main
dimitarOnGithub 045ca15
Merge branch 'pycontribs:main' into main
dimitarOnGithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -473,6 +473,7 @@ def __init__( | |||
kerberos_options: dict[str, Any] | None = None, | ||||
validate=False, | ||||
get_server_info: bool = True, | ||||
with_lookup: bool = True, | ||||
async_: bool = False, | ||||
async_workers: int = 5, | ||||
logging: bool = True, | ||||
|
@@ -665,6 +666,14 @@ def __init__( | |||
else: | ||||
self._version = (0, 0, 0) | ||||
|
||||
self.with_lookup = with_lookup | ||||
if with_lookup: | ||||
warnings.warn( | ||||
"Auto-lookup (with_lookup) has been set to True, the library will look-up the provided user " | ||||
"for its 'add_watcher', 'remove_watcher' and 'assign_issue' methods; this functionality " | ||||
"will be deprecated in future releases" | ||||
) | ||||
|
||||
if self._options["check_update"] and not JIRA.checked_version: | ||||
self._check_update_() | ||||
JIRA.checked_version = True | ||||
|
@@ -2264,18 +2273,25 @@ def _get_user_id(self, user: str | None) -> str | None: | |||
|
||||
# non-resource | ||||
@translate_resource_args | ||||
def assign_issue(self, issue: int | str, assignee: str | None) -> bool: | ||||
def assign_issue(self, issue: int | str, assignee: str | User | None) -> bool: | ||||
"""Assign an issue to a user. | ||||
|
||||
Args: | ||||
issue (Union[int, str]): the issue ID or key to assign | ||||
assignee (str): the user to assign the issue to. None will set it to unassigned. -1 will set it to Automatic. | ||||
assignee (Union[str, User]): username (for hosted) or account ID (for cloud) of the user to add to the | ||||
watchers list. Alternatively, you can provide the User object itself. | ||||
adehad marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
None will set it to unassigned. -1 will set it to Automatic. | ||||
|
||||
Returns: | ||||
bool | ||||
""" | ||||
url = self._get_latest_url(f"issue/{issue}/assignee") | ||||
user_id = self._get_user_id(assignee) | ||||
if isinstance(assignee, User): | ||||
user_id: str | None = self._get_user_identifier(assignee) | ||||
else: | ||||
user_id = assignee | ||||
if self.with_lookup: | ||||
user_id = self._get_user_id(user_id) | ||||
payload = {"accountId": user_id} if self._is_cloud else {"name": user_id} | ||||
self._session.put(url, data=json.dumps(payload)) | ||||
return True | ||||
|
@@ -2720,23 +2736,28 @@ def watchers(self, issue: str | int) -> Watchers: | |||
return self._find_for_resource(Watchers, issue) | ||||
|
||||
@translate_resource_args | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
def add_watcher(self, issue: str | int, watcher: str) -> Response: | ||||
def add_watcher(self, issue: str | int, watcher: str | User) -> Response: | ||||
"""Add a user to an issue's watchers list. | ||||
|
||||
Args: | ||||
issue (Union[str, int]): ID or key of the issue affected | ||||
watcher (str): name of the user to add to the watchers list | ||||
watcher (str | User): username (for hosted) or account ID (for cloud) of the user to add to the watchers | ||||
list | ||||
|
||||
Returns: | ||||
Response | ||||
""" | ||||
url = self._get_url("issue/" + str(issue) + "/watchers") | ||||
# Use user_id when adding watcher | ||||
watcher_id = self._get_user_id(watcher) | ||||
if isinstance(watcher, User): | ||||
watcher_id: str | None = self._get_user_identifier(watcher) | ||||
else: | ||||
watcher_id = watcher | ||||
if self.with_lookup: | ||||
watcher_id = self._get_user_id(watcher_id) | ||||
return self._session.post(url, data=json.dumps(watcher_id)) | ||||
|
||||
@translate_resource_args | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
def remove_watcher(self, issue: str | int, watcher: str) -> Response: | ||||
def remove_watcher(self, issue: str | int, watcher: str | User) -> Response: | ||||
"""Remove a user from an issue's watch list. | ||||
|
||||
Args: | ||||
|
@@ -2748,8 +2769,15 @@ def remove_watcher(self, issue: str | int, watcher: str) -> Response: | |||
""" | ||||
url = self._get_url("issue/" + str(issue) + "/watchers") | ||||
# https://docs.atlassian.com/software/jira/docs/api/REST/8.13.6/#api/2/issue-removeWatcher | ||||
user_id = self._get_user_id(watcher) | ||||
payload = {"accountId": user_id} if self._is_cloud else {"username": user_id} | ||||
if isinstance(watcher, User): | ||||
watcher_id: str | None = self._get_user_identifier(watcher) | ||||
else: | ||||
watcher_id = watcher | ||||
if self.with_lookup: | ||||
watcher_id = self._get_user_id(watcher_id) | ||||
payload = ( | ||||
{"accountId": watcher_id} if self._is_cloud else {"username": watcher_id} | ||||
) | ||||
result = self._session.delete(url, params=payload) | ||||
return result | ||||
|
||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be critical for this approach to work to remove this decorator which would have automagically converted the object to a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the decorator touches on the
User
objects, it seems to only manipulate theIssue
in this case