GitHubの「パーマネントリンク」ボットが私の投稿の意味を静かに台無しにした

About a year ago, I made a post on GitHub’s Discourse instance that included a bunch of URLs of the form “https://github.com/OWNER/REPO/tree/BRANCH/path” in order to discuss how GitHub.com processes such URLs. My post promptly received a system-generated edit with the message “Github link was replaced by a permanent link”, which appears to be coming from the discourse-github plugin. While replacing the branch name with a permanent link to the current commit ID may be a useful feature in the common case of a post citing particular code, in the special case of discussing GitHub URL processing, the edit destroyed the meaning of my post. I was lucky enough to notice the bot edit right away, and after several rounds of fighting with the bot, I eventually found a workaround of adding a <span> tag to prevent the bot’s pattern from matching, like this:

https://github.com/OWNER/REPO/tree/<span>BRANCH</span>/PATH

But other authors might not notice the bot edit and might be left with a post that would confuse readers.

What is the best solution to avoid undesired GitHub permanent link edits to a particular post? In general, I feel like it’s wrong for bots to make automatic edits that risk ruining a post. It would be safer to (1) ask the author when a post is saved whether the links should be edited or (2) have the bot add a permanent link without removing the original link. (I seem to recall seeing some bots on other web sites, maybe Reddit, that add information without deleting the existing information.) If the Discourse maintainers consider those options too ugly or too much work to accommodate a rare use case, some other options might be to (3) show a notice after the post is saved with a link to information about how the author can avoid the edits if needed, either as (a) a dedicated banner in the UI or (b) just a line of text added by the bot to the end of the post.

I’m not sure what would be the most reasonable design for the author to opt out of the edits. The discourse-github plugin’s site-wide exclusion settings based on the link target don’t seem well-suited for this purpose. Perhaps my current workaround with the <span> tag is adequate. Even if no change is made to Discourse, I hope this post will make the workaround easier to discover for authors who do notice the problem.

Note: I previously raised this issue on GitHub’s forum because I assumed the “permanent link” bot was specific to GitHub’s instance, but a commenter there clued me in that it is a general Discourse feature, so I’m raising the issue here.

Thanks for your attention!

「いいね!」 2

I think this is a good feature, because people often paste links to master and these almost always grow outdated over time. Still, it should be possible to intentionally paste a link to a branch as there are many valid reasons to do this. Also generally this feature seems a bit broken, it rewrites things it shouldn’t and doesn’t parse things that it probably should.

Here are some examples that could be used as test cases to fix it:

  1. Plain link made by just pasting a URL. I would expect this to be rewritten, and it is: subdomain-static/forums-enhancements.js at master · ClassicPress/subdomain-static · GitHub
  2. Markdown link of the form [url](url). I would expect this link not to be rewritten, because I have explicitly specified both the text and the URL. Instead, the link text is rewritten, and the link URL is not. This is broken: https://github.com/ClassicPress/subdomain-static/blob/master/forums-enhancements.js
  3. URL enclosed in backquotes. This is not a link and should not be rewritten, but it is: https://github.com/ClassicPress/subdomain-static/blob/master/forums-enhancements.js
  4. URL in a triple-backquoted code block. This is not a link and should not be rewritten, but it is:
    https://github.com/ClassicPress/subdomain-static/blob/master/forums-enhancements.js
    

I think only (1) above should be rewritten. This would make the behavior more predictable, and only rewrite “plain” links. Links where a specific markdown structure has been used (can be thought of as a way to express a specific intention) should be left alone.

「いいね!」 1

This feature appears to not be enabled on meta.discourse.org?

参考までに、私は反対です。(2) 編集: [text](URL) の一般的なケース((2a)と呼びましょう)では、リンクURLは(1)と同じように書き直されるべきだと思います。(現在の、テキストは書き直し、URLは書き直さないという動作は完全に間違っていることには同意します。)(1)と(2a)のどちらを書き直すかの決定は、読者にリンクURLが表示されることが有用か、それとも紛らわしいかどうかに基づいており、リンクが執筆時点のコードのバージョンを指すべきか、それとも読み取り時点のコードのバージョンを指すべきかという意図に基づくものではありません。もちろん、パーマリンクの問題は認識しているので、必要な場合は自分でパーマリンクを作成します。しかし、より一般的には、Discourse管理者がパーマリンクボットを有効にすることに決めた場合、それはおそらく、ほとんどのユーザーがブランチ名ベースのリンクが壊れるリスクを認識していないと考えているからであり、Markdownリンク構文の使用が、その特定のリンクが書き直されることを望まないユーザーがその問題に気づいているというシグナルであるとはあまり思いません。

しかし、どちらも憶測に過ぎないと思います。上級ユーザーとしては、オーバーライドできる限り、デフォルトがどうであってもあまり気にしません。

はい、まさにその通りです。現在、それをオーバーライドする方法はありません。[url](url)(リンクテキストとURLがまったく同じ)と書くことは、ボットにそのリンクを書き換えるべきではないことを示す方法になります。なぜなら、そのように書く他の理由がないからです。

リンクのターゲットURLから推測されるタイトルではなく、独自のタイトルを付けたい場合は、そのようになります。つまり、[タイトル](URL)です。リンクにタイトルを付けることは、URLの書き換えに対する好意を示すものではないため、URLの書き換えに関しては、@mattmccutchenと同様に、1と2は一貫して動作すべきだと思います。

タイトルがURLと完全に一致することが、書き換えられないことを示すという議論があるかもしれませんが、ユーザーがタイトルを提供したいが、URLを書き換えたくない場合はどうでしょうか?それを指定する別の方法が必要です。

思いつくのは、埋め込み画像サイズのようなタイトルの接尾辞ですが、ユーザーがそれを見つける方法がわかりません。

埋め込み画像は次のようにサイズ設定できます。
![タイトル|100x200](URL)

したがって、discourse-githubプラグインは、次のようなものを探すように(おそらく)作ることができます。
[タイトル|github-no-rewrite](URL)

ああ、あなたの(2)が、テキストとURLが同じである特別な場合にのみ言及していることは、私には明確ではありませんでした。私の発言は、テキストとURLが同じではない場合がある一般的なケース(今これを(2a)と呼びましょう)に関するものでした。

ケース(2)では、URLは書き換えるがテキストは書き換えないのは奇妙で、不整合が残ることは同意しますが、不整合を避けたいのであれば、両方とも書き換えるのが最善の方法であると主張することも同様に可能であると思います。したがって、(2)をオプトアウトとして扱うという議論は説得力があるとは思いません。(2a)で機能するオプトアウトが必要であることを考えると、ユーザーに(2)と同じオプトアウトを使わせ、設計を複雑にしないようにしたいです。(これはSimon Manningのアイデアでもあったと思いますか?)

これを正しく理解しているか(または可能かどうか)わかりませんが、Inline PDF Previews - #45 by Johani のようなスペースエスケープを使用できますか? [ text]( url) はテキストも URL も書き換えず、それ以外は自動的に変更されるということですか?

このバージョンはそのままにして、書き直さないでください。確認させてください。

https://github.com/correctcomputation/checkedc-clang/blob/master-post-microsoft/clang/docs/checkedc/Setup-and-Build.md

次のように書かれています。

<https://github.com/correctcomputation/checkedc-clang/blob/master-post-microsoft/clang/docs/checkedc/Setup-and-Build.md>

このディスコースインスタンスではGitHubのパーマリンク書き換えが無効になっているため、有効なテストではありません。(「公式」インスタンスで無効になっている場合、この機能について何を物語っているのかと思います :upside_down_face:

代わりに、この例をreplace_github_non_permalinks.rb / replace_github_non_permalinks_spec.rbのテストケースとして記述した場合、そのリンクも書き換えられることがわかると思います。

「いいね!」 1