diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-05-04 13:19:56 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-05-05 18:16:10 +0200 |
commit | f7ea3421caa2c8957a82454255c4fdd699b70a9c (patch) | |
tree | 299faef7b4588dd5f39b0908ee3c5668655926a6 /bug | |
parent | 0d976f66e87b7c053b10d50fe0849f6c8e5412e6 (diff) | |
download | git-bug-f7ea3421caa2c8957a82454255c4fdd699b70a9c.tar.gz |
Add ForceLabelChange functionalities
Diffstat (limited to 'bug')
-rw-r--r-- | bug/op_label_change.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bug/op_label_change.go b/bug/op_label_change.go index a2108941..0e7929b7 100644 --- a/bug/op_label_change.go +++ b/bug/op_label_change.go @@ -234,6 +234,33 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r return results, labelOp, nil } +// ForceChangeLabels is a convenience function to apply the operation +// The difference with ChangeLabels is that no checks of deduplications are done. You are entirely +// responsible of what you are doing. In the general case, you want to use ChangeLabels instead. +// The intended use of this function is to allow importers to create legal but unexpected label changes, +// like removing a label with no information of when it was added before. +func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string) (*LabelChangeOperation, error) { + added := make([]Label, len(add)) + for i, str := range add { + added[i] = Label(str) + } + + removed := make([]Label, len(remove)) + for i, str := range remove { + removed[i] = Label(str) + } + + labelOp := NewLabelChangeOperation(author, unixTime, added, removed) + + if err := labelOp.Validate(); err != nil { + return nil, err + } + + b.Append(labelOp) + + return labelOp, nil +} + func labelExist(labels []Label, label Label) bool { for _, l := range labels { if l == label { |