diff --git a/contrib/buildbot/server.py b/contrib/buildbot/server.py --- a/contrib/buildbot/server.py +++ b/contrib/buildbot/server.py @@ -182,7 +182,7 @@ # Only link PRs that do not reside in code blocks if multilineCodeBlockDelimiters % 2 == 0: - def replacePRWithLink(baseUrl): + def replacePRWithLink(baseUrl, prefix): def repl(match): nonlocal foundPRs # This check matches identation-based code blocks (2+ spaces) @@ -197,25 +197,22 @@ foundPRs += 1 PRNum = match.group(1) - remaining = '' - if len(match.groups()) >= 2: - remaining = match.group(2) - - return '[[{}/{} | PR{}]]{}'.format( - baseUrl, PRNum, PRNum, remaining) + return '[[{}/{} | {}#{}]]'.format( + baseUrl, PRNum, prefix, PRNum) return repl - line = re.sub( - r'PR[ #]*(\d{3}\d+)', - replacePRWithLink( - 'https://github.com/bitcoin/bitcoin/pull'), - line) - - # Be less aggressive about serving libsecp256k1 links. Check - # for some reference to the name first. - if re.search('secp', line, re.IGNORECASE): - line = re.sub(r'PR[ #]*(\d{2}\d?)([^\d]|$)', replacePRWithLink( - 'https://github.com/bitcoin-core/secp256k1/pull'), line) + githubUrl = 'https://github.com/{}/pull' + supportedRepos = dict() + supportedRepos = { + 'core': githubUrl.format('bitcoin/bitcoin'), + 'core-gui': githubUrl.format('bitcoin-core/gui'), + 'secp256k1': githubUrl.format('bitcoin-core/secp256k1') + } + + for prefix, url in supportedRepos.items(): + regEx = r'{}#(\d*)'.format(prefix) + line = re.sub(regEx, replacePRWithLink( + url, prefix), line) newSummary += line diff --git a/contrib/buildbot/test/test_endpoint_backportcheck.py b/contrib/buildbot/test/test_endpoint_backportcheck.py --- a/contrib/buildbot/test/test_endpoint_backportcheck.py +++ b/contrib/buildbot/test/test_endpoint_backportcheck.py @@ -42,17 +42,10 @@ "Some text ```Ignore this PR3456``` Some more text.\n" "```\nPR4567 in a multi-line code block\nPR5678 in the same code block\n```\n" " Ignore this indented PR4567" - # Note that short numbered PRs are much more common when referencing non-bitcoin PRs, - # so we'll ignore them for now. - "Ignore short numbered PRs: PR123" - # But we do support secp256k1 PRs with 2-3 digits, so make - # sure they're also ignored properly "This is a test summary `Ignore this secp256k1 backport PR234` some text.\n" "Some text ```Ignore this secp256k1 PR345``` Some more text.\n" "```\nsecp256k1 PR456 in a multi-line code block\nsecp256k1 PR567 in the same code block\n```\n" - " Ignore this indented secp256k1 PR456" - "Ignore long numbered PRs for secp256k1: PR1234" - "Ignore short numbered PRs for secp256k1: PR1", + " Ignore this indented secp256k1 PR456", }, }]) @@ -68,7 +61,7 @@ 'id': '1234', 'fields': { 'summary': "This is a test summary\n" - # Bitcoin Core links + # Bitcoin Core references that are NOT hyperlinked "Backport of Core PR2345 and PR34567\n" "Backports with optional separators PR 2345 and PR#34567 and PR #4567\n" "PR6789 outside of a code block `PR4567 inside a code block`\n" @@ -76,14 +69,29 @@ "```\nPR4567 in a multi-line code block\n```\n" " PR4567 in a code block using indentation\n" "Another backport PR567890\n" - # secp256k1 links + # secp256k1 references that are NOT hyperlinked "Backport of Secp256k1 PR23 and PR345\n" "Backport of Secp256k1 PR 23 and PR#345 and PR #45\n" "SECP256K1 PR678 outside of a code block `secp256k1 PR456 inside a code block`\n" "```secp256k1 PR456 in a single-line code block```\n" "```\nsecp256k1 PR456 in a multi-line code block\n```\n" " secp256k1 PR456 in a code block using indentation\n" - "Another secp backport PR567", + "Another secp backport PR567\n" + # only canonical markdown is hyperlinked now + "random yourname#12345 repo that is not supported is not hyperlinked\n" + "a backport of secp256k1#894\n" + "this is a backport of core#16723 and of core-gui#2\n" + "this is a very unlikely backport of core#16723, core-gui#2 and secp256k1#253431\n" + "malformed backport of core#16400#16458 should only link to the first #\n" + + "```this is a very unlikely backport of core#16723, core-gui#2" + " and secp256k1#253431 in a single-code block```\n" + + "```\nthis is a very unlikely backport of core#16723, core-gui#2 " + "and secp256k1#253431 in a multi-line code block\n```\n" + + " this is a very unlikely backport of core#16723, core-gui#2 and " + "secp256k1#253431 in a code block using indentation\n", }, }]) @@ -96,27 +104,44 @@ "type": "summary", "value": "This is a test summary\n" # Bitcoin Core links - "Backport of Core [[https://github.com/bitcoin/bitcoin/pull/2345 | PR2345]] and " - "[[https://github.com/bitcoin/bitcoin/pull/34567 | PR34567]]\n" - "Backports with optional separators [[https://github.com/bitcoin/bitcoin/pull/2345 | PR2345]] and " - "[[https://github.com/bitcoin/bitcoin/pull/34567 | PR34567]] and " - "[[https://github.com/bitcoin/bitcoin/pull/4567 | PR4567]]\n" - "[[https://github.com/bitcoin/bitcoin/pull/6789 | PR6789]] outside of a code block `PR4567 inside a code block`\n" + "Backport of Core PR2345 and PR34567\n" + "Backports with optional separators PR 2345 and PR#34567 and PR #4567\n" + "PR6789 outside of a code block `PR4567 inside a code block`\n" "```PR4567 in a single-line code block```\n" "```\nPR4567 in a multi-line code block\n```\n" " PR4567 in a code block using indentation\n" - "Another backport [[https://github.com/bitcoin/bitcoin/pull/567890 | PR567890]]\n" + "Another backport PR567890\n" # secp256k1 links - "Backport of Secp256k1 [[https://github.com/bitcoin-core/secp256k1/pull/23 | PR23]] and " - "[[https://github.com/bitcoin-core/secp256k1/pull/345 | PR345]]\n" - "Backport of Secp256k1 [[https://github.com/bitcoin-core/secp256k1/pull/23 | PR23]] and " - "[[https://github.com/bitcoin-core/secp256k1/pull/345 | PR345]] and " - "[[https://github.com/bitcoin-core/secp256k1/pull/45 | PR45]]\n" - "SECP256K1 [[https://github.com/bitcoin-core/secp256k1/pull/678 | PR678]] outside of a code block `secp256k1 PR456 inside a code block`\n" + "Backport of Secp256k1 PR23 and PR345\n" + "Backport of Secp256k1 PR 23 and PR#345 and PR #45\n" + "SECP256K1 PR678 outside of a code block `secp256k1 PR456 inside a code block`\n" "```secp256k1 PR456 in a single-line code block```\n" "```\nsecp256k1 PR456 in a multi-line code block\n```\n" " secp256k1 PR456 in a code block using indentation\n" - "Another secp backport [[https://github.com/bitcoin-core/secp256k1/pull/567 | PR567]]", + "Another secp backport PR567\n" + # only canonical markdown is hyperlinked now + "random yourname#12345 repo that is not supported is not hyperlinked\n" + "a backport of [[https://github.com/bitcoin-core/secp256k1/pull/894 " + "| secp256k1#894]]\n" + + "this is a backport of [[https://github.com/bitcoin/bitcoin/pull/16723 | " + "core#16723]] and of [[https://github.com/bitcoin-core/gui/pull/2 | core-gui#2]]\n" + + "this is a very unlikely backport of [[https://github.com/bitcoin/bitcoin/pull/16723 " + "| core#16723]], [[https://github.com/bitcoin-core/gui/pull/2 | core-gui#2]] " + "and [[https://github.com/bitcoin-core/secp256k1/pull/253431 | secp256k1#253431]]\n" + + "malformed backport of [[https://github.com/bitcoin/bitcoin/pull/16400 | " + "core#16400]]#16458 should only link to the first #\n" + + "```this is a very unlikely backport of core#16723, core-gui#2" + " and secp256k1#253431 in a single-code block```\n" + + "```\nthis is a very unlikely backport of core#16723, core-gui#2 " + "and secp256k1#253431 in a multi-line code block\n```\n" + + " this is a very unlikely backport of core#16723, core-gui#2 and " + "secp256k1#253431 in a code block using indentation\n", }], objectIdentifier='1234')] self.phab.differential.revision.edit.assert_has_calls( calls, any_order=True) diff --git a/doc/backporting.md b/doc/backporting.md --- a/doc/backporting.md +++ b/doc/backporting.md @@ -73,7 +73,7 @@ 5. Run `git show` side-by-side with `git show ` and verify that the changes are reasonable. If there are additional changes caused by the merge conflict 6. Run the build, and the rpc test suite and verify completion. -7. `arc diff` and at the bottom of the summary note: "Backport of Bitcoin Core PR# ". +7. `arc diff` and at the bottom of the summary note: `Backport of core#XXXXX`[1](#fn1). the PR# can be obtained by searching on github for the commit you are backporting. If you are backporting a commit which depends on another commit from the same PR, note that you are backporting `Part 1 of X`. Additionally, if it is the second or @@ -87,5 +87,9 @@ 2. Perform steps 2 through 6 from "Backporting each diff individually" in repetition for each diff in a Bitcoin Core pull request. 3. `git rebase -i origin/master` and squash the commits together. -4. `arc diff` and at the bottom of the summary note: "Backport of Bitcoin Core PR# ". +4. `arc diff` and at the bottom of the summary note: `Backport of core#XXXXX`[1](#fn1). The title of the diff should be: `[Backport] ` + +[1]: besides `core`, the prefixes `core-gui` and `secp256k1` will also include a + hyperlink to the appropriate pull request in the summary automatically, as long as they are in the + format `[prefix]#[pr_number]`. No spaces, all lowercase.