From 62ab452d86011ac2c5067818f4852f31f7e5b95d Mon Sep 17 00:00:00 2001 From: Robin Neatherway Date: Tue, 1 Nov 2022 11:08:06 +0000 Subject: [PATCH] Include link to the Slack message in 'details' mode --- cmd/gh-slack/main.go | 23 ++++++++++++++++++----- internal/gh/gh.go | 9 ++++----- internal/markdown/markdown.go | 5 +++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cmd/gh-slack/main.go b/cmd/gh-slack/main.go index 37b6572..5487cda 100644 --- a/cmd/gh-slack/main.go +++ b/cmd/gh-slack/main.go @@ -103,22 +103,35 @@ func realMain() error { return err } + var channelName string if opts.Details { - output = markdown.WrapInDetails(output) + channelInfo, err := client.ChannelInfo(channelID) + if err != nil { + return err + } + + channelName = channelInfo.Name + output = markdown.WrapInDetails(channelName, opts.Args.Start, output) } if repoUrl != "" { - channelInfo, err := client.ChannelInfo(channelID) + if channelName == "" { + channelInfo, err := client.ChannelInfo(channelID) + if err != nil { + return err + } + channelName = channelInfo.Name + } + + err := gh.NewIssue(repoUrl, channelName, output) if err != nil { return err } - gh.NewIssue(repoUrl, channelInfo, output) } else if issueUrl != "" { - channelInfo, err := client.ChannelInfo(channelID) + err := gh.AddComment(issueUrl, output) if err != nil { return err } - gh.AddComment(issueUrl, channelInfo, output) } else { os.Stdout.WriteString(output) } diff --git a/internal/gh/gh.go b/internal/gh/gh.go index bc2fa77..9f45ea8 100644 --- a/internal/gh/gh.go +++ b/internal/gh/gh.go @@ -5,30 +5,29 @@ import ( "os" "github.com/cli/go-gh" - "github.com/rneatherway/gh-slack/internal/slackclient" ) -func NewIssue(repoUrl string, channel *slackclient.Channel, content string) error { +func NewIssue(repoUrl string, channelName, content string) error { out, _, err := gh.Exec( "issue", "-R", repoUrl, "create", "--title", - fmt.Sprintf("Slack conversation archive of `#%s`", channel.Name), + fmt.Sprintf("Slack conversation archive of `#%s`", channelName), "--body", content) os.Stdout.Write(out.Bytes()) return err } -func AddComment(issueUrl string, channel *slackclient.Channel, content string) error { +func AddComment(issueUrl string, content string) error { out, _, err := gh.Exec( "issue", "comment", issueUrl, "--body", - fmt.Sprintf("Slack conversation archive of `#%s`\n%s", channel.Name, content)) + content) os.Stdout.Write(out.Bytes()) return err } diff --git a/internal/markdown/markdown.go b/internal/markdown/markdown.go index 5447057..f8d7b16 100644 --- a/internal/markdown/markdown.go +++ b/internal/markdown/markdown.go @@ -142,6 +142,7 @@ func FromMessages(client *slackclient.SlackClient, history *slackclient.HistoryR return b.String(), nil } -func WrapInDetails(s string) string { - return fmt.Sprintf("
\n Click to expand\n\n%s\n
", s) +func WrapInDetails(channelName, link, s string) string { + return fmt.Sprintf("Slack conversation archive of [`#%s`](%s)\n\n
\n Click to expand\n\n%s\n
", + channelName, link, s) }