mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 01:05:26 +01:00 
			
		
		
		
	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>
This commit is contained in:
		
							
								
								
									
										44
									
								
								modules/print/comment.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								modules/print/comment.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| // 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, | ||||
| 	) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Norwin
					Norwin