Changeset View
Changeset View
Standalone View
Standalone View
contrib/buildbot/server.py
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | def backportCheck(): | ||||
foundPRs = 0 | foundPRs = 0 | ||||
multilineCodeBlockDelimiters = 0 | multilineCodeBlockDelimiters = 0 | ||||
newSummary = "" | newSummary = "" | ||||
for line in summary.splitlines(keepends=True): | for line in summary.splitlines(keepends=True): | ||||
multilineCodeBlockDelimiters += len(re.findall(r'```', line)) | multilineCodeBlockDelimiters += len(re.findall(r'```', line)) | ||||
# Only link PRs that do not reside in code blocks | # Only link PRs that do not reside in code blocks | ||||
if multilineCodeBlockDelimiters % 2 == 0: | if multilineCodeBlockDelimiters % 2 == 0: | ||||
def replacePRWithLink(baseUrl): | def replacePRWithLink(baseUrl, prefix): | ||||
def repl(match): | def repl(match): | ||||
nonlocal foundPRs | nonlocal foundPRs | ||||
# This check matches identation-based code blocks (2+ spaces) | # This check matches identation-based code blocks (2+ spaces) | ||||
# and common cases for single-line code blocks (using | # and common cases for single-line code blocks (using | ||||
# both single and triple backticks) | # both single and triple backticks) | ||||
if match.string.startswith(' ') or len( | if match.string.startswith(' ') or len( | ||||
re.findall(r'`', match.string[:match.start()])) % 2 > 0: | re.findall(r'`', match.string[:match.start()])) % 2 > 0: | ||||
# String remains unchanged | # String remains unchanged | ||||
return match.group(0) | return match.group(0) | ||||
else: | else: | ||||
# Backport PR is linked inline | # Backport PR is linked inline | ||||
foundPRs += 1 | foundPRs += 1 | ||||
PRNum = match.group(1) | PRNum = match.group(1) | ||||
remaining = '' | return '[[{}/{} | {}#{}]]'.format( | ||||
if len(match.groups()) >= 2: | baseUrl, PRNum, prefix, PRNum) | ||||
remaining = match.group(2) | |||||
return '[[{}/{} | PR{}]]{}'.format( | |||||
baseUrl, PRNum, PRNum, remaining) | |||||
return repl | return repl | ||||
line = re.sub( | githubUrl = 'https://github.com/{}/pull' | ||||
r'PR[ #]*(\d{3}\d+)', | supportedRepos = dict() | ||||
replacePRWithLink( | supportedRepos = { | ||||
'https://github.com/bitcoin/bitcoin/pull'), | 'core': githubUrl.format('bitcoin/bitcoin'), | ||||
line) | 'core-gui': githubUrl.format('bitcoin-core/gui'), | ||||
'secp256k1': githubUrl.format('bitcoin-core/secp256k1') | |||||
# Be less aggressive about serving libsecp256k1 links. Check | } | ||||
# for some reference to the name first. | |||||
if re.search('secp', line, re.IGNORECASE): | for prefix, url in supportedRepos.items(): | ||||
line = re.sub(r'PR[ #]*(\d{2}\d?)([^\d]|$)', replacePRWithLink( | regEx = r'{}#(\d*)'.format(prefix) | ||||
'https://github.com/bitcoin-core/secp256k1/pull'), line) | line = re.sub(regEx, replacePRWithLink( | ||||
url, prefix), line) | |||||
newSummary += line | newSummary += line | ||||
if foundPRs > 0: | if foundPRs > 0: | ||||
phab.updateRevisionSummary(revisionId, newSummary) | phab.updateRevisionSummary(revisionId, newSummary) | ||||
return SUCCESS, 200 | return SUCCESS, 200 | ||||
▲ Show 20 Lines • Show All 840 Lines • Show Last 20 Lines |