This commit is contained in:
Kota Kanbe
2017-05-31 20:42:20 +09:00
committed by kota kanbe
parent a14810bbd4
commit c6ad9ea57a
7 changed files with 210 additions and 406 deletions

View File

@@ -596,14 +596,6 @@ type Cpe struct {
// References is a slice of Reference
type References []Reference
// Find elements that matches the function passed in argument
func (r References) Find(f func(r Reference) bool) (refs []Reference) {
for _, rr := range r {
refs = append(refs, rr)
}
return
}
// Reference has a related link of the CVE
type Reference struct {
Source string

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package models
import (
"bytes"
"fmt"
"strings"
)
@@ -110,10 +111,39 @@ func (p Package) FormatNewVer() string {
// FormatVersionFromTo formats installed and new package version
func (p Package) FormatVersionFromTo() string {
return fmt.Sprintf("%s-%s -> %s",
return fmt.Sprintf("%s-%s - %s",
p.Name, p.FormatVer(), p.FormatNewVer())
}
// FormatChangelog formats the changelog
func (p Package) FormatChangelog() string {
buf := []string{}
if p.NewVersion == "" {
return ""
}
packVer := fmt.Sprintf("%s-%s -> %s",
p.Name, p.FormatVer(), p.FormatNewVer())
var delim bytes.Buffer
for i := 0; i < len(packVer); i++ {
delim.WriteString("-")
}
clog := p.Changelog.Contents
if lines := strings.Split(clog, "\n"); len(lines) != 0 {
clog = strings.Join(lines[0:len(lines)-1], "\n")
}
switch p.Changelog.Method {
case FailedToGetChangelog:
clog = "No changelogs"
case FailedToFindVersionInChangelog:
clog = "Failed to parse changelogs. For detials, check yourself"
}
buf = append(buf, packVer, delim.String(), clog)
return strings.Join(buf, "\n")
}
// Changelog has contents of changelog and how to get it.
// Method: modesl.detectionMethodStr
type Changelog struct {