Skip to content

Commit

Permalink
Merge pull request #20 from rneatherway/messagelink
Browse files Browse the repository at this point in the history
Include link to the Slack message in 'details' mode
  • Loading branch information
rneatherway authored Nov 4, 2022
2 parents 73d749a + 62ab452 commit af0e635
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
23 changes: 18 additions & 5 deletions cmd/gh-slack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 4 additions & 5 deletions internal/gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions internal/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func FromMessages(client *slackclient.SlackClient, history *slackclient.HistoryR
return b.String(), nil
}

func WrapInDetails(s string) string {
return fmt.Sprintf("<details>\n <summary>Click to expand</summary>\n\n%s\n</details>", s)
func WrapInDetails(channelName, link, s string) string {
return fmt.Sprintf("Slack conversation archive of [`#%s`](%s)\n\n<details>\n <summary>Click to expand</summary>\n\n%s\n</details>",
channelName, link, s)
}

0 comments on commit af0e635

Please sign in to comment.