Skip to content
Permalink
Browse files
[GitHub] git commit generates a nicely formatted commit log but is …
…missing bug information

https://bugs.webkit.org/show_bug.cgi?id=240254
<rdar://93033766 >

Reviewed by Chris Dumez.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py: Add "commit" program.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:
(Branch.main): Invoke Commit.bug_urls.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py:
(FilteredCommand.parser): Typo fix in log message.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/commit.py: Added.
(Commit.parser):
(Commit.bug_urls): Extract a list of bug URLs from an issue.
(Commit.main): Extract commit message information from issue.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py:

Canonical link: https://commits.webkit.org/250445@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294011 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed May 10, 2022
1 parent fc7ac06 commit 09604eb79b422e6ef76deb0f8671d68a8a8dacb1
@@ -1,3 +1,24 @@
2022-05-10 Jonathan Bedard <jbedard@apple.com>

[GitHub] `git commit` generates a nicely formatted commit log but is missing bug information
https://bugs.webkit.org/show_bug.cgi?id=240254
<rdar://93033766 >

Reviewed by Chris Dumez.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py: Add "commit" program.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:
(Branch.main): Invoke Commit.bug_urls.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py:
(FilteredCommand.parser): Typo fix in log message.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/commit.py: Added.
(Commit.parser):
(Commit.bug_urls): Extract a list of bug URLs from an issue.
(Commit.main): Extract commit message information from issue.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py:

2022-05-09 Oriol Brufau <obrufau@igalia.com>

[cssom] Don't index perspective/transform-origin-* in computed styles
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.13.2',
version='4.14.0',
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, 13, 2)
version = Version(4, 14, 0)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
@@ -30,6 +30,7 @@
from .canonicalize import Canonicalize
from .clean import Clean
from .command import Command
from .commit import Commit
from .checkout import Checkout
from .credentials import Credentials
from .find import Find, Info
@@ -74,7 +75,12 @@ def main(
)

subparsers = parser.add_subparsers(help='sub-command help')
programs = [Blame, Branch, Canonicalize, Checkout, Clean, Find, Info, Land, Log, Pull, PullRequest, Revert, Setup, InstallGitLFS, Credentials]
programs = [
Blame, Branch, Canonicalize, Checkout,
Clean, Find, Info, Land, Log, Pull,
PullRequest, Revert, Setup, InstallGitLFS,
Credentials, Commit,
]
if subversion:
programs.append(SetupGitSvn)

@@ -24,6 +24,7 @@
import sys

from .command import Command
from .commit import Commit

from webkitbugspy import Tracker
from webkitcorepy import run, string_utils, Terminal
@@ -131,13 +132,7 @@ def main(cls, args, repository, why=None, redact=False, **kwargs):

if issue:
args._title = issue.title
args._bug_urls = [issue.link]
types = [type(issue.tracker)]
for related in issue.references:
if type(related.tracker) in types:
continue
args._bug_urls.append(related.link)
types.append(type(related.tracker))
args._bug_urls = Commit.bug_urls(issue)

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

@@ -71,7 +71,7 @@ def parser(cls, parser, loggers=None):
parser.add_argument(
'args', nargs='*',
type=str, default=None,
help='Arguments to be passed to tbe native source-code management tool',
help='Arguments to be passed to the native source-code management tool',
)
parser.add_argument(
'--identifier', '-i',
@@ -0,0 +1,105 @@
# Copyright (C) 2022 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import sys

from .command import Command

from webkitbugspy import Tracker
from webkitcorepy import run, string_utils
from webkitscmpy import local


class Commit(Command):
name = 'commit'
help = 'Create a new commit containing the current contents of the index ' \
'passing any provided issue to the commit message.'

@classmethod
def parser(cls, parser, loggers=None):
parser.add_argument(
'args', nargs='*',
type=str, default=None,
help='Arguments to be passed to `git commit`',
)
parser.add_argument(
'-i', '--issue', '-b', '--bug', '-r',
dest='issue', type=str,
help='Number (or url) of the issue or bug to create branch for',
)
parser.add_argument(
'-a', '--all',
dest='all', action='store_true', default=False,
help='Tell the command to automatically stage files that have been modified and '
'deleted, but new files you have not told Git about are not affected.',
)
parser.add_argument(
'--amend',
dest='amend', action='store_true', default=False,
help='Replace the tip of the current branch by creating a new commit',
)

@classmethod
def bug_urls(cls, issue):
if not issue:
return ''

bug_urls = [issue.link]
types = [type(issue.tracker)]
for related in issue.references:
if type(related.tracker) in types:
continue
bug_urls.append(related.link)
types.append(type(related.tracker))
return bug_urls

@classmethod
def main(cls, args, repository, command=None, representation=None, **kwargs):
if not isinstance(repository, local.Git):
sys.stderr.write("Can only '{}' on a native Git repository\n".format(cls.name))
return 1

issue = None
if args.issue:
if string_utils.decode(args.issue).isnumeric() and Tracker.instance():
issue = Tracker.instance().issue(int(args.issue))
else:
issue = Tracker.from_string(args.issue)
if not issue:
sys.stderr.write("'{}' cannot be converted to an issue\n".format(args.issue))
return 1

additional_args = []
if args.all:
additional_args += ['--all']
if args.amend:
additional_args += ['--amend']

env = os.environ
env['COMMIT_MESSAGE_TITLE'] = issue.title if issue else ''
env['COMMIT_MESSAGE_BUG'] = '\n'.join(cls.bug_urls(issue))
return run(
[repository.executable(), 'commit', '--date=now'] + additional_args + args.args,
cwd=repository.root_path,
env=env,
).returncode
@@ -1,4 +1,4 @@
# Copyright (C) 2020 Apple Inc. All rights reserved.
# Copyright (C) 2020-2022 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -21,10 +21,16 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import json
import logging
import os
import unittest

from mock import patch
from datetime import datetime
from webkitscmpy import Commit, Contributor
from webkitbugspy import bugzilla, mocks as bmocks
from webkitcorepy import OutputCapture, testing
from webkitcorepy.mocks import Environment
from webkitscmpy import Contributor, Commit, program, mocks


class TestCommit(unittest.TestCase):
@@ -298,3 +304,89 @@ def test_from_json_str(self):
message='Message'
),
)


class TestDoCommit(testing.PathTestCase):
basepath = 'mock/repository'
BUGZILLA = 'https://bugs.example.com'

def setUp(self):
super(TestDoCommit, self).setUp()
os.mkdir(os.path.join(self.path, '.git'))
os.mkdir(os.path.join(self.path, '.svn'))

def test_svn(self):
with OutputCapture(level=logging.INFO) as captured, mocks.local.Git(), mocks.local.Svn(self.path), patch(
'webkitbugspy.Tracker._trackers', []):
self.assertEqual(1, program.main(
args=('commit',),
path=self.path,
))
self.assertEqual(captured.root.log.getvalue(), '')
self.assertEqual(captured.stderr.getvalue(), "Can only 'commit' on a native Git repository\n")

def test_none(self):
with OutputCapture(level=logging.INFO) as captured, mocks.local.Git(), mocks.local.Svn(), patch(
'webkitbugspy.Tracker._trackers', []):
self.assertEqual(1, program.main(
args=('commit',),
path=self.path,
))
self.assertEqual(captured.stderr.getvalue(), "Can only 'commit' on a native Git repository\n")

def test_commit(self):
with OutputCapture(level=logging.INFO) as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), patch('webkitbugspy.Tracker._trackers', []):
repo.staged['added.txt'] = 'added'
self.assertEqual(0, program.main(
args=('commit',),
path=self.path,
))
self.assertDictEqual(repo.staged, {})
self.assertEqual(repo.head.hash, 'c28f53f7fabd7bd9535af890cb7dc473cb342999')
self.assertEqual(
'[Testing] Creating commits\n'
'Reviewed by Jonathan Bedard\n\n'
' * added.txt\n',
repo.head.message,
)

self.assertEqual(
'\n'.join([line for line in captured.root.log.getvalue().splitlines() if 'Mock process' not in line]),
'')
self.assertEqual(captured.stdout.getvalue(), "")
self.assertEqual(captured.stderr.getvalue(), "")

def test_commit_with_bug(self):
with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub(
projects=bmocks.PROJECTS) as remote, bmocks.Bugzilla(
self.BUGZILLA.split('://')[-1],
projects=bmocks.PROJECTS, issues=bmocks.ISSUES,
environment=Environment(
BUGS_EXAMPLE_COM_USERNAME='tcontributor@example.com',
BUGS_EXAMPLE_COM_PASSWORD='password',
)), patch(
'webkitbugspy.Tracker._trackers', [bugzilla.Tracker(self.BUGZILLA)],
), mocks.local.Git(
self.path, remote='https://{}'.format(remote.remote),
remotes=dict(fork='https://{}/Contributor/WebKit'.format(remote.hosts[0])),
) as repo, mocks.local.Svn():
repo.staged['added.txt'] = 'added'
self.assertEqual(0, program.main(
args=('commit', '-i', '3', ),
path=self.path,
))
self.assertDictEqual(repo.staged, {})
self.assertEqual(repo.head.hash, '0cc822a8ca16698e13363f917e3d9dad387141a4')
self.assertEqual(
'Example issue 2\n'
'https://bugs.example.com/show_bug.cgi?id=3\n'
'Reviewed by Jonathan Bedard\n\n'
' * added.txt\n',
repo.head.message,
)

self.assertEqual(
'\n'.join([line for line in captured.root.log.getvalue().splitlines() if 'Mock process' not in line]),
'')
self.assertEqual(captured.stdout.getvalue(), "")
self.assertEqual(captured.stderr.getvalue(), "")

0 comments on commit 09604eb

Please sign in to comment.