jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324211?usp=email )

Change subject: welcome: Reuse user edit count
......................................................................

welcome: Reuse user edit count

Retain the edit count while applying the welcome threshold.

Reuse it for the zero check and status message instead of looking it up again.

Change-Id: I24712e3f0e6f5960aef5d12a0a1be7996454f787
---
M scripts/welcome.py
M tests/welcome_tests.py
2 files changed, 23 insertions(+), 3 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/scripts/welcome.py b/scripts/welcome.py
index 22d87bb..35e2186 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -837,10 +837,10 @@
             self.show_status(Msg.SKIP)
             pywikibot.info(f'{user.username} might be a global bot!')

-        elif user.editCount() < globalvar.attach_edit_count:
-            if user.editCount() != 0:
+        elif (edit_count := user.editCount()) < globalvar.attach_edit_count:
+            if edit_count != 0:
                 self.show_status(Msg.IGNORE)
-                pywikibot.info(f'{user.username} has only {user.editCount()}'
+                pywikibot.info(f'{user.username} has only {edit_count}'
                                ' contributions.')
             elif not globalvar.quiet:
                 self.show_status(Msg.IGNORE)
diff --git a/tests/welcome_tests.py b/tests/welcome_tests.py
index 03f8ba7..8139ac7 100755
--- a/tests/welcome_tests.py
+++ b/tests/welcome_tests.py
@@ -21,6 +21,26 @@

     net = False

+    def test_skip_page_reuses_edit_count(self) -> None:
+        """Test that the edit count is retrieved once."""
+        bot = SimpleNamespace(show_status=MagicMock())
+        user = MagicMock(username='Alice')
+        user.is_blocked.return_value = False
+        user.is_locked.return_value = False
+        user.groups.return_value = []
+        user.editCount.return_value = 1
+
+        with (
+            patch.object(welcome.globalvar, 'attach_edit_count', 2),
+            patch.object(welcome.pywikibot, 'info') as info,
+        ):
+            result = welcome.WelcomeBot.skip_page(bot, user)
+
+        self.assertTrue(result)
+        user.editCount.assert_called_once_with()
+        bot.show_status.assert_called_once_with(welcome.Msg.IGNORE)
+        info.assert_called_once_with('Alice has only 1 contributions.')
+
     def test_signature_file_closed_on_read_error(self) -> None:
         """Test that the signature file is closed when reading fails."""
         file_obj = MagicMock()

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324211?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I24712e3f0e6f5960aef5d12a0a1be7996454f787
Gerrit-Change-Number: 1324211
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to