1
0
Fork 0
forked from forgejo/forgejo

Additional API support for labels (#3290)

* Add API support for labels.

* Error handling for adding/replacing multiple issue labels

* Revisions to function names and error handling. Use issue.ClearLabels in replace/clear functions

* Additional code cleanup
This commit is contained in:
lstahlman 2016-08-03 09:24:16 -07:00 committed by 无闻
parent b1133c9934
commit 2eeb0ec9b0
5 changed files with 399 additions and 1 deletions

View file

@ -5,6 +5,7 @@
package models
import (
"bytes"
"fmt"
)
@ -34,6 +35,30 @@ func (err ErrNamePatternNotAllowed) Error() string {
return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
}
type ErrMultipleErrors struct {
Errors []error
}
func IsErrMultipleErrors(err error) bool {
_, ok := err.(ErrMultipleErrors)
return ok
}
func (err ErrMultipleErrors) Error() string {
var message bytes.Buffer
message.WriteString("Multiple errors encountered: ")
for i := range err.Errors {
message.WriteString(err.Errors[i].Error())
if i < len(err.Errors)-1 {
message.WriteString("; ")
}
}
return message.String()
}
// ____ ___
// | | \______ ___________
// | | / ___// __ \_ __ \
@ -545,6 +570,20 @@ func (err ErrLabelNotExist) Error() string {
return fmt.Sprintf("label does not exist [id: %d]", err.ID)
}
type ErrLabelNotValidForRepository struct {
ID int64
RepoID int64
}
func IsErrLabelNotValidForRepository(err error) bool {
_, ok := err.(ErrLabelNotValidForRepository)
return ok
}
func (err ErrLabelNotValidForRepository) Error() string {
return fmt.Sprintf("label is not valid for repository [label_id: %d, repo_id: %d]", err.ID, err.RepoID)
}
// _____ .__.__ __
// / \ |__| | ____ _______/ |_ ____ ____ ____
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \