From e8d4bbd03061afb0dac572cf911313fb2e82e54a Mon Sep 17 00:00:00 2001 From: Lacey Williams Henschel Date: Thu, 15 Dec 2022 16:02:42 -0800 Subject: [PATCH] :bug: GH issue titles can be quite long; truncate them --- libraries/github.py | 2 +- libraries/tests/test_github.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libraries/github.py b/libraries/github.py index f96f3b32..35fd62aa 100644 --- a/libraries/github.py +++ b/libraries/github.py @@ -358,7 +358,7 @@ class GithubUpdater: library=self.library, github_id=issue_dict["id"], defaults={ - "title": issue_dict["title"], + "title": issue_dict["title"][:255], "number": issue_dict["number"], "is_open": issue_dict["state"] == "open", "closed": closed_at, diff --git a/libraries/tests/test_github.py b/libraries/tests/test_github.py index 2fdf788d..447dfc6b 100644 --- a/libraries/tests/test_github.py +++ b/libraries/tests/test_github.py @@ -83,6 +83,29 @@ def test_update_issues_existing(tp, library, github_api_repo_issues_response): assert issue.title == existing_issue_data.title +def test_update_issues_long_title(tp, library, github_api_repo_issues_response): + """GithubUpdater.update_issues()""" + new_issues_count = len(github_api_repo_issues_response) + expected_count = Issue.objects.count() + new_issues_count + title = "sample" * 100 + assert len(title) > 255 + expected_title = title[:255] + assert len(expected_title) <= 255 + + with patch("libraries.github.repo_issues") as repo_issues_mock: + updater = GithubUpdater(library=library) + # Make an extra-long title so we can confirm that it saves + github_id = github_api_repo_issues_response[0]["id"] + github_api_repo_issues_response[0]["title"] = "sample" * 100 + repo_issues_mock.return_value = github_api_repo_issues_response + updater.update_issues() + + assert Issue.objects.count() == expected_count + assert Issue.objects.filter(library=library, github_id=github_id).exists() + issue = Issue.objects.get(library=library, github_id=github_id) + assert issue.title == expected_title + + # LibraryUpdater tests