Skip to content

Commit

Permalink
Glamour support for merge request descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap committed Jan 13, 2020
1 parent 75146a3 commit 039f39f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ func init() {
mrCmd.Flags().BoolP("list", "l", false, "List merge requests on a remote")
mrCmd.Flags().BoolP("browse", "b", false, "View merge request <id> in a browser")
mrCmd.Flags().StringP("close", "d", "", "Close merge request <id> on remote")
mrCmd.Flags().BoolP("no-glamour", "G", false, "Don't use glamour to print the issue description")
RootCmd.AddCommand(mrCmd)
}
16 changes: 14 additions & 2 deletions cmd/mr_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"strings"

"github.com/charmbracelet/glamour"
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
lab "github.com/zaquestion/lab/internal/gitlab"
Expand All @@ -27,11 +28,13 @@ var mrShowCmd = &cobra.Command{
log.Fatal(err)
}

printMR(mr, rn)
glamour_disabled, _ := cmd.Flags().GetBool("no-glamour")

printMR(mr, rn, !glamour_disabled)
},
}

func printMR(mr *gitlab.MergeRequest, project string) {
func printMR(mr *gitlab.MergeRequest, project string, glamour_enabled bool) {
assignee := "None"
milestone := "None"
labels := "None"
Expand All @@ -50,6 +53,14 @@ func printMR(mr *gitlab.MergeRequest, project string) {
labels = strings.Join(mr.Labels, ", ")
}

if glamour_enabled {
r, _ := glamour.NewTermRenderer(
glamour.WithStandardStyle("dark"),
)

mr.Description, _ = r.Render(mr.Description)
}

fmt.Printf(`
#%d %s
===================================
Expand All @@ -72,5 +83,6 @@ WebURL: %s
func init() {
mrShowCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrShowCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrShowCmd.Flags().BoolP("no-glamour", "G", false, "Don't use glamour to print the issue description")
mrCmd.AddCommand(mrShowCmd)
}

0 comments on commit 039f39f

Please sign in to comment.