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 = '' | remaining = '' | ||||
if len(match.groups()) >= 2: | if len(match.groups()) >= 2: | ||||
remaining = match.group(2) | remaining = match.group(2) | ||||
return '[[{}/{} | PR{}]]{}'.format( | return '[[{}/{} | {}#{}]]{}'.format( | ||||
baseUrl, PRNum, PRNum, remaining) | baseUrl, PRNum, prefix, PRNum, remaining) | ||||
return repl | return repl | ||||
line = re.sub( | githubUrl = 'https://github.com/{}/pull' | ||||
r'PR[ #]*(\d{3}\d+)', | supportedRepos = { | ||||
replacePRWithLink( | 'Core': githubUrl.format('bitcoin/bitcoin'), | ||||
'https://github.com/bitcoin/bitcoin/pull'), | 'core-gui': githubUrl.format('bitcoin-core/gui'), | ||||
line) | 'secp256k1': githubUrl.format('bitcoin-core/secp256k1') | ||||
} | |||||
# Be less aggressive about serving libsecp256k1 links. Check | |||||
# for some reference to the name first. | for prefix, url in supportedRepos.values: | ||||
if re.search('secp', line, re.IGNORECASE): | regEx = r'{}#\d+'.format(prefix) | ||||
line = re.sub(r'PR[ #]*(\d{2}\d?)([^\d]|$)', replacePRWithLink( | line = re.sub(regEx, replacePRWithLink( | ||||
'https://github.com/bitcoin-core/secp256k1/pull'), line) | 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 |