Skip to content
Permalink
Browse files
[git-webkit] Link issue to pull requests
https://bugs.webkit.org/show_bug.cgi?id=236339
<rdar://problem/88657772>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.main): Add link to pull request in issue comments, assign issue to
pull request author.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:


Canonical link: https://commits.webkit.org/247170@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@289684 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Feb 12, 2022
1 parent a55af93 commit 69b1ce5d29e42754bb97fc95d64c5f19ae3a32fb
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 5 deletions.
@@ -1,3 +1,18 @@
2022-02-09 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Link issue to pull requests
https://bugs.webkit.org/show_bug.cgi?id=236339
<rdar://problem/88657772>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
(PullRequest.main): Add link to pull request in issue comments, assign issue to
pull request author.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/pull_request_unittest.py:

2022-02-09 Jonathan Bedard <jbedard@apple.com>

[EWS] Rebase PRs on tip of branch
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.1.2',
version='4.1.3',
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, 1, 2)
version = Version(4, 1, 3)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
@@ -27,6 +27,7 @@
from .command import Command
from .branch import Branch

from webkitbugspy import Tracker
from webkitcorepy import arguments, run, Terminal
from webkitscmpy import local, log, remote

@@ -207,6 +208,12 @@ def main(cls, args, repository, **kwargs):
existing_pr = None
commits = list(repository.commits(begin=dict(hash=branch_point.hash), end=dict(branch=repository.branch)))

issue = None
for line in commits[0].message.split() if commits[0] and commits[0].message else []:
issue = Tracker.from_string(line)
if issue:
break

if existing_pr:
log.info("Updating pull-request for '{}'...".format(repository.branch))
pr = rmt.pull_requests.update(
@@ -233,6 +240,17 @@ def main(cls, args, repository, **kwargs):
sys.stderr.write("Failed to create pull-request for '{}'\n".format(repository.branch))
return 1
print("Created '{}'!".format(pr))

if issue:
log.info('Checking issue assignee...')
if issue.assignee != issue.tracker.me():
issue.assign(issue.tracker.me())
print('Assigning associated issue to {}'.format(issue.tracker.me()))
log.info('Checking for pull request link in associated issue...')
if pr.url and not any([pr.url in comment.content for comment in issue.comments]):
issue.add_comment('Pull request: {}'.format(pr.url))
print('Posted pull request link to {}'.format(issue.link))

if pr.url:
print(pr.url)

@@ -1,4 +1,4 @@
# Copyright (C) 2021 Apple Inc. All rights reserved.
# Copyright (C) 2021-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
@@ -23,11 +23,13 @@
import logging
import os
import sys
import time
import unittest

from webkitbugspy import User
from mock import patch
from webkitbugspy import Tracker, User, bugzilla, radar, mocks as bmocks
from webkitcorepy import OutputCapture, testing, log as wcplog
from webkitcorepy.mocks import Terminal as MockTerminal
from webkitcorepy.mocks import Terminal as MockTerminal, Environment
from webkitscmpy import Contributor, Commit, PullRequest, local, program, mocks, remote, log as wsplog


@@ -250,6 +252,7 @@ def test_parse_html_body_single(self):

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

def setUp(self):
super(TestDoPullRequest, self).setUp()
@@ -461,6 +464,58 @@ def test_github_reopen(self):
],
)

def test_github_bugzilla(self):
with OutputCapture(level=logging.INFO) as captured, mocks.remote.GitHub() as remote, bmocks.Bugzilla(
self.BUGZILLA.split('://')[-1],
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)) as repo, mocks.local.Svn():

repo.commits['eng/pr-branch'] = [Commit(
hash='06de5d56554e693db72313f4ca1fb969c30b8ccb',
branch='eng/pr-branch',
author=dict(name='Tim Contributor', emails=['tcontributor@example.com']),
identifier="5.1@eng/pr-branch",
timestamp=int(time.time()),
message='[Testing] Existing commit\nbugs.example.com/show_bug.cgi?id=1'
)]
repo.head = repo.commits['eng/pr-branch'][-1]
self.assertEqual(0, program.main(
args=('pull-request', '-v', '--no-history'),
path=self.path,
))

self.assertEqual(
Tracker.instance().issue(1).comments[-1].content,
'Pull request: https://github.example.com/WebKit/WebKit/pull/1',
)

self.assertEqual(
captured.stdout.getvalue(),
"Created 'PR 1 | [Testing] Existing commit'!\n"
'Posted pull request link to https://bugs.example.com/show_bug.cgi?id=1\n'
'https://github.example.com/WebKit/WebKit/pull/1\n',
)
self.assertEqual(captured.stderr.getvalue(), '')
log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
' Found 1 commit...',
"Using committed changes...",
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
"Pushing 'eng/pr-branch' to 'fork'...",
"Creating pull-request for 'eng/pr-branch'...",
'Checking issue assignee...',
'Checking for pull request link in associated issue...',
],
)

def test_bitbucket(self):
with OutputCapture(level=logging.INFO) as captured, mocks.remote.BitBucket() as remote, mocks.local.Git(self.path, remote='ssh://git@{}/{}/{}.git'.format(
remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3],
@@ -612,6 +667,52 @@ def test_bitbucket_reopen(self):
],
)

def test_bitbucket_radar(self):
with OutputCapture(level=logging.INFO) as captured, mocks.remote.BitBucket() as remote, mocks.local.Git(
self.path, remote='ssh://git@{}/{}/{}.git'.format(remote.hosts[0], remote.project.split('/')[1], remote.project.split('/')[3]),
) as repo, mocks.local.Svn(), Environment(RADAR_USERNAME='tcontributor'), bmocks.Radar(issues=bmocks.ISSUES), patch('webkitbugspy.Tracker._trackers', [radar.Tracker()]):

repo.commits['eng/pr-branch'] = [Commit(
hash='06de5d56554e693db72313f4ca1fb969c30b8ccb',
branch='eng/pr-branch',
author=dict(name='Tim Contributor', emails=['tcontributor@example.com']),
identifier="5.1@eng/pr-branch",
timestamp=int(time.time()),
message='<rdar://problem/1> [Testing] Existing commit\n'
)]
repo.head = repo.commits['eng/pr-branch'][-1]
self.assertEqual(0, program.main(
args=('pull-request', '-v', '--no-history'),
path=self.path,
))

self.assertEqual(
Tracker.instance().issue(1).comments[-1].content,
'Pull request: https://bitbucket.example.com/projects/WEBKIT/repos/webkit/pull-requests/1/overview',
)

self.assertEqual(
captured.stdout.getvalue(),
"Created 'PR 1 | <rdar://problem/1> [Testing] Existing commit'!\n"
'Posted pull request link to <rdar://1>\n'
'https://bitbucket.example.com/projects/WEBKIT/repos/webkit/pull-requests/1/overview\n',
)
self.assertEqual(captured.stderr.getvalue(), '')
log = captured.root.log.getvalue().splitlines()
self.assertEqual(
[line for line in log if 'Mock process' not in line], [
' Found 1 commit...',
"Using committed changes...",
"Rebasing 'eng/pr-branch' on 'main'...",
"Rebased 'eng/pr-branch' on 'main!'",
" Found 1 commit...",
"Pushing 'eng/pr-branch' to 'origin'...",
"Creating pull-request for 'eng/pr-branch'...",
'Checking issue assignee...',
'Checking for pull request link in associated issue...',
],
)


class TestNetworkPullRequestGitHub(unittest.TestCase):
remote = 'https://github.example.com/WebKit/WebKit'

0 comments on commit 69b1ce5

Please sign in to comment.