1
0
mirror of https://gitea.com/Sirherobrine23/tea.git synced 2024-07-07 10:26:21 -03:00
tea/modules/print/comment.go
Norwin 32b7b771cc Add tea comment and show comments of issues/pulls (#313)
show comments of PR

TODO: there needs to be a way to force running non-interactively

add `tea comment` to post a comment

add --comments flag, prompt only if necessary

don't prompt if --comments is provided, or output is piped

show comments for issues, add --comments flag

tea comment: print resulting comment

Merge branch 'master' into issue-172-comments

remove debug print statement

unrelated, but better than opening another PR for this ;)

Merge remote-tracking branch 'upstream/master' into issue-172-comments

ret err

fix lint

Co-authored-by: Norwin Roosen <git@nroo.de>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/313
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: 6543 <6543@obermui.de>
Co-Authored-By: Norwin <noerw@noreply.gitea.io>
Co-Committed-By: Norwin <noerw@noreply.gitea.io>
2020-12-22 00:07:35 +08:00

45 lines
991 B
Go

// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package print
import (
"fmt"
"strings"
"code.gitea.io/sdk/gitea"
)
// Comments renders a list of comments to stdout
func Comments(comments []*gitea.Comment) {
var out = make([]string, len(comments))
for i, c := range comments {
out[i] = formatComment(c)
}
outputMarkdown(fmt.Sprintf(
// this will become a heading by means of the first --- from a comment
"Comments\n%s",
strings.Join(out, "\n"),
))
}
// Comment renders a comment to stdout
func Comment(c *gitea.Comment) {
outputMarkdown(formatComment(c))
}
func formatComment(c *gitea.Comment) string {
edited := ""
if c.Updated.After(c.Created) {
edited = fmt.Sprintf(" *(edited on %s)*", FormatTime(c.Updated))
}
return fmt.Sprintf(
"---\n\n**@%s** wrote on %s%s:\n\n%s\n",
c.Poster.UserName,
FormatTime(c.Created),
edited,
c.Body,
)
}