def sendReviewRebased(db, from_user, to_user, recipients, review, new_upstream, rebased_commits, onto_branch=None):
# First check if we can/should send emails to the user at all.
try:
checkEmailEnabled(db, to_user)
subject = generateSubjectLine(db, to_user, review, "updatedReview.reviewRebased")
except MailDisabled:
return []
if from_user == to_user and to_user.getPreference(db, "email.ignoreOwnChanges"):
return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': review.repository.getURL(db, to_user),
'from.fullname': from_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
if new_upstream:
data["new_upstream"] = new_upstream.oneline(db, decorate=True)
text = """\
%(from.fullname)s has rebased the review branch onto:
%(new_upstream)s""" % data
else:
text = "%(from.fullname)s has rewritten the history on the review branch." % data
body += """%s
""" % textutils.reflow(text, line_length)
body += """The new branch log is:
"""
for commit in rebased_commits:
body += commit.oneline(db) + "\n"
files = []
parent_message_id = getReviewMessageId(db, to_user, review, files)
message_id = generateMessageId(len(files) + 1)
files.append(sendMail(
db, review, message_id, from_user, to_user, recipients, subject, body,
parent_message_id=parent_message_id))
return files
开发者ID:Aessy,项目名称:critic,代码行数:60,代码来源:mail.py
示例2: sendFiltersApplied
def sendFiltersApplied(db, from_user, to_user, review, globalfilters, parentfilters, assigned):
# First check if the user has activated email sending at all.
if not to_user.getPreference(db, "email.activated"): return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': review.repository.getURL(db, to_user),
'from.fullname': from_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
if globalfilters:
what = "global filters"
else:
what = "global filters from upstream repositories"
text = ("%s has modified the assignments in the review by making %s apply, "
"which they previously did not. This had the effect that you are "
"now a %s the review."
% (from_user.fullname,
what,
"reviewer of changes in" if assigned else "watcher of"))
body += """%s
""" % textutils.reflow(text, line_length)
if assigned:
body += renderFiles(db, to_user, review, "The following changes are now assigned to you:", assigned)
files = []
parent_message_id = None
cursor = db.cursor()
cursor.execute("SELECT messageid FROM reviewmessageids WHERE uid=%s AND review=%s", [to_user.id, review.id])
row = cursor.fetchone()
if not row:
files.extend(sendReviewPlaceholder(db, to_user, review))
cursor.execute("SELECT messageid FROM reviewmessageids WHERE uid=%s AND review=%s", [to_user.id, review.id])
row = cursor.fetchone()
if row:
parent_message_id = "<%[email protected]%s>" % (row[0], configuration.base.HOSTNAME)
files.append(sendMail(db, review, generateMessageId(len(files) + 1), from_user, to_user, [to_user], generateSubjectLine(db, to_user, review, "updatedReview.parentFiltersApplied"), body, parent_message_id=parent_message_id))
return files
开发者ID:ryfow,项目名称:critic,代码行数:60,代码来源:mail.py
示例3: reflow
def reflow(text, indent):
try:
import textutils
return textutils.reflow(text, indent=indent)
except Exception:
# The 'textutils' module depends on 'configuration', so make our
# dependency on it conditional.
return text
开发者ID:Aessy,项目名称:critic,代码行数:8,代码来源:configtest.py
示例4: sendVerificationMail
def sendVerificationMail(db, user, email_id=None):
cursor = db.cursor()
if email_id is None:
cursor.execute("""SELECT email
FROM users
WHERE id=%s""",
(user.id,))
email_id, = cursor.fetchone()
cursor.execute("""SELECT email, verification_token
FROM useremails
WHERE id=%s""",
(email_id,))
email, verification_token = cursor.fetchone()
if verification_token is None:
verification_token = auth.getToken(encode=base64.b16encode)
with db.updating_cursor("useremails") as cursor:
cursor.execute("""UPDATE useremails
SET verification_token=%s
WHERE id=%s""",
(verification_token, email_id))
if configuration.base.ACCESS_SCHEME == "http":
protocol = "http"
else:
protocol = "https"
administrators = dbutils.getAdministratorContacts(db, indent=2)
if administrators:
administrators = ":\n\n%s" % administrators
else:
administrators = "."
recipients = [mailutils.User(user.name, email, user.fullname)]
subject = "[Critic] Please verify your email: %s" % email
body = textutils.reflow("""
This is a message from the Critic code review system at %(hostname)s. The user
'%(username)s' on this system has added this email address to his/her account.
If this is you, please confirm this by following this link:
%(url_prefix)s/verifyemail?email=%(email)s&token=%(verification_token)s
If this is not you, you can safely ignore this email. If you wish to report
abuse, please contact the Critic system's administrators%(administrators)s
""" % { "hostname": configuration.base.HOSTNAME,
"username": user.name,
"email": email,
"url_prefix": "%s://%s" % (protocol, configuration.base.HOSTNAME),
"verification_token": verification_token,
"administrators": administrators })
mailutils.sendMessage(recipients, subject, body)
def sendFiltersApplied(db, from_user, to_user, review, globalfilters, parentfilters, assigned):
# First check if we can/should send emails to the user at all.
try:
checkEmailEnabled(db, to_user)
subject = generateSubjectLine(db, to_user, review, "updatedReview.parentFiltersApplied")
except MailDisabled:
return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': review.repository.getURL(db, to_user),
'from.fullname': from_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
if globalfilters:
what = "global filters"
else:
what = "global filters from upstream repositories"
text = ("%s has modified the assignments in the review by making %s apply, "
"which they previously did not. This had the effect that you are "
"now a %s the review."
% (from_user.fullname,
what,
"reviewer of changes in" if assigned else "watcher of"))
body += """%s
""" % textutils.reflow(text, line_length)
if assigned:
body += renderFiles(db, to_user, review, "The following changes are now assigned to you:", assigned)
files = []
parent_message_id = getReviewMessageId(db, to_user, review, files)
message_id = generateMessageId(len(files) + 1)
files.append(sendMail(
db, review, message_id, from_user, to_user, [to_user], subject, body,
parent_message_id=parent_message_id))
return files
开发者ID:Aessy,项目名称:critic,代码行数:56,代码来源:mail.py
示例6: sendExtensionOutput
def sendExtensionOutput(db, user_id, batch_id, output):
to_user = dbutils.User.fromId(db, user_id)
cursor = db.cursor()
cursor.execute("SELECT review, uid FROM batches WHERE id=%s", (batch_id,))
review_id, batch_user_id = cursor.fetchone()
review = dbutils.Review.fromId(db, review_id)
batch_user = dbutils.User.fromId(db, batch_user_id)
# First check if we can/should send emails to the user at all.
try:
checkEmailEnabled(db, to_user)
subject = generateSubjectLine(db, to_user, review, "extensionOutput")
except MailDisabled:
return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'batch.user.fullname': batch_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
text = "A batch of changes submitted by %(batch.user.fullname)s has been processed by your installed extensions." % data
body += """%s
""" % textutils.reflow(text, line_length)
body += "The extensions generated the following output:\n%s" % output
files = []
parent_message_id = getReviewMessageId(db, to_user, review, files)
message_id = generateMessageId(len(files) + 1)
files.append(sendMail(
db, review, message_id, to_user, to_user, [to_user], subject, body,
parent_message_id=parent_message_id))
return files
开发者ID:Aessy,项目名称:critic,代码行数:53,代码来源:mail.py
示例7: sendReviewRebased
def sendReviewRebased(db, from_user, to_user, recipients, review, new_upstream, rebased_commits, onto_branch=None):
# First check if the user has activated email sending at all.
if not to_user.getPreference(db, "email.activated"): return []
if from_user == to_user and to_user.getPreference(db, "email.ignoreOwnChanges"): return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': "%s:%s" % (configuration.base.HOSTNAME, review.repository.path),
'from.fullname': from_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
if new_upstream or onto_branch:
if onto_branch is None:
data['target'] = "the commit '%s'" % new_upstream
else:
data['target'] = "the branch '%s'" % onto_branch
text = "%(from.fullname)s has rebased the review branch onto %(target)s." % data
else:
text = "%(from.fullname)s has rewritten the history on the review branch." % data
body += """%s
""" % textutils.reflow(text, line_length)
body += """The new branch log is:
"""
for commit in rebased_commits:
body += "%s %s\n" % (commit.sha1[:8], commit.niceSummary())
cursor = db.cursor()
cursor.execute("SELECT messageid FROM reviewmessageids WHERE uid=%s AND review=%s", [to_user.id, review.id])
row = cursor.fetchone()
if row: parent_message_id = "<%[email protected]%s>" % (row[0], configuration.base.HOSTNAME)
else: parent_message_id = None
return [sendMail(db, review, generateMessageId(), from_user, to_user, recipients, generateSubjectLine(db, to_user, review, "updatedReview.reviewRebased"), body, parent_message_id=parent_message_id)]
开发者ID:KurSh,项目名称:critic,代码行数:53,代码来源:mail.py
示例8: sendExtensionOutput
def sendExtensionOutput(db, user_id, batch_id, output):
user = dbutils.User.fromId(db, user_id)
# Explicitly *don't* check if the user has activated email sending. This
# allows a user to disable email sending and then install extensions whose
# output is still sent.
#if not user.getPreference(db, "email.activated"): return []
line_length = user.getPreference(db, "email.lineLength")
hr = "-" * line_length
cursor = db.cursor()
cursor.execute("SELECT review, uid FROM batches WHERE id=%s", (batch_id,))
review_id, batch_user_id = cursor.fetchone()
review = dbutils.Review.fromId(db, review_id)
batch_user = dbutils.User.fromId(db, batch_user_id)
data = { 'review.id': review.id,
'review.url': review.getURL(db, user, 2),
'batch.user.fullname': batch_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
text = "A batch of changes submitted by %(batch.user.fullname)s has been processed by your installed extensions." % data
body += """%s
""" % textutils.reflow(text, line_length)
body += "The extensions generated the following output:\n%s" % output
cursor.execute("SELECT messageid FROM reviewmessageids WHERE uid=%s AND review=%s", [user.id, review.id])
row = cursor.fetchone()
if row: parent_message_id = "<%[email protected]%s>" % (row[0], configuration.base.HOSTNAME)
else: parent_message_id = None
return [sendMail(db, review, generateMessageId(), user, user, [user], generateSubjectLine(db, user, review, "extensionOutput"), body, parent_message_id=parent_message_id)]
开发者ID:KurSh,项目名称:critic,代码行数:48,代码来源:mail.py
示例9: createBranch
def createBranch(user, repository, name, head):
processCommits(repository.name, head)
cursor = db.cursor()
def commit_id(sha1):
cursor.execute("SELECT id FROM commits WHERE sha1=%s", [sha1])
return cursor.fetchone()[0]
components = name.split("/")
for index in range(1, len(components)):
try: repository.revparse("refs/heads/%s" % "/".join(components[:index]))
except: continue
message = ("Cannot create branch with name '%s' since there is already a branch named '%s' in the repository." %
(name, "/".join(components[:index])))
raise IndexException, textutils.reflow(message, line_length=80 - len("remote: "))
if name.startswith("r/"):
try:
review_id = int(name[2:])
cursor.execute("SELECT branches.name FROM reviews JOIN branches ON (branches.id=reviews.branch) WHERE reviews.id=%s", (review_id,))
row = cursor.fetchone()
message = "Refusing to create review named as a number."
if row:
message += "\nDid you mean to push to the branch '%s', perhaps?" % row[0]
raise IndexException, message
except ValueError:
pass
if user.getPreference(db, "review.createViaPush"):
the_commit = gitutils.Commit.fromSHA1(db, repository, head, commit_id(head))
all_commits = [the_commit]
review = review_utils.createReview(db, user, repository, all_commits, name, the_commit.summary(), None, via_push=True)
print "Submitted review: %s/r/%d" % (dbutils.getURLPrefix(db), review.id)
if review.reviewers:
print " Reviewers:"
for reviewer in review.reviewers:
print " %s <%s>" % (reviewer.fullname, reviewer.email)
if review.watchers:
print " Watchers:"
for watcher in review.watchers:
print " %s <%s>" % (watcher.fullname, watcher.email)
if configuration.extensions.ENABLED:
if extensions.executeProcessCommits(db, user, review, all_commits, None, the_commit, stdout):
print
print "Thank you!"
return True
else:
raise IndexException, "Refusing to create review; user preference 'review.createViaPush' is not enabled."
sha1 = head
base = None
tail = None
cursor.execute("""SELECT 1
FROM reachable
JOIN branches ON (branches.id=reachable.branch)
JOIN repositories ON (repositories.id=branches.repository)
WHERE repositories.id=%s
LIMIT 1""",
(repository.id,))
if cursor.fetchone():
def reachable(sha1):
cursor.execute("""SELECT branches.id
FROM branches
JOIN reachable ON (reachable.branch=branches.id)
JOIN commits ON (commits.id=reachable.commit)
WHERE branches.repository=%s
AND branches.type='normal'
AND commits.sha1=%s
ORDER BY reachable.branch ASC
LIMIT 1""",
(repository.id, sha1))
return cursor.fetchone()
else:
def reachable(sha1):
return None
commit_map = {}
commit_list = []
row = reachable(sha1)
if row:
# Head of branch is reachable from an existing branch. Could be because
# this branch is actually empty (just created with no "own" commits) or
# it could have been merged into some other already existing branch. We
# can't tell, so we just record it as empty.
base = row[0]
#.........这里部分代码省略.........
开发者ID:KurSh,项目名称:critic,代码行数:101,代码来源:index.py
示例10: sendPing
def sendPing(db, from_user, to_user, recipients, review, note):
# First check if the user has activated email sending at all.
if not to_user.getPreference(db, "email.activated"): return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': "%s:%s" % (configuration.base.HOSTNAME, review.repository.path),
'from.fullname': from_user.fullname,
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
body += """%(from.fullname)s has pinged the review!
""" % data
if note:
body += """Additional information from %s:
%s
""" % (from_user.getFirstName(), textutils.reflow(note, line_length, indent=2))
cursor = db.cursor()
cursor.execute("""SELECT reviewfiles.file, SUM(reviewfiles.deleted), SUM(reviewfiles.inserted)
FROM reviewfiles
JOIN reviewuserfiles ON (reviewuserfiles.file=reviewfiles.id)
WHERE reviewfiles.review=%s
AND reviewfiles.state='pending'
AND reviewuserfiles.uid=%s
GROUP BY reviewfiles.file""",
(review.id, to_user.id))
pending_files_lines = cursor.fetchall()
cursor.execute("""SELECT DISTINCT changesets.child
FROM reviewfiles
JOIN reviewuserfiles ON (reviewuserfiles.file=reviewfiles.id)
JOIN changesets ON (changesets.id=reviewfiles.changeset)
WHERE reviewfiles.review=%s
AND reviewfiles.state='pending'
AND reviewuserfiles.uid=%s""",
(review.id, to_user.id))
pending_commits = cursor.fetchall()
body += renderFiles(db, to_user, review, "These pending changes are assigned to you:", pending_files_lines, pending_commits, showcommit_link=True)
cursor.execute("SELECT messageid FROM reviewmessageids WHERE uid=%s AND review=%s", [to_user.id, review.id])
row = cursor.fetchone()
if row: parent_message_id = "<%[email protected]%s>" % (row[0], configuration.base.HOSTNAME)
else: parent_message_id = None
return [sendMail(db, review, generateMessageId(), from_user, to_user, recipients, generateSubjectLine(db, to_user, review, "pingedReview"), body, parent_message_id=parent_message_id)]
开发者ID:KurSh,项目名称:critic,代码行数:65,代码来源:mail.py
示例11: sendReviewAddedCommits
def sendReviewAddedCommits(db, from_user, to_user, recipients, review, commits, changesets, tracked_branch=False):
# First check if we can send emails to the user at all.
if not checkEmailEnabled(db, to_user):
return []
if from_user == to_user and to_user.getPreference(db, "email.ignoreOwnChanges"):
return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
relevant_only = to_user not in review.owners and to_user != from_user and to_user.getPreference(db, "email.updatedReview.relevantChangesOnly")
cursor = db.cursor()
if relevant_only:
cursor.execute("SELECT type FROM reviewusers WHERE review=%s AND uid=%s", (review.id, to_user.id))
if cursor.fetchone()[0] == 'manual': relevant_only = False
all_commits = dict((commit.sha1, commit) for commit in commits)
changeset_for_commit = {}
for changeset in changesets:
# We don't include diffs for merge commits in mails.
if len(changeset.child.parents) == 1:
if changeset.child in all_commits:
changeset_for_commit[changeset.child] = changeset
else:
# An added changeset where the child isn't part of the added
# commits will be a changeset between a "replayed rebase" commit
# and the new head commit, generated when doing a non-fast-
# forward rebase. The relevant commit from such a changeset is
# the first (and only) parent.
changeset_for_commit[changeset.parent] = changeset
if relevant_only:
relevant_files = review.getRelevantFiles(db, to_user)
relevant_commits = set()
for changeset in changesets:
for file in changeset.files:
if file.id in relevant_files:
if changeset.child in all_commits:
relevant_commits.add(changeset.child)
else:
# "Replayed rebase" commit; see comment above.
relevant_commits.add(all_commits[changeset.parent])
break
else:
cursor.execute("SELECT id FROM commentchains WHERE review=%s AND state='addressed' AND addressed_by=%s", (review.id, changeset.child.getId(db)))
for chain_id in cursor.fetchall():
cursor.execute("SELECT 1 FROM commentchainusers WHERE chain=%s AND uid=%s", (chain_id, to_user.id))
if cursor.fetchone():
relevant_commits.add(changeset.child)
break
if not relevant_commits:
return []
else:
relevant_commits = None
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': review.repository.getURL(db, to_user),
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
commitset = log_commitset.CommitSet(commits)
if tracked_branch:
body += "The automatic tracking of\n %s\n" % tracked_branch
body += textutils.reflow("has updated the review by pushing %sadditional commit%s to the branch" % ("an " if len(commits) == 1 else "", "s" if len(commits) > 1 else ""), line_length)
else:
body += textutils.reflow("%s has updated the review by pushing %sadditional commit%s to the branch" % (from_user.fullname, "an " if len(commits) == 1 else "", "s" if len(commits) > 1 else ""), line_length)
body += "\n %s\n" % review.branch.name
body += textutils.reflow("in the repository", line_length)
body += "\n %s\n\n\n" % review.repository.getURL(db, to_user)
cursor.execute("""SELECT file, SUM(deleted), SUM(inserted)
FROM fullreviewuserfiles
WHERE review=%%s
AND changeset IN (%s)
AND state='pending'
AND assignee=%%s
GROUP BY file""" % ",".join(["%s"] * len(changesets)),
[review.id] + [changeset.id for changeset in changesets] + [to_user.id])
pending_files_lines = cursor.fetchall()
if pending_files_lines:
heads = commitset.getHeads()
tails = commitset.getFilteredTails(review.repository)
#.........这里部分代码省略.........
开发者ID:andreastt,项目名称:critic,代码行数:101,代码来源:mail.py
示例12: sendReviewBatch
#.........这里部分代码省略.........
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': "%s:%s" % (configuration.base.HOSTNAME, review.repository.path),
'hr': "-" * line_length }
header = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
if batch_chain_id is not None:
batch_chain = review_comment.CommentChain.fromId(db, batch_chain_id, from_user, review=review)
else:
batch_chain = None
data["batch.author.fullname"] = from_user.fullname
first_name = from_user.getFirstName()
if batch_chain is not None:
batch_chain.loadComments(db, from_user)
comment_ids.add(batch_chain.comments[0].id)
remark = """%s'%s comment:
%s
""" % (first_name, first_name[-1] != 's' and 's' or '', textutils.reflow(batch_chain.comments[0].comment, line_length, indent=2))
else:
remark = ""
body = header
body += textutils.reflow("%(batch.author.fullname)s has submitted a batch of changes to the review." % data, line_length)
body += "\n\n\n"
body += remark
if not was_accepted and is_accepted:
state_change = textutils.reflow("The review is now ACCEPTED!", line_length) + "\n\n\n"
elif was_accepted and not is_accepted:
state_change = textutils.reflow("The review is NO LONGER ACCEPTED!", line_length) + "\n\n\n"
else:
state_change = ""
body += state_change
body += reviewed_files
body += unreviewed_files
subject = generateSubjectLine(db, to_user, review, "updatedReview.submittedChanges")
def renderCommentChains(chains):
result = ""
if chains:
for chain, new_state, new_type in chains:
for focus_comment in chain.comments:
if focus_comment.batch_id == batch_id:
break
else:
focus_comment = None
if focus_comment is not None or new_state is not None or new_type is not None:
result += renderChainInMail(db, to_user, chain, focus_comment, new_state, new_type, line_length, context_lines) + "\n\n"
开发者ID:KurSh,项目名称:critic,代码行数:67,代码来源:mail.py
示例13: sendReviewAddedCommits
def sendReviewAddedCommits(db, from_user, to_user, recipients, review, changesets, tracked_branch=False):
# First check if the user has activated email sending at all.
if not to_user.getPreference(db, "email.activated"): return []
if from_user == to_user and to_user.getPreference(db, "email.ignoreOwnChanges"): return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
relevant_only = to_user not in review.owners and to_user != from_user and to_user.getPreference(db, "email.updatedReview.relevantChangesOnly")
cursor = db.cursor()
if relevant_only:
cursor.execute("SELECT type FROM reviewusers WHERE review=%s AND uid=%s", (review.id, to_user.id))
if cursor.fetchone()[0] == 'manual': relevant_only = False
if relevant_only:
relevant_files = review.getRelevantFiles(db, to_user)
relevant_commits = set()
for changeset in changesets:
for file in changeset.files:
if file.id in relevant_files:
relevant_commits.add(changeset.child.getId(db))
break
else:
cursor.execute("SELECT id FROM commentchains WHERE review=%s AND state='addressed' AND addressed_by=%s", (review.id, changeset.child.getId(db)))
for chain_id in cursor.fetchall():
cursor.execute("SELECT 1 FROM commentchainusers WHERE chain=%s AND uid=%s", (chain_id, to_user.id))
if cursor.fetchone():
relevant_commits.add(changeset.child.getId(db))
break
if not relevant_commits:
return []
else:
relevant_commits = None
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.branch.name': review.branch.name,
'review.branch.repository': "%s:%s" % (configuration.base.HOSTNAME, review.repository.path),
'hr': hr }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
""" % data
commits = []
for index, changeset in enumerate(changesets):
if changeset.parent.sha1 == changeset.child.parents[0]:
commits.append(changeset.child)
commitset = log_commitset.CommitSet(commits)
if tracked_branch:
body += "The automatic tracking of\n %s\n" % tracked_branch
body += textutils.reflow("has updated the review by pushing %sadditional commit%s to the branch" % ("an " if len(commits) == 1 else "", "s" if len(commits) > 1 else ""), line_length)
else:
body += textutils.reflow("%s has updated the review by pushing %sadditional commit%s to the branch" % (from_user.fullname, "an " if len(commits) == 1 else "", "s" if len(commits) > 1 else ""), line_length)
body += "\n %s\n" % review.branch.name
body += textutils.reflow("in the repository", line_length)
body += "\n %s:%s\n\n\n" % (configuration.base.HOSTNAME, review.repository.path)
cursor.execute("""SELECT file, SUM(deleted), SUM(inserted)
FROM fullreviewuserfiles
WHERE review=%%s
AND changeset IN (%s)
AND state='pending'
AND assignee=%%s
GROUP BY file""" % ",".join(["%s"] * len(changesets)),
[review.id] + [changeset.id for changeset in changesets] + [to_user.id])
pending_files_lines = cursor.fetchall()
if pending_files_lines:
heads = commitset.getHeads()
tails = commitset.getFilteredTails(review.repository)
if len(heads) == 1 and len(tails) == 1:
showcommit_link = (tails.pop()[:8], heads.pop().sha1[:8])
else:
showcommit_link = False
body += renderFiles(db, to_user, review, "These changes were assigned to you:", pending_files_lines, showcommit_link=showcommit_link)
all_commits = to_user.getPreference(db, "email.updatedReview.displayCommits")
context_lines = to_user.getPreference(db, "email.comment.contextLines")
if all_commits:
body += "The additional commit%s requested to be reviewed are:\n\n" % ("s" if len(commits) > 1 else "")
contextLines = to_user.getPreference(db, "email.updatedReview.diff.contextLines")
diffMaxLines = to_user.getPreference(db, "email.updatedReview.diff.maxLines")
displayStats = to_user.getPreference(db, "email.updatedReview.displayStats")
#.........这里部分代码省略.........
开发者ID:KurSh,项目名称:critic,代码行数:101,代码来源:mail.py
示例14: sendReviewPlaceholder
def sendReviewPlaceholder(db, to_user, review):
# First check if the user has activated email sending at all.
if not to_user.getPreference(db, "email.activated"): return []
line_length = to_user.getPreference(db, "email.lineLength")
hr = "-" * line_length
why = "This message is sent to you when you become associated with a review after the review was initially requested. It is then sent instead of the regular \"New Review\" message, for the purpose of using as the reference/in-reply-to message for other messages sent about this review."
data = { 'review.id': review.id,
'review.url': review.getURL(db, to_user, 2),
'review.owner.fullname': review.owners[0].fullname,
'review.branch.name': review.branch.name,
'review.branch.repository': "%s:%s" % (configuration.base.HOSTNAME, review.repository.path),
'hr': hr,
'why': textutils.reflow(why, line_length) }
body = """%(hr)s
This is an automatic message generated by the review at:
%(review.url)s
%(hr)s
%(why)s
%(hr)s
""" % data
body += """%(review.owner.fullname)s has requested a review of the changes on the branch
%(review.branch.name)s
in the repository
%(review.branch.repository)s
""" % data
all_reviewers = to_user.getPreference(db, "email.newReview.displayReviewers")
all_watchers = to_user.getPreference(db, "email.newReview.displayWatchers")
if all_reviewers or all_watchers:
if all_reviewers:
if review.reviewers:
body += "The users assigned to review the changes on the review branch are:\n"
for reviewer in review.reviewers:
body += " " + reviewer.fullname + "\n"
body += "\n"
else:
body += """No reviewers have been identified for the changes in this review. This means
the review is currently stuck; it cannot finish unless there are reviewers.
"""
if all_watchers and review.watchers:
body += "The following additional users are following the review:\n"
for watcher in review.watchers:
body += " " + watcher.fullname + "\n"
body += "\n"
body += "\n"
if review.description:
body += """Description:
%s
""" % textutils.reflow(review.description, line_length, indent=2)
message_id = generateMessageId()
cursor = db.cursor()
cursor.execute("INSERT INTO reviewmessageids (uid, review, messageid) VALUES (%s, %s, %s)",
[to_user.id, review.id, message_id])
return [sendMail(db, review, message_id, review.owners[0], to_user, [to_user], generateSubjectLine(db, to_user, review, "newishReview"), body)]
开发者ID:KurSh,项目名称:critic,代码行数:82,代码来源:mail.py
示例15: process_request
#.........这里部分代码省略.........
query = ("repository=%d&from=%s&to=%s"
% (repository.id, items[0], items[1]))
if query:
if req.query:
query += "&" + req.query
req.query = query
req.path = "showcommit"
continue
except gitutils.GitReferenceError:
pass
break
req.setStatus(404)
raise page.utils.DisplayMessage(
title="Not found!",
body="Page not handled: /%s" % path)
except GeneratorExit:
raise
except page.utils.NotModified:
req.setStatus(304)
req.start()
return []
except request.MovedTemporarily as redirect:
req.setStatus(307)
req.addResponseHeader("Location", redirect.location)
if redirect.no_cache:
req.addResponseHeader("Cache-Control", "no-cache")
req.start()
return []
except request.DoExternalAuthentication as command:
command.execute(db, req)
return []
except request.MissingWSGIRemoteUser as error:
# req object is not initialized yet.
start_response("200 OK", [("Content-Type", "text/html")])
return ["""\
<pre>error: Critic was configured with '--auth-mode host' but there was no
REMOTE_USER variable in the WSGI environ dict provided by the web server.
To fix this you can either reinstall Critic using '--auth-mode critic' (to let
Critic handle user authentication automatically), or you can configure user
authentication properly in the web server. For apache2, the latter can be done
by adding the something like the following to the apache site configuration for
Critic:
<Location />
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/path/to/critic-main.htpasswd.users"
Require valid-user
</Location>
If you need more dynamic http authentication you can instead setup mod_wsgi with
a custom WSGIAuthUserScript directive. This will cause the provided credentials
to be passed to a Python function called check_password() that you can implement
yourself. This way you can validate the user/pass via any existing database or
for example an LDAP server. For more information on setting up such
authentication in apache2, see:
<a href="%(url)s">%(url)s</a></pre>""" % { "url": "http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider" }]
except page.utils.DisplayMessage as message:
if user is None:
user = dbutils.User.makeAnonymous()
document = page.utils.displayMessage(
db, req, user, title=message.title, message=message.body,
review=message.review, is_html=message.html)
req.setContentType("text/html")
req.start()
return [str(document)]
except Exception:
# crash might be psycopg2.ProgrammingError so rollback to avoid
# "InternalError: current transaction is aborted" inside handleException()
if db and db.closed():
db = None
elif db:
db.rollback()
error_title, error_body = handleException(db, req, user)
error_body = reflow("\n\n".join(error_body))
error_message = "\n".join([error_title,
"=" * len(error_title),
"",
error_body])
assert not req.isStarted()
req.setStatus(500)
req.setContentType("text/plain")
req.start()
return [error_message]
finally:
if db:
db.close()
请发表评论