Skip to content

gdap issue fix - #441

Merged
Bala-Sakabattula merged 5 commits into
release-engineering:mainfrom
Bala-Sakabattula:GDAP-issue
Mar 30, 2026
Merged

Bala-Sakabattula merged 5 commits into
release-engineering:mainfrom
Bala-Sakabattula:GDAP-issue

Conversation

@Bala-Sakabattula

Copy link
Copy Markdown
Collaborator

Fixed GDAP issue by updating the comment format function and modifying user assignment to use query parameters with the search_users function in the Jira client library.

@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Fix Jira Cloud GDAP compatibility with accountId-based assignment

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Updated match_user() to return dict with accountId for Jira Cloud compatibility
• Changed search_users() calls to use query= parameter instead of user= for GDPR strict mode
• Modified user assignment to use accountId instead of name for Jira Cloud
• Updated comment formatting to use accountId in user mentions
• Fixed user attribute access with getattr() for optional fields like displayName and
  accountId
Diagram
flowchart LR
  A["match_user function"] -->|"returns Dict with accountId"| B["assign_user function"]
  C["search_users calls"] -->|"use query= parameter"| A
  C -->|"use query= parameter"| D["format_comment function"]
  B -->|"assign by accountId"| E["Jira Cloud API"]
  D -->|"mention by accountId"| E
Loading

Grey Divider

File Changes

1. sync2jira/downstream_issue.py 🐞 Bug fix +31/-20

Jira Cloud accountId-based user assignment and query parameter fix

• Updated match_user() return type from Optional[str] to Optional[Dict[str, str]] with name
 and accountId keys
• Changed search_users() call to use query= parameter for Jira Cloud GDPR strict mode
• Modified user attribute access to use getattr() for optional fields (displayName, accountId,
 emailAddress)
• Updated assign_user() to assign issues using accountId instead of name
• Added import of Dict type from typing module

sync2jira/downstream_issue.py


2. sync2jira/downstream_pr.py 🐞 Bug fix +4/-3

Update PR comment formatting for Jira Cloud accountId

• Changed search_users() call to use query= parameter instead of user= for Jira Cloud GDPR
 strict mode
• Updated comment formatting to use accountId instead of key for user mentions
• Added safe attribute access with getattr() for accountId field

sync2jira/downstream_pr.py


3. tests/test_downstream_issue.py 🧪 Tests +12/-8

Update tests for accountId-based user assignment

• Added accountId attribute to mock user objects in multiple test cases
• Updated test assertions to expect accountId in assignment calls instead of name
• Changed search_users() mock calls to use query= parameter
• Updated test comments to clarify Jira Cloud behavior

tests/test_downstream_issue.py


View more (1)
4. tests/test_downstream_pr.py 🧪 Tests +4/-1

Update PR comment tests for accountId formatting

• Added accountId attribute to mock user object in setUp
• Updated test assertions to expect accountId in comment formatting
• Added assertions to verify search_users() is called with query= parameter
• Updated expected comment format to use accountId instead of key

tests/test_downstream_pr.py


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Mar 20, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Join None displayName ☑ 🐞 Bug ⛯ Reliability
Description
In match_user(), the warning log builds a string via `', '.join(getattr(u, 'displayName', None)
...); if any displayName is None/missing, join() raises TypeError` and aborts user matching.
This can prevent assignment sync from running in the multi-match path.
Code

sync2jira/downstream_issue.py[R595-601]

   log.warning(
       "Found %d Jira users for %r:  %s%s",
       len(users),
       email,
-            ", ".join(u.name for u in users[0:limit]),
+            ", ".join(getattr(u, "displayName", None) for u in users[0:limit]),
       "..." if len(users) > limit else "",
   )
Evidence
The PR changed the log formatting from joining u.name strings to joining `getattr(u,
'displayName', None) values, which can include None`. In the same function the code already uses
the safer ... or "" pattern for displayName, showing the intended fallback behavior but it’s not
applied to the join.

sync2jira/downstream_issue.py[586-601]
sync2jira/downstream_issue.py[589-592]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`match_user()` can throw `TypeError` when logging multiple matching Jira users because it passes `None` values into `", ".join(...)`.
### Issue Context
The function already uses `getattr(..., None) or ""` for `displayName` when constructing the return dict; the same defensive pattern should be applied when building the warning message.
### Fix Focus Areas
- sync2jira/downstream_issue.py[594-601]
- sync2jira/downstream_issue.py[586-592]
### Expected change
Update the join expression to only join strings, e.g. `", ".join((getattr(u, "displayName", None) or "") for u in users[:limit])`, or fall back to `u.name` when `displayName` is missing.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Server assignee sync broken 🐞 Bug ✓ Correctness
Description
assign_user() now assigns only when a matched Jira user has accountId; on Jira Server/Data
Center this field typically doesn’t exist, so upstream assignee syncing will silently stop assigning
and fall back to owner/unassigned. This is a breaking change because the project documentation and
other code paths still assume Jira “username/name” semantics.
Code

sync2jira/downstream_issue.py[R651-656]

+        matched = match_user(emails, client)
+        if matched and matched.get("accountId"):
+            # Jira Cloud assigns by accountId
+            downstream.update({"assignee": {"accountId": matched["accountId"]}})
+            log.info("Assigned %s to %r", downstream.key, matched.get("name"))
       return
Evidence
The new gate if matched and matched.get('accountId'): prevents assignment unless accountId is
present. The documentation explicitly shows configuration against non-Atlassian.net Jira servers,
and the codebase still uses/clears assignees by name in other paths, indicating Server/DC support
is expected.

sync2jira/downstream_issue.py[633-638]
sync2jira/downstream_issue.py[650-656]
sync2jira/downstream_issue.py[1110-1144]
docs/source/quickstart.rst[19-40]
docs/source/config-file.rst[161-165]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Assignee syncing is now Cloud-only: `assign_user()` updates the issue only when `accountId` is present. On Jira Server/Data Center, this prevents assignment entirely.
### Issue Context
The repo documentation shows non-Atlassian.net Jira servers as supported, and other code still uses `assignee.name` and clears assignees via `{"name": ""}`.
### Fix Focus Areas
- sync2jira/downstream_issue.py[571-617]
- sync2jira/downstream_issue.py[633-656]
- sync2jira/downstream_issue.py[1110-1152]
- docs/source/quickstart.rst[19-40]
### Expected change
Implement a dual-path assignment:
- If `accountId` exists: `downstream.update({"assignee": {"accountId": ...}})` (Cloud)
- Else fall back to Server/DC identifiers (commonly `name` or `key`, depending on your Jira/python-jira usage): `downstream.update({"assignee": {"name": ...}})`
Also add/adjust unit tests to cover `accountId` missing but `name` present to prevent future regressions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Reporter mention becomes [~None] ☑ 🐞 Bug ✓ Correctness
Description
format_comment() constructs a Jira mention using accountId even when it’s missing, which
produces the literal string [~None] in the comment body. This degrades comment correctness and can
prevent proper reporter attribution in synced PR comments.
Code

sync2jira/downstream_pr.py[R44-51]

+    # Find the pr.reporter's Jira user (use query= for Jira Cloud GDPR strict mode).
+    ret = client.search_users(query=pr.reporter)
# Loop through ret till we find a match
for user in ret:
   if user.displayName == pr.reporter:
-            reporter = f"[~{user.key}]"
+            aid = getattr(user, "accountId", None)
+            reporter = f"[~{aid}]"
       break
Evidence
The code uses getattr(user, 'accountId', None) and immediately interpolates it into the mention
format without checking for a non-empty value, so a missing accountId will render as [~None].

sync2jira/downstream_pr.py[44-53]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`format_comment()` can emit invalid mention markup (`[~None]`) when the matched user lacks `accountId`.
### Issue Context
The function currently matches by `displayName`, then unconditionally formats a mention using `accountId`.
### Fix Focus Areas
- sync2jira/downstream_pr.py[44-53]
### Expected change
Only use the accountId-based mention when `aid` is truthy; otherwise fall back to a safe identifier (e.g., the prior `user.key` behavior or plain `pr.reporter`). Add a unit test where `search_users()` returns a user with matching `displayName` but `accountId=None` to verify the fallback.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread sync2jira/downstream_issue.py Resolved
Comment thread sync2jira/downstream_issue.py Resolved
Comment thread sync2jira/downstream_pr.py Resolved
webbnh

This comment was marked as resolved.

webbnh

This comment was marked as resolved.

@Bala-Sakabattula

Copy link
Copy Markdown
Collaborator Author

@webbnh I looked and implemented the suggestion..Thanks!!

webbnh

This comment was marked as resolved.

@webbnh webbnh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Bala-Sakabattula
Bala-Sakabattula merged commit 2865eb7 into release-engineering:main Mar 30, 2026
5 checks passed
@Bala-Sakabattula
Bala-Sakabattula deleted the GDAP-issue branch March 30, 2026 18:58
@qodo-for-releng qodo-for-releng Bot mentioned this pull request Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants