vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
refactor
c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 17d ago · parent ec2aba4b
metadata/request_find.go +36
| @@ -0,0 +1,36 @@ | |||
| 1 | package metadata | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "strings" | ||
| 6 | |||
| 7 | "github.com/rodent-software/vole/core/git" | ||
| 8 | ) | ||
| 9 | |||
| 10 | // Find returns one request by id. A unique prefix is accepted, because the list | ||
| 11 | // command prints full ids but people type the part they read. | ||
| 12 | func FindRequest(g *git.Repo, id string) (*Request, error) { | ||
| 13 | id = strings.TrimSpace(id) | ||
| 14 | list, err := LoadRequests(g, Ref) | ||
| 15 | if err != nil { | ||
| 16 | return nil, err | ||
| 17 | } | ||
| 18 | for _, r := range list { | ||
| 19 | if r.ID == id || (len(id) >= 4 && strings.HasPrefix(r.ID, strings.ToUpper(id))) { | ||
| 20 | return r, nil | ||
| 21 | } | ||
| 22 | } | ||
| 23 | return nil, fmt.Errorf("no change request matches %q", id) | ||
| 24 | } | ||
| 25 | |||
| 26 | // CurrentApprovals counts the approvals that still name the request's current | ||
| 27 | // head and base. An approval of an older head is history, not a vote. | ||
| 28 | func (r *Request) CurrentApprovals() int { | ||
| 29 | n := 0 | ||
| 30 | for _, a := range r.Approvals { | ||
| 31 | if a.Head == r.Head && a.Base == r.Base { | ||
| 32 | n++ | ||
| 33 | } | ||
| 34 | } | ||
| 35 | return n | ||
| 36 | } | ||