jenkins-bot submitted this change.

View Change

Approvals: Meno25: Looks good to me, approved jenkins-bot: Verified
[bugfix] Take rollbacktoken in revertbot.py

Bug: T250509
Change-Id: Ic7200cb37bb8ead7634cba197eeb579c7b65772f
---
M scripts/revertbot.py
1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index b5dabce..38c071c 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -99,38 +99,40 @@
"""Revert a single item."""
page = pywikibot.Page(self.site, item['title'])
history = list(page.revisions(total=2))
- if len(history) > 1:
- rev = history[1]
- else:
+ if len(history) <= 1:
return False

- comment = i18n.twtranslate(
- self.site, 'revertbot-revert',
- {'revid': rev.revid,
- 'author': rev.user,
- 'timestamp': rev.timestamp})
-
- if self.opt.comment:
- comment += ': ' + self.opt.comment
+ rev = history[1]

pywikibot.output(color_format(
'\n\n>>> {lightpurple}{0}{default} <<<',
page.title(as_link=True, force_interwiki=True, textlink=True)))

if not self.opt.rollback:
+ comment = i18n.twtranslate(
+ self.site, 'revertbot-revert',
+ {'revid': rev.revid,
+ 'author': rev.user,
+ 'timestamp': rev.timestamp})
+ if self.opt.comment:
+ comment += ': ' + self.opt.comment
+
old = page.text
page.text = page.getOldVersion(rev.revid)
pywikibot.showDiff(old, page.text)
page.save(comment)
return comment

+ params = {
+ 'action': 'rollback',
+ 'title': page,
+ 'user': self.user,
+ 'token': self.site.tokens['rollback'],
+ 'markbot': True,
+ }
try:
- pywikibot.data.api.Request(
- self.site, parameters={'action': 'rollback',
- 'title': page,
- 'user': self.user,
- 'token': rev.rollbacktoken,
- 'markbot': True}).submit()
+ r = pywikibot.data.api.Request(self.site, parameters=params)
+ r.submit()
except pywikibot.data.api.APIError as e:
if e.code == 'badtoken':
pywikibot.error(
@@ -138,7 +140,7 @@
else:
pywikibot.exception()
return False
- return 'The edit(s) made in {0} by {1} was rollbacked'.format(
+ return 'The edit(s) made in {} by {} was rollbacked'.format(
page.title(), self.user)

def log(self, msg) -> None:

To view, visit change 640414. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic7200cb37bb8ead7634cba197eeb579c7b65772f
Gerrit-Change-Number: 640414
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Meno25 <meno25mail@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged