Anish Shah added the comment:
I have updated the patch according to reviews suggested by @maciej.szulik and
@berker.peksag
Description:-
This patch adds a new table "pull_request" which is used to save GitHub PR URLs.
URL can be added manually using "GitHub PR" field on issue's page.
---
GitHub PR URL will also be added automatically in two ways - for that, you can
have a look at issue589 and issue600
_______________________________________________________
PSF Meta Tracker <metatrac...@psf.upfronthosting.co.za>
<http://psf.upfronthosting.co.za/roundup/meta/issue586>
_______________________________________________________
diff --git a/detectors/pull_request.py b/detectors/pull_request.py
new file mode 100644
index 0000000..6a206e5
--- /dev/null
+++ b/detectors/pull_request.py
@@ -0,0 +1,35 @@
+# Auditor for GitHub URLs
+# Check if it is a valid GitHub Pull Request URL and extract PR number
+
+import re
+import urlparse
+
+
+def validate_github_url(db, cl, nodeid, newvalues):
+ url = newvalues.get('url', '')
+ if url == '':
+ return
+ parsed_url = urlparse.urlparse(url)
+ if parsed_url.scheme == '':
+ url = 'https://' + url
+ parsed_url = urlparse.urlparse(url)
+ if parsed_url.scheme not in ('http', 'https'):
+ raise ValueError("Invalid URL scheme in GitHub PR")
+ if 'github.com' not in parsed_url.netloc or 'pull' not in parsed_url.path:
+ raise ValueError("Invalid GitHub PR")
+ newvalues['url'] = parsed_url.geturl()
+ regex = re.match(".*/pull/(\d+)", newvalues['url'])
+ if regex and len(regex.groups()) == 1:
+ pr_no = regex.groups()[0]
+ try:
+ db.pull_request.lookup(pr_no)
+ raise ValueError("GitHub PR already added to an issue")
+ except KeyError:
+ newvalues['pr_no'] = pr_no
+ else:
+ raise ValueError("Invalid GitHub PR")
+
+
+def init(db):
+ db.pull_request.audit('create', validate_github_url)
+ db.pull_request.audit('set', validate_github_url)
diff --git a/html/issue.item.html b/html/issue.item.html
index ddc4ec3..17eecd1 100644
--- a/html/issue.item.html
+++ b/html/issue.item.html
@@ -220,6 +220,14 @@
</td>
</tr>
+<tr tal:condition="context/is_edit_ok">
+ <th><tal:block i18n:translate="">GitHub PR</tal:block>:</th>
+ <td colspan="3">
+ <input type="hidden" name="@link@pull_requests" value="pull_request-1">
+ <input type="text" name="pull_request-1@url" size="50">
+ </td>
+</tr>
+
</table>
</fieldset>
<table class="form">
@@ -273,6 +281,43 @@
</tr>
</table>
+<table class="files" tal:condition="context/pull_requests">
+ <tr><th class="header" colspan="5" i18n:translate="">GitHub Pull
Requests</th></tr>
+ <tr>
+ <th i18n:translate="">Link</th>
+ <th i18n:translate="">Author</th>
+ <th i18n:translate="">Date</th>
+ <th i18n:translate="">Edit</th>
+ <th i18n:translate="">Remove</th>
+ </tr>
+ <tr tal:repeat="pull_request python:context.pull_requests.sorted('creation')">
+ <td>
+ <a tal:attributes="href pull_request/url"
+ tal:content="pull_request/url" target="_blank">
+ GitHub PR link
+ </a>
+ </td>
+ <td>
+ <span tal:content="pull_request/creator">creator's name</span>
+ </td>
+ <td>
+ <span tal:content="python:pull_request.creation.pretty('%Y-%m-%d
%H:%M')">creation date</span>
+ </td>
+ <td>
+ <a tal:condition="pull_request/is_edit_ok"
+ tal:attributes="href string:pull_request${pull_request/id}">edit</a>
+ </td>
+ <td>
+ <form style="padding:0" method="post"
tal:condition="pull_request/is_edit_ok"
+ tal:attributes="action string:issue${context/id}">
+ <input type="hidden" name="@remove@pull_requests" tal:attributes="value
pull_request/id">
+ <input type="hidden" name="@action" value="edit">
+ <input type="submit" value="Remove">
+ </form>
+ </td>
+ </tr>
+</table>
+
<p tal:condition="python: context.id and not request.user.contrib_form and
any(file.creator.id == request.user.id for file in
context.files)"
id="contribform">
diff --git a/schema.py b/schema.py
index d91bf7b..c125a5f 100644
--- a/schema.py
+++ b/schema.py
@@ -173,6 +173,12 @@ hgrepo = Class(db, "hgrepo",
patchbranch=String(),
)
+pull_request = Class(db, "pull_request",
+ url=String(),
+ pr_no=String(),)
+
+pull_request.setkey("pr_no")
+
# IssueClass automatically gets these properties in addition to the Class ones:
# title = String()
# messages = Multilink("msg")
@@ -194,7 +200,8 @@ issue = IssueClass(db, "issue",
stage=Link('stage'),
nosy_count=Number(),
message_count=Number(),
- hgrepos=Multilink('hgrepo'))
+ hgrepos=Multilink('hgrepo'),
+ pull_requests=Multilink('pull_request'))
#
# TRACKER SECURITY SETTINGS
@@ -222,7 +229,7 @@ for r in 'User', 'Developer', 'Coordinator':
for cl in ('issue_type', 'severity', 'component',
'version', 'priority', 'stage', 'status', 'resolution',
- 'issue', 'keyword', 'hgrepo'):
+ 'issue', 'keyword', 'hgrepo', 'pull_request'):
db.security.addPermissionToRole('User', 'View', cl)
db.security.addPermissionToRole('Anonymous', 'View', cl)
@@ -233,6 +240,13 @@ p = db.security.addPermission(name='Edit', klass='hgrepo',
check=may_edit_hgrepo
properties=['url', 'patchbranch'])
db.security.addPermissionToRole('User', p)
+def may_edit_github_url(db, userid, itemid):
+ return userid == db.pull_request.get(itemid, "creator")
+db.security.addPermissionToRole('User', 'Create', 'pull_request')
+p = db.security.addPermission(name='Edit', klass='pull_request',
+ check=may_edit_github_url, properties=['url'])
+db.security.addPermissionToRole('User', p)
+
class may_view_spam:
def __init__(self, klassname):
self.klassname = klassname
@@ -292,7 +306,7 @@ p = db.security.addPermission(name='Create', klass='issue',
properties=('title', 'type',
'components', 'versions',
'severity',
- 'messages', 'files', 'nosy',
'hgrepos'),
+ 'messages', 'files', 'nosy',
'hgrepos', 'pull_requests'),
description='User can report and discuss issues')
db.security.addPermissionToRole('User', p)
@@ -300,7 +314,7 @@ p = db.security.addPermission(name='Edit', klass='issue',
properties=('title', 'type',
'components', 'versions',
'severity',
- 'messages', 'files', 'nosy',
'hgrepos'),
+ 'messages', 'files', 'nosy',
'hgrepos', 'pull_requests'),
description='User can report and discuss issues')
db.security.addPermissionToRole('User', p)
@@ -335,7 +349,7 @@ for cl in ('issue', 'file', 'msg', 'keyword'):
##########################
for cl in ('issue_type', 'severity', 'component',
'version', 'priority', 'stage', 'status', 'resolution', 'issue',
- 'file', 'msg', 'hgrepo'):
+ 'file', 'msg', 'hgrepo', 'pull_request'):
db.security.addPermissionToRole('Coordinator', 'View', cl)
db.security.addPermissionToRole('Coordinator', 'Edit', cl)
db.security.addPermissionToRole('Coordinator', 'Create', cl)
_______________________________________________
Tracker-discuss mailing list
Tracker-discuss@python.org
https://mail.python.org/mailman/listinfo/tracker-discuss
Code of Conduct: https://www.python.org/psf/codeofconduct/