Page MenuHomePhabricator

Pywikibot contribution howto
Open, Needs TriagePublic

Description

Some of the features are suitable to be added directly to the Pywikibot which is library what we are using for mediawiki API access. Basic concept is that when fixing Pywikibot bug is that you:

1.) register Wikitech and Gerrit account ( gerrit = codereview)
2.) Create Phabricator ticket for the bug or feature what you are doing
3.) When ready submit change to gerrit for code review
4.) When it is OK in gerrit it will be merged to production

Documentation

Howto setup Wikitech account

1.) Create wikitech-account

2.) Setup gerrit-account and ssh-keys

Howto Install development enviroment

python -m venv venv 
source venv/bin/activate    
git clone --recursive ssh://WIKITECH_USERNAME@gerrit.wikimedia.org:29418/pywikibot/core.git pywikibot-git 
cd pywikibot-git
pip install --upgrade pip
pip install -r requirements.txt
pip install flake8
pip install git-review
cp user-config.py.sample user-config.py

And update user-config.py with correct Wikimedia Commons user name

  • Config Git-review **

Setup emails and settings in gerrit first: https://gerrit.wikimedia.org/r/settings/

then setup git

cd pywikibot-git
git config user.email "EMAIL"
git config user.name "USERNAME"
git review -s --verbose

; Running code

Example code for running logevents

import pywikibot
from datetime import datetime, timedelta

site = pywikibot.Site('en', 'wikipedia')
end_time = pywikibot.Timestamp.now()
start_time = end_time - timedelta(days=7)

for entry in site.logevents(start=start_time, end=end_time, total=50, reverse=True):
    print(f"{entry.timestamp()}: {entry.type()} - {entry.action()}")

Running code
Running code using the github version of pywikibot

python pwb.py myscript.py

Tests
Add test case for testing missing oauth permission to Pywikibot tests to tests/sparql_tests.py

python -m unittest -v tests.site_tests

Howto test code formatting

flake8 tests/sparql_tests.py

Howto push change to review
Basic idea:

  • Only single commits are viewed
  • All reviewed commits are reviewed against current master
  • When new version of the commit is reviewed the user dev-branch is updated to latest master and changes are amended to single commit
  • Reviews and phabricator tickets are linked using phabricator ticket in commit message
  • Commit message is message which will be shown as commit message when change is merged to master

Example commit message

  • First line is title without ticketnumber or prefix.
  • Second line is empty line
  • Next lines are description
  • Then is one empty line and line which contains text "Bug: " and Phabricator ticket number.
Give visible error to user when there are no rights.

Currently bot does not give user-visible output when
user is not logged in or user does not have permissions.
Instead of silently failing inform user of a problem.

Bug: T345342

Submitting first version

git checkout -b bugfix/T123456-short-description
DO CHANGES
git stash
git fetch —-all
git pull --rebase origin master
git stash pop
git status
git ADD CHANGED FILE
git commit
git review

Submit updated versions to re-review

DO CHANGES
git stash
git fetch —-all
git pull --rebase origin master
FIX MERGE CONFLICTS
git add fixed file
git rebase --continue
git stash pop
git status
git ADD CHANGED FILE
git commit --amend
git review

Howto test something in gerrit

  • 959755 is gerrit id number
git review -d 959755