Merge lp:~chad.smith/lp2kanban/allow-mps-linked-to-branch-cards into lp:lp2kanban

Proposed by Chad Smith
Status: Merged
Approved by: Chad Smith
Approved revision: 130
Merged at revision: 128
Proposed branch: lp:~chad.smith/lp2kanban/allow-mps-linked-to-branch-cards
Merge into: lp:lp2kanban
Diff against target: 151 lines (+39/-14)
3 files modified
src/lp2kanban/bugs2cards.py (+22/-8)
src/lp2kanban/kanban.py (+8/-4)
src/lp2kanban/tests/test_bugs2cards.py (+9/-2)
To merge this branch: bzr merge lp:~chad.smith/lp2kanban/allow-mps-linked-to-branch-cards
Reviewer Review Type Date Requested Status
Benji York (community) Approve
Review via email: mp+282684@code.launchpad.net

Commit message

Support branch cards that contain either a launchapad MP url or branch url. Emit warnings for cards that link to non-branch/MP urls.

Description of the change

Update regex to match both MP and branch url to kanban.

Add get_lp_branch_name to extract a valid branch url from either MP or branch links provided in card.external_system_url.

Also emit warnings if external_system_url isn't set to a launchpad branch or mp url so we can track down automation issues from jenkins output.

To test:

https://ci.lscape.net/view/Infrastructure/job/kanban-sync/configure
# change the repository URL from lp:lp2kanban to lp:~chad.smith/lp2kanban/allow-mps-linked-to-branch-cards

Then click build.
It'll run against our board
You can watch the "Activity Stream" accessible from the Pie chart icon on the right side of our board (https://canonical.leankit.com/Boards/View/102392996#workflow-view)

Any changes made by kanban-sync will be labelled as performed by "Landscape Robot"

Alternately you can run biuldout locally to setup a local python environment in ./bin/py
make configs
./create_creds.py (then authorize your user for everything in the browser that starts)
./bin/py -c configs/sync.ini -b "Lanscape 2016"

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This branch looks good.

review: Approve
131. By Chad Smith

use raw string for REGEX per review comment

Revision history for this message
Chad Smith (chad.smith) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lp2kanban/bugs2cards.py'
2--- src/lp2kanban/bugs2cards.py 2016-01-11 16:33:13 +0000
3+++ src/lp2kanban/bugs2cards.py 2016-01-15 16:15:22 +0000
4@@ -9,7 +9,7 @@
5 update_blueprints_from_work_items,
6 )
7 from lp2kanban.kanban import (
8- BRANCH_REGEX,
9+ BRANCH_MP_REGEX,
10 LeankitKanban,
11 LeankitTaskBoard,
12 Record,
13@@ -254,9 +254,15 @@
14 card_tags = set(card.tags.split(","))
15 if feature_tags.intersection(card_tags):
16 linked_cards.add(card)
17- if (branch_links and card.external_system_url and
18- BRANCH_REGEX.match(card.external_system_url)):
19- if card.external_system_url in branch_links:
20+ if branch_links and card.external_system_url:
21+ match = BRANCH_MP_REGEX.match(card.external_system_url)
22+ if not match:
23+ continue
24+ # Drop any merge content from branch
25+ user, project, branchname, _ = match.groups()
26+ url = "https://code.launchpad.net/~{}/{}/{}".format(
27+ user, project, branchname)
28+ if url in branch_links:
29 linked_cards.add(card)
30 return linked_cards
31
32@@ -341,7 +347,7 @@
33 has_id = (card.external_card_id is not None and
34 card.external_card_id.strip() != '')
35 has_branch = (card.external_system_url is not None and
36- BRANCH_REGEX.match(card.external_system_url))
37+ BRANCH_MP_REGEX.match(card.external_system_url))
38 if NO_SYNC_MARKER in card.title or NO_SYNC_MARKER in card.description:
39 return False
40 return (has_id or has_branch)
41@@ -569,6 +575,14 @@
42 return lp
43
44
45+def get_lp_branch_name(url):
46+ """Return the branch name from either an MP or branch url provided"""
47+ match = BRANCH_MP_REGEX.match(url)
48+ if match:
49+ return "~" + "/".join(match.groups()[:3])
50+ return None
51+
52+
53 def sync_board(board, bconf):
54 lp = get_lp(bconf)
55 all_projects = []
56@@ -600,8 +614,7 @@
57 if card.external_card_id:
58 # Cards with external_id are processed by getCardsWithExternalIds
59 continue
60- branch_name = card.external_system_url.replace(
61- "https://code.launchpad.net/", "")
62+ branch_name = get_lp_branch_name(card.external_system_url)
63 branch = lp.branches.getByUniqueName(unique_name=branch_name)
64 if not branch:
65 print "Invalid branch url ({}) for card '{}'".format(
66@@ -609,7 +622,8 @@
67 continue
68 if should_sync_card(card, bconf):
69 branch_info = get_branch_info([branch])
70- owner_name = BRANCH_REGEX.match(card.external_system_url).group(1)
71+ owner_name = BRANCH_MP_REGEX.match(
72+ card.external_system_url).group(1)
73 card_status = get_card_status(None, '', branch_info)
74 card_path = card.lane.path
75 if isinstance(card.lane.board, LeankitTaskBoard):
76
77=== modified file 'src/lp2kanban/kanban.py'
78--- src/lp2kanban/kanban.py 2016-01-11 16:33:13 +0000
79+++ src/lp2kanban/kanban.py 2016-01-15 16:15:22 +0000
80@@ -11,8 +11,8 @@
81
82
83 ANNOTATION_REGEX = re.compile('^\s*{.*}\s*$', re.MULTILINE|re.DOTALL)
84-BRANCH_REGEX = re.compile(
85- '^https://code.launchpad.net/~([.\w]*)/([-\w]*)/([-\w]*)$')
86+BRANCH_MP_REGEX = re.compile(
87+ r'^https?://code.launchpad.net/~([-.\w]*)/([-\w]*)/([-\w]*)/?(.*merge/\d+)?$')
88
89
90 class Record(dict):
91@@ -559,9 +559,13 @@
92 if card.description_annotations:
93 self._cards_with_description_annotations.add(card)
94 if card.external_system_url:
95+ url = card.external_system_url.encode('ascii', 'ignore')
96 self._cards_with_external_links.add(card)
97- if BRANCH_REGEX.match(card.external_system_url):
98+ if BRANCH_MP_REGEX.match(card.external_system_url):
99 self._cards_with_branches.add(card)
100+ else:
101+ print ("WARNING: Card won't sync. Non-branch link ({}) "
102+ "for {}.".format(url, card.title))
103 print " - %s feature cards" % len(
104 self._feature_cards)
105 print " - %s cards with external ids" % len(
106@@ -772,7 +776,7 @@
107 print " * %s (%d)" % (board.title, board.id)
108
109 # Get a board by the title.
110- board_name = 'Landscape Test Board'
111+ board_name = 'Landscape 2016'
112 print "Getting board '%s'..." % board_name
113 board = kanban.getBoard(title=board_name)
114 board.printLanes()
115
116=== modified file 'src/lp2kanban/tests/test_bugs2cards.py'
117--- src/lp2kanban/tests/test_bugs2cards.py 2016-01-11 16:33:13 +0000
118+++ src/lp2kanban/tests/test_bugs2cards.py 2016-01-15 16:15:22 +0000
119@@ -349,6 +349,7 @@
120 self.assertEqual(CardStatus.CODING, status)
121
122 BRANCH_URL = "https://code.launchpad.net/~me/project/branch-name"
123+MP_URL = "https://code.launchpad.net/~me/project/branch-name/+merge/1234"
124
125 class CardStatusTest(unittest.TestCase):
126
127@@ -639,16 +640,22 @@
128 """
129 linked_card = FauxCard(
130 tags="no-tag-match", external_system_url=BRANCH_URL)
131+ linked_card_with_trailing_slash = FauxCard(
132+ tags="no-tag-match", external_system_url=BRANCH_URL+"/")
133+ mp_linked_card = FauxCard(
134+ tags="no-tag-match", external_system_url=MP_URL)
135 tagged_card = FauxCard(
136 tags="feature1",
137 external_system_url=BRANCH_URL + "no-branch-match")
138 self.board.cards.extend([
139- linked_card, tagged_card,
140+ linked_card, tagged_card, mp_linked_card,
141+ linked_card_with_trailing_slash,
142 FauxCard(tags="no-tag-match",
143 external_system_url=BRANCH_URL + "no-branch-match")])
144 cards = get_cards_for_feature(self.feature_card, self.feature_bug)
145 self.assertItemsEqual([
146- self.feature_card, linked_card, tagged_card],
147+ self.feature_card, linked_card, linked_card_with_trailing_slash,
148+ mp_linked_card, tagged_card],
149 cards)
150
151 def test_get_cards_for_feature_gets_cards_with_either_tags_or_links(self):

Subscribers

People subscribed via source and target branches

to all changes: