MCPcopy Create free account
hub / github.com/containerd/release-tool / getCommitOrVersion

Function getCommitOrVersion

util.go:202–232  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
202func 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
234func formatDependency(name, commitOrVersion string, isSha bool) dependency {
235 var sha string

Callers 3

TestParseModuleCommitFunction · 0.85
parseGoModDependenciesFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseModuleCommitFunction · 0.68