Skip to content
This repository has been 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

Open
therealplato opened this issue Apr 9, 2019 · 2 comments

Comments

@therealplato
Copy link
Contributor

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?

@freeformz
Copy link

It could reply to the original message with the permalink (i.e. create a thread). I don't think I'd like to get a DM anyway as it takes me out of the context of the convo.

@theckman
Copy link
Collaborator

We could also make it respond via an ephemeral message.

@therealplato Would you mind re-raising this against https://github.com/gobridge/gopherbot for consideration? I'm going to be archiving this repo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants