getCommitOrVersion parses the commit or version from go modules and returns the commit sha or ref and whether the result is a git sha
(cov string)
| 200 | // getCommitOrVersion parses the commit or version from go modules |
| 201 | // and returns the commit sha or ref and whether the result is a git sha |
| 202 | func getCommitOrVersion(cov string) (string, bool) { |
| 203 | // parse the commit or version. It'll either be of the form |
| 204 | // v0.0.0 or v0.0.0-date-commitID. Split by '-' to check |
| 205 | dashFields := strings.FieldsFunc(cov, func(c rune) bool { return c == '-' }) |
| 206 | fieldsLen := len(dashFields) |
| 207 | |
| 208 | if fieldsLen > 3 { |
| 209 | // empty string signifies error to caller |
| 210 | return "", false |
| 211 | } |
| 212 | |
| 213 | var isSha bool |
| 214 | |
| 215 | // if dashFields has one or two fields, it is likely a version (possibly with a -rc1). |
| 216 | // Thus, it should be used as is. |
| 217 | // the only case we meddle is when there are three fields, so we can strip the commitID |
| 218 | if len(dashFields) == 3 { |
| 219 | // If there are three fields, use the last (the commit) |
| 220 | // as often the version found in the first field is just a placeholder |
| 221 | cov = dashFields[2] |
| 222 | isSha = true |
| 223 | } |
| 224 | |
| 225 | // despite it being idiomatic to go modules, the +incompatible is a bit |
| 226 | // unsightly in release notes. Let's cut it out of the version if it |
| 227 | // exists |
| 228 | if incpIdx := strings.Index(cov, "+incompatible"); incpIdx > 0 { |
| 229 | return cov[:incpIdx], isSha |
| 230 | } |
| 231 | return cov, isSha |
| 232 | } |
| 233 | |
| 234 | func formatDependency(name, commitOrVersion string, isSha bool) dependency { |
| 235 | var sha string |
no outgoing calls