Skip to content
This repository was archived by the owner on Jun 1, 2020. It is now read-only.
This repository was archived by the owner on Jun 1, 2020. It is now read-only.

enhancement: suggest github permalinks when gopher sees non-perma code links #56

@ghost

Description

I frequently find myself pasting example links from github to demonstrate something I've written or point out something in #reviews. Less frequently I find myself editing my slack posts to replace https://github.com/therealplato/shortlink/blob/master/config.go#L10 with https://github.com/therealplato/shortlink/blob/b4821cb7375cc6afaae61ebd6515c71a5fd32635/config.go#L10.

The latter link is preferable if future searchers are trying to understand the point of discussion, as the former link will probably point to different code soon. Gopher could help me catch any links I forget to permalink myself.

Something like:

var GithubCode = regexp.MustCompile(`https://github.com/[^/]/[^/]/blob/master/[^ ]*#L[L0-9\-]+`)
var HasPermalink = regexp.MustCompile(`blob/[0-9a-f]{32}`)
...
if GithubCode.MatchString(msg) {
  link := GithubCode.FindString(msg)  
  if !IsPermalink.MatchString(msg) {
    // permalink := acquirePermalink(msg)
    bot.ReplyDM(msg, "I saw you linked %s, which looks like it's pointing to specific code on a branch or tag. It's not unusual for those refs to eventually point to different code, so this link might not be useful to gophers who read this later. If you'd like the link to work in the future, press `y` on that page and edit the new link.", link)
}

Preemptively yes, regex are relatively difficult to read and debug, I find them great for rapid prototyping though :)

Do you think the more usable search history is worth the annoyance costs of getting DM's from gopher?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions