Skip to content

Commit

Permalink
feat: ignore not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
Beatriz Vieira committed Dec 9, 2018
1 parent 9875448 commit 3d4dc40
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gitlabels/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"log"
"net/http"
"regexp"

"github.com/google/go-github/github"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (s Service) removeLabels(ctx context.Context, user, repo string, labels []s
err := s.git.DeleteLabel(ctx, user, repo, label)
if err == nil {
s.logger.Printf("[%s/%s] removed label:[%s]", user, repo, label)
} else {
} else if !isNotFound(err) {
s.logger.Printf("[%s/%s] failed to remove label:[%s], error: %v", user, repo, label, err)
}
}
Expand All @@ -81,7 +82,7 @@ func (s Service) renameLabels(ctx context.Context, user, repo string, labels map
err := s.git.EditLabel(ctx, user, repo, label, newLabel, labelsInfo[newLabel])
if err == nil {
s.logger.Printf("[%s/%s] renaming label from:[%s] to:[%s]", user, repo, label, newLabel)
} else {
} else if !isNotFound(err) {
renamed[newLabel] = nil
s.logger.Printf("[%s/%s] failed to rename label from:[%s] to:[%s], error: %v", user, repo, label, newLabel, err)
}
Expand Down Expand Up @@ -114,6 +115,11 @@ func (s Service) createLabels(ctx context.Context, user, repo string, labels map
return nil
}

func isNotFound(err error) bool {
errorResponse, ok := err.(*github.ErrorResponse)
return ok && errorResponse.Response.StatusCode == http.StatusNotFound
}

func findError(errors []github.Error, code string) bool {
for _, err := range errors {
if err.Code == code {
Expand Down

0 comments on commit 3d4dc40

Please sign in to comment.