Merlijn van Deen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/238837
Change subject: Move branch parsing to utils, add tests
......................................................................
Move branch parsing to utils, add tests
Moved to utils.py, added doctest + tox.ini
Change-Id: Ib41e96db00f30711c1e42ad0b7522a975dbe0f88
---
M forrestbot.py
A tox.ini
A utils.py
3 files changed, 35 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/tools/forrestbot
refs/changes/37/238837/1
diff --git a/forrestbot.py b/forrestbot.py
index 16903f5..befda21 100644
--- a/forrestbot.py
+++ b/forrestbot.py
@@ -13,6 +13,7 @@
import gerrit_rest
import phabricator as legophab
import config
+from utils import wmf_number
phab = legophab.Phabricator(
config.PHAB_HOST,
@@ -21,6 +22,8 @@
)
gerrit = gerrit_rest.GerritREST("https://gerrit.wikimedia.org/r")
+
+
@functools.lru_cache()
def get_master_branches(repository):
logging.debug("Requesting 'master' branches for %s" % repository)
@@ -28,27 +31,6 @@
projbranches = gerrit.branches(silly_encoded_name)
projbranches = [b['ref'] for b in projbranches]
-
- def wmf_number(branchname):
- """
- 'wmf/1.26wmf10' -> 12610
- 'wmf/1.25wmf8' -> 12508
- 'wmf/1.26wmf3-back' -> False # wtf Gather??
- 'wmf/phase0' -> False # wtf??
- """
- try:
- major, minor = branchname.split('wmf', 1)
- except ValueError:
- return False
- major = major.replace('.', '')
- try:
- int(minor)
- except ValueError:
- return False
- if len(minor) == 1:
- minor = '0' + minor
-
- return int(major + minor)
marker = 'refs/heads/wmf/'
newest_wmf = sorted([b.split(marker)[1] for b in projbranches
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..8e18b1c
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,7 @@
+[tox]
+envlist = py34
+skipsdist = True
+
+[testenv]
+deps = requests
+commands = python -m doctest utils.py
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..90446d5
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,25 @@
+def wmf_number(branchname):
+ """
+ >>> wmf_number('wmf/1.26wmf10')
+ 12610
+ >>> wmf_number('wmf/1.25wmf8')
+ 12508
+ >>> wmf_number('wmf/1.26wmf3-back') # wtf Gather??
+ False
+ >>> wmf_number('wmf/phase0')
+ False
+ """
+
+ try:
+ major, minor = branchname.split('wmf', 1)
+ except ValueError:
+ return False
+ major = major.replace('.', '')
+ try:
+ int(minor)
+ except ValueError:
+ return False
+ if len(minor) == 1:
+ minor = '0' + minor
+
+ return int(major + minor)
--
To view, visit https://gerrit.wikimedia.org/r/238837
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib41e96db00f30711c1e42ad0b7522a975dbe0f88
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/forrestbot
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits