Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Windows #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion change-merged
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@ parser.add_option("-b", "--branch", dest="branch_name",
parser.add_option("-t", "--topic", dest="topic",
help="Gerrit topic of Changeset")
parser.add_option("-s", "--submitter", dest="submitter",
help="Gerrit Patchset id")
help="Gerrit Submitter")
parser.add_option("--submitter-username", dest="submitter_username",
help="Gerrit Submitter User Name")
parser.add_option("-c", "--commit", dest="commit",
help="GIT Commit SHA ID")
parser.add_option("--change-owner", dest="change_owner",
help="Gerrit Change Owner")
parser.add_option("--change-owner-username", dest="change_owner_username",
help="Gerrit Change Owner User Name")
parser.add_option("--newrev", dest="new_rev",
help="Gerrit New Rev")

options, args = parser.parse_args()
try:
idx = sys.argv.index('--topic')
except ValueError:
pass
else:
if sys.argv[idx+1].startswith('--'):
sys.argv.insert(idx+1, '')
options, args = parser.parse_args()

# run trac update with hook-name and options
trac_update = TracGerritTicket(hook_name=sys.argv[0],
Expand Down
1 change: 1 addition & 0 deletions change-merged.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python D:\gerrit\site\hooks\change-merged %*
12 changes: 12 additions & 0 deletions comment-added
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ parser.add_option("-t", "--topic", dest="topic",
help="Gerrit topic of Changeset")
parser.add_option("-a", "--author", dest="author",
help="Gerrit Comment Author", default=None)
parser.add_option("--author-username", dest="author_username",
help="Gerrit Comment Author User Name", default=None)
parser.add_option("-c", "--commit", dest="commit",
help="GIT Commit SHA ID")
parser.add_option("-m", "--comment", dest="comment",
Expand All @@ -47,6 +49,8 @@ parser.add_option("--Code-Review", dest="review",
help="Gerrit Review", default=None)
parser.add_option("--change-owner", dest="change_owner",
help="Gerrit Change Owner", default=None)
parser.add_option("--change-owner-username", dest="change_owner_username",
help="Gerrit Change Owner User Name")
parser.add_option("--Verified", dest="verified",
help="Gerrit Verified", default=None)
parser.add_option("--Verified-oldValue", dest="verified_oldValue",
Expand All @@ -56,6 +60,14 @@ parser.add_option("--Code-Review-oldValue", dest="review_oldValue",


options, args = parser.parse_args()
try:
idx = sys.argv.index('--topic')
except ValueError:
pass
else:
if sys.argv[idx+1].startswith('--'):
sys.argv.insert(idx+1, '')
options, args = parser.parse_args()

# run trac update with hook-name and options
trac_update = TracGerritTicket(hook_name=sys.argv[0],
Expand Down
1 change: 1 addition & 0 deletions comment-added.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python D:\gerrit\site\hooks\comment-added %*
12 changes: 12 additions & 0 deletions patchset-created
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ parser.add_option("-b", "--branch", dest="branch_name",
help="Gerrit Branch Name")
parser.add_option("-l", "--uploader", dest="uploader",
help="Gerrit Uploader", default=None)
parser.add_option("--uploader-username", dest="uploader_username",
help="Gerrit Uploader User Name", default=None)
parser.add_option("-c", "--commit", dest="commit",
help="GIT Commit SHA ID")
parser.add_option("-u", "--change-url", dest="change_url",
Expand All @@ -47,8 +49,18 @@ parser.add_option("-k", "--kind", dest="kind",
help="Gerrit Change Kind")
parser.add_option("--change-owner", dest="change_owner",
help="Gerrit Change Owner")
parser.add_option("--change-owner-username", dest="change_owner_username",
help="Gerrit Change Owner User Name")

options, args = parser.parse_args()
try:
idx = sys.argv.index('--topic')
except ValueError:
pass
else:
if sys.argv[idx+1].startswith('--'):
sys.argv.insert(idx+1, '')
options, args = parser.parse_args()

# run trac update with hook-name and options
trac_update = TracGerritTicket(hook_name=sys.argv[0],
Expand Down
1 change: 1 addition & 0 deletions patchset-created.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python D:\gerrit\site\hooks\patchset-created %*
10 changes: 10 additions & 0 deletions ref-update
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ parser.add_option("-r", "--refname", dest="refname",
help="Git ref Name")
parser.add_option("-u", "--uploader", dest="uploader",
help="Gerrit Uploader")
parser.add_option("--uploader-username", dest="uploader_username",
help="Gerrit Uploader User Name", default=None)
parser.add_option("-o", "--oldrev", dest="oldrev",
help="GIT old rev")
parser.add_option("-n", "--newrev", dest="newrev",
help="GIT new rev")

options, args = parser.parse_args()
try:
idx = sys.argv.index('--topic')
except ValueError:
pass
else:
if sys.argv[idx+1].startswith('--'):
sys.argv.insert(idx+1, '')
options, args = parser.parse_args()

trac_update = TracGerritTicket(hook_name=sys.argv[0],
options=options)
Expand Down
2 changes: 2 additions & 0 deletions ref-update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exit 0
python D:\gerrit\site\hooks\ref-update %*
29 changes: 19 additions & 10 deletions trac_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
from subprocess import Popen, PIPE, call
from datetime import datetime

from trac.env import open_environment

## regex to find #TICKETNUMBER
TICKET_RE = re.compile('#([0-9]+)')
TICKET_RE = re.compile('(?:#|issue|bug|ticket|<)\s*([0-9]+)')

## remove substring from end of string
# thanks to http://stackoverflow.com/a/3663505/1922402
Expand Down Expand Up @@ -208,15 +210,16 @@ def __init__(self, hook_name, options, config_path=None, debug=False):

self.trac_env = self.config.get_env_for_repo(self.repo_name)
if not self.trac_env:
print("no trac environment setting, exit")
sys.exit(0)

if self.trac_env.startswith("http"):
if self.trac_env.startswith("http"):
self.trac_over_rpc = True
else:
self.trac_over_rpc = False
self.env = open_environment(self.trac_env)

self.hook_name = hook_name
self.hook_name = rchop(hook_name, ".py")
self.debug = debug

self.commit_msg = ""
Expand Down Expand Up @@ -333,12 +336,14 @@ def trac_merge_success(self):
msg = "!Repo/Branch: %s/%s\n" \
"[%s Gerrit Patchset merged]\n\n" \
"%s\n\n" \
"merged by %s" \
"merged by %s\n\n" \
"Commit-Id: %s" \
% (self.repo_name,
self.options.branch_name,
self.options.change_url,
self.commit_msg,
self.options.submitter)
self.options.submitter,
self.options.commit)
return msg

def trac_new_review(self):
Expand All @@ -356,7 +361,7 @@ def trac_new_review(self):
else:
comment = self.options.comment.split('\n')
change_url_line = "[%s Comment]\n\n" % self.options.change_url
comment_line = "Comment zu %s\n\n%s" % (comment[0],
comment_line = "Comment to %s\n\n%s" % (comment[0],
'\n>'.join(comment[1:]))
msg = "%s" \
"%s" \
Expand All @@ -371,13 +376,17 @@ def trac_new_patchset(self):
correct_change_url = "{0}/c/{1}".format(part_one, part_two)
msg = "!Repo/Branch: %s/%s\n" \
"[%s/%s Gerrit Patchset %s]\n\n" \
"%s" \
"Author: %s\n" \
"%s\n\n" \
"uploaded by %s\n\n" \
% (self.repo_name,
self.options.branch_name,
correct_change_url,
self.options.patchset,
self.options.patchset,
self.commit_msg)
self.options.change_owner,
self.commit_msg,
self.options.uploader)
return msg


Expand All @@ -387,7 +396,7 @@ def handle_trac(self):
self.options.is_draft == 'true'):
return

if self.trac_over_rpc:
if self.trac_over_rpc:
import xmlrpclib
else:
if not (os.path.exists(self.trac_env) and
Expand Down Expand Up @@ -473,7 +482,7 @@ def handle_trac(self):
sys.stderr.write('Unexpected error while handling Trac ' \
'ticket ID %s: %s (RPC)' \
% (ticket_id, e))

else:
try:
db = self.env.get_db_cnx()
Expand Down