Skip to content
Permalink
Browse files
[git-webkit] Redact bug title in branch name on alternate remotes
https://bugs.webkit.org/show_bug.cgi?id=239826
<rdar://problem/92418512>

Rubber-stamped by Aakash Jain.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:
(Branch.main): Allow caller to redact bug title in branch name.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.pull_request_branch_point): Redact bug title in branch name
for non-origin remotes.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/branch_unittest.py:
(TestBranch.test_redacted):

Canonical link: https://commits.webkit.org/250121@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293615 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Apr 29, 2022
1 parent 26a36d9 commit b4a2f3b4513b6f89987000ebbeef6b24cd709d27
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
@@ -1,3 +1,21 @@
2022-04-29 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Redact bug title in branch name on alternate remotes
https://bugs.webkit.org/show_bug.cgi?id=239826
<rdar://problem/92418512>

Rubber-stamped by Aakash Jain.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:
(Branch.main): Allow caller to redact bug title in branch name.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.pull_request_branch_point): Redact bug title in branch name
for non-origin remotes.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/branch_unittest.py:
(TestBranch.test_redacted):

2022-04-27 Jonathan Bedard <jbedard@apple.com>

[ews-build.webkit.org] Link to PRs with undefined title
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.12.0',
version='4.12.1',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)

version = Version(4, 12, 0)
version = Version(4, 12, 1)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
@@ -92,22 +92,24 @@ def to_branch_name(cls, value):
return string_utils.encode(result, target_type=str)

@classmethod
def main(cls, args, repository, why=None, **kwargs):
def main(cls, args, repository, why=None, redact=False, **kwargs):
if not isinstance(repository, local.Git):
sys.stderr.write("Can only 'branch' on a native Git repository\n")
return 1

if not args.issue:
args.issue = Terminal.input('{}nter name of new branch (or bug URL): '.format('{}, e'.format(why) if why else 'E'))

if string_utils.decode(args.issue).isnumeric() and Tracker.instance():
if string_utils.decode(args.issue).isnumeric() and Tracker.instance() and not redact:
issue = Tracker.instance().issue(int(args.issue))
if issue and issue.title:
args.issue = cls.to_branch_name(issue.title)
else:
issue = Tracker.from_string(args.issue)
if issue and issue.title:
if issue and issue.title and not redact:
args.issue = cls.to_branch_name(issue.title)
elif issue:
args.issue = str(issue.id)

args.issue = cls.normalize_branch_name(args.issue)

@@ -145,16 +145,21 @@ def check_pull_request_args(cls, repository, args):

@classmethod
def pull_request_branch_point(cls, repository, args, **kwargs):
# FIXME: We can do better by infering the remote from the branch point, if it's not specified
source_remote = args.remote or 'origin'

if repository.branch in repository.DEFAULT_BRANCHES or repository.PROD_BRANCHES.match(repository.branch):
if Branch.main(args, repository, why="'{}' is not a pull request branch".format(repository.branch), **kwargs):
if Branch.main(
args, repository,
why="'{}' is not a pull request branch".format(repository.branch),
redact=source_remote != 'origin', **kwargs
):
sys.stderr.write("Abandoning pushing pull-request because '{}' could not be created\n".format(args.issue))
return None
elif args.issue and repository.branch != args.issue:
sys.stderr.write("Creating a pull-request for '{}' but we're on '{}'\n".format(args.issue, repository.branch))
return None

# FIXME: We can do better by infering the remote from the branch point, if it's not specified
source_remote = args.remote or 'origin'
if not repository.config().get('remote.{}.url'.format(source_remote)):
sys.stderr.write("'{}' is not a remote in this repository\n".format(source_remote))
return None
@@ -27,7 +27,7 @@
from webkitbugspy import bugzilla, mocks as bmocks, radar
from webkitcorepy import OutputCapture, testing
from webkitcorepy.mocks import Time as MockTime, Terminal as MockTerminal, Environment
from webkitscmpy import local, program, mocks
from webkitscmpy import local, program, mocks, log


class TestBranch(testing.PathTestCase):
@@ -95,6 +95,24 @@ def test_prompt_url(self):
self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/Example-feature-1'...\n")
self.assertEqual(captured.stdout.getvalue(), "Enter name of new branch (or bug URL): \nCreated the local development branch 'eng/Example-feature-1'\n")

def test_redacted(self):
class MockOptions(object):
def __init__(self):
self.issue = None

with MockTerminal.input('<rdar://2>'), OutputCapture(level=logging.INFO) as captured, mocks.local.Git(self.path), \
bmocks.Radar(issues=bmocks.ISSUES), patch('webkitbugspy.Tracker._trackers', [radar.Tracker()]), mocks.local.Svn(), MockTime:

log.setLevel(logging.INFO)
self.assertEqual(0, program.Branch.main(
MockOptions(), local.Git(self.path),
redact=True,
))
self.assertEqual(local.Git(self.path).branch, 'eng/2')
self.assertEqual(captured.root.log.getvalue(), "Creating the local development branch 'eng/2'...\n")
self.assertEqual(captured.stdout.getvalue(), "Enter name of new branch (or bug URL): \nCreated the local development branch 'eng/2'\n")


def test_invalid_branch(self):
with OutputCapture() as captured, mocks.local.Git(self.path), mocks.local.Svn(), MockTime:
self.assertEqual(1, program.main(

0 comments on commit b4a2f3b

Please sign in to comment.