From 2ab9cf556f1d793568b40e214b8ba0a51dfc6290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E6=A9=99?= Date: Mon, 20 Jan 2025 09:16:31 -0800 Subject: [PATCH] Add git push option for description (#412) --- docs/usage/git-push-options.md | 6 ++++++ internal/hooks/post_receive.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/docs/usage/git-push-options.md b/docs/usage/git-push-options.md index 218d6d70..738617b5 100644 --- a/docs/usage/git-push-options.md +++ b/docs/usage/git-push-options.md @@ -17,6 +17,12 @@ git push -o title=Gist123 git push -o title="My Gist 123" ``` +## Change description + +```shell +git push -o description="This is my gist description" +``` + ## Change visibility ```shell diff --git a/internal/hooks/post_receive.go b/internal/hooks/post_receive.go index 8ab04332..628948c1 100644 --- a/internal/hooks/post_receive.go +++ b/internal/hooks/post_receive.go @@ -65,6 +65,11 @@ func PostReceive(in io.Reader, out, er io.Writer) error { outputSb.WriteString(fmt.Sprintf("Gist title set to \"%s\"\n\n", opts["title"])) } + if opts["description"] != "" && validator.Var(opts["description"], "max=1000") == nil { + gist.Description = opts["description"] + outputSb.WriteString(fmt.Sprintf("Gist description set to \"%s\"\n\n", opts["description"])) + } + if hasNoCommits, err := git.HasNoCommits(gist.User.Username, gist.Uuid); err != nil { _, _ = fmt.Fprintln(er, "Failed to check if gist has no commits") return fmt.Errorf("failed to check if gist has no commits: %w", err)