Skip to content

Commit 94fe7ff

Browse files
authored
🐛 fix(vsts): truncate vsts issue title length (#92207)
1 parent 4bd2afd commit 94fe7ff

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/sentry/integrations/vsts/issues.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"is currently Deleted within the following Microsoft Entra tenant"
3333
]
3434

35+
VSTS_ISSUE_TITLE_MAX_LENGTH = 128
36+
3537

3638
class VstsIssuesSpec(IssueSyncIntegration, SourceCodeIssueIntegration, ABC):
3739
description = "Integrate Azure DevOps work items by linking a project."
@@ -201,6 +203,9 @@ def create_issue(self, data: Mapping[str, str], **kwargs: Any) -> Mapping[str, A
201203
description = data["description"]
202204
item_type = data["work_item_type"]
203205

206+
if len(title) > VSTS_ISSUE_TITLE_MAX_LENGTH:
207+
title = title[: VSTS_ISSUE_TITLE_MAX_LENGTH - 3] + "..."
208+
204209
try:
205210
created_item = client.create_work_item(
206211
project=project_id,

tests/sentry/integrations/vsts/test_issues.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,41 @@ def test_create_issue(self):
193193
{"op": "add", "path": "/fields/System.History", "value": "<p>Fix this.</p>\n"},
194194
]
195195

196+
@responses.activate
197+
def test_create_issue_title_too_long(self):
198+
responses.add(
199+
responses.PATCH,
200+
"https://fabrikam-fiber-inc.visualstudio.com/0987654321/_apis/wit/workitems/$Microsoft.VSTS.WorkItemTypes.Task",
201+
body=WORK_ITEM_RESPONSE,
202+
content_type="application/json",
203+
)
204+
205+
long_title = "A" * 200 # Title longer than VSTS's 128 character limit
206+
expected_title = "A" * 125 + "..."
207+
208+
form_data = {
209+
"title": long_title,
210+
"description": "Fix this.",
211+
"project": "0987654321",
212+
"work_item_type": "Microsoft.VSTS.WorkItemTypes.Task",
213+
}
214+
assert self.integration.create_issue(form_data) == {
215+
"key": self.issue_id,
216+
"description": "Fix this.",
217+
"title": expected_title,
218+
"metadata": {"display_name": "Fabrikam-Fiber-Git#309"},
219+
}
220+
request = responses.calls[-1].request
221+
assert request.headers["Content-Type"] == "application/json-patch+json"
222+
payload = orjson.loads(request.body)
223+
assert payload == [
224+
{"op": "add", "path": "/fields/System.Title", "value": expected_title},
225+
# Adds both a comment and a description.
226+
# See method for details.
227+
{"op": "add", "path": "/fields/System.Description", "value": "<p>Fix this.</p>\n"},
228+
{"op": "add", "path": "/fields/System.History", "value": "<p>Fix this.</p>\n"},
229+
]
230+
196231
@responses.activate
197232
def test_create_issue_failure(self):
198233
form_data = {

0 commit comments

Comments
 (0)