Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support version retrieval from custom branches
Fixes #251
  • Loading branch information
webknjaz committed Jun 9, 2018
commit fb8b84c37f7c868c2fb95f768b6e3a5defc0c105
9 changes: 8 additions & 1 deletion cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pathlib
import subprocess
import webbrowser
import re
import sys
import requests
import toml
Expand Down Expand Up @@ -72,10 +73,16 @@ def upstream(self):

@property
def sorted_branches(self):
def version_from_branch(branch):
try:
return tuple(map(int, re.match(r'^.*(?P<version>\d+(\.\d+)+).*$', branch).groupdict()['version'].split('.')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe reading regex template from config is even better?

Copy link
Contributor Author

@webknjaz webknjaz May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see how it's more flexible. I was thinking about this, but IRL regex is easy to screw up: they'll be exposed to the internals and helpless, and it would require them to actually scan through the code to figure out how it's being used, why and how to fix that.
It also looks like mixing up higher-level public API with implementation details, which IMHO should be separated.
So I'd be cautious when providing the end-users with such tooling.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe invite a syntax like stable-* where the star is version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be more complex than needed

except AttributeError as attr_err:
raise ValueError(f'Branch {branch} seems to not have a version in its name.') from attr_err

return sorted(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mariatta optionally we could try/except this as well and fall back to returning branches list in their original order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mariatta what do you think about falling back to unordered branch list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no need to support unordered branch list yet, I'm thinking to keep things as is and not change the behavior.

self.branches,
reverse=True,
key=lambda v: tuple(map(int, v.split('.'))))
key=version_from_branch)

@property
def username(self):
Expand Down