Example #1
0
func (f *Formatter) commentMapping(comment *gc.Comment) map[string]string {
	var path = ""
	var line = ""
	if comment.FileRef != nil {
		path = comment.FileRef.Path
		line = fmt.Sprintf("%v", comment.FileRef.Line)
	}
	return map[string]string{
		authorName:           comment.Author.Name,
		authorEmail:          comment.Author.Email,
		authorDateISO8601:    comment.Author.Date.Format(time.RFC3339),
		authorDateUnix:       fmt.Sprintf("%v", comment.Author.Date.Unix()),
		committerName:        comment.Amender.Name,
		committerEmail:       comment.Amender.Email,
		committerDateISO8601: comment.Amender.Date.Format(time.RFC3339),
		committerDateUnix:    fmt.Sprintf("%v", comment.Amender.Date.Unix()),
		commentFull:          *comment.ID,
		commentShort:         (*comment.ID)[:7],
		commitFull:           *comment.Commit,
		commitShort:          (*comment.Commit)[:7],
		bodyContent:          comment.Content,
		titleLine:            comment.Title(),
		filePath:             path,
		lineNumber:           line,
		newLine:              "\n",
		dividerLine:          strings.Repeat("-", int(f.termWidth)),
	}
}
Example #2
0
func (f *Formatter) FormatComment(comment *gc.Comment) string {
	var content string
	switch {
	case f.format == Short || len(f.format) == 0:
		content = f.substituteVariables(ShortFormat, comment)
	case f.format == Full:
		content = f.substituteVariables(FullFormat, comment)
	case f.format == Disco:
		content = f.substituteVariables(discoFormat, comment)
	case f.format == Raw:
		format := string(f.substituteVariables(RawFormat, comment))
		content = fmt.Sprintf(format, comment.Serialize())
	case strings.HasPrefix(f.format, formatPrefix):
		content = f.substituteVariables(f.format[len(formatPrefix):], comment)
	}

	var components []byte
	for _, lineContent := range strings.Split(content, "\n") {
		if f.useMargin {
			components = append(components, []byte(fmt.Sprintf("%s%s│%s%s", f.indent, f.colorMapping["magenta"], f.colorMapping["resetColor"], lineContent))...)
		} else {
			components = append(components, []byte(fmt.Sprintf("%s\n", lineContent))...)
		}
	}
	components = append(components, []byte("\n\n")...)
	return string(components)
}