Drop error only on purpose or else report back or log (#514)

- Remove Deadcode
- Simplify Code
- Drop error only on purpose
This commit is contained in:
6543
2021-11-23 15:36:52 +01:00
committed by GitHub
parent f454371e56
commit fe31fb1e06
59 changed files with 464 additions and 347 deletions

View File

@@ -239,7 +239,7 @@ func (c *config) Activate(ctx context.Context, u *model.User, r *model.Repo, lin
if err != nil {
return err
}
c.Deactivate(ctx, u, r, link)
_ = c.Deactivate(ctx, u, r, link)
return c.newClient(ctx, u).CreateHook(r.Owner, r.Name, &internal.Hook{
Active: true,

View File

@@ -30,7 +30,6 @@ import (
const (
get = "GET"
put = "PUT"
post = "POST"
del = "DELETE"
)
@@ -213,7 +212,7 @@ func (c *Client) do(rawurl, method string, in, out interface{}) (*string, error)
// error response.
if resp.StatusCode > http.StatusPartialContent {
err := Error{}
json.NewDecoder(resp.Body).Decode(&err)
_ = json.NewDecoder(resp.Body).Decode(&err)
err.Status = resp.StatusCode
return nil, err
}

View File

@@ -28,13 +28,7 @@ const (
hookPush = "repo:push"
hookPullCreated = "pullrequest:created"
hookPullUpdated = "pullrequest:updated"
changeBranch = "branch"
changeNamedBranch = "named_branch"
stateMerged = "MERGED"
stateDeclined = "DECLINED"
stateOpen = "OPEN"
stateOpen = "OPEN"
)
// parseHook parses a Bitbucket hook from an http.Request request and returns

View File

@@ -100,11 +100,6 @@ func getDepot(c *gin.Context) {
}
}
func getProjects(c *gin.Context) {
c.Header("Content-Type", "application/json;charset=UTF-8")
c.String(200, fakeProjectsPayload)
}
func getFile(c *gin.Context) {
c.Header("Content-Type", "application/json;charset=UTF-8")
switch fmt.Sprintf("%s/%s/%s/%s", c.Param("gk"), c.Param("prj"), c.Param("ref"), c.Param("path")) {
@@ -273,23 +268,6 @@ const projectNotFoundPayload = `
}
`
const fakeProjectsPayload = `
{
"code":0,
"data":{
"list":{
"owner_user_name":"demo1",
"name":"test1",
"icon":"/static/project_icon/scenery-5.png",
},
"page":1,
"pageSize":1,
"totalPage":1,
"totalRow":1
}
}
`
const fakeFilePayload = `
{
"code":0,

View File

@@ -76,7 +76,7 @@ func createRepoHook(c *gin.Context) {
URL string `json:"url"`
} `json:"config"`
}{}
c.BindJSON(&in)
_ = c.BindJSON(&in)
if in.Type != "gitea" ||
in.Conf.Type != "json" ||
in.Conf.URL != "http://localhost" {

View File

@@ -115,18 +115,6 @@ func convertPerm(from *github.Repository) *model.Perm {
}
}
// convertTeamPerm is a helper function used to convert a GitHub organization
// permissions to the common Woodpecker permissions structure.
func convertTeamPerm(from *github.Membership) *model.Perm {
admin := false
if *from.Role == "admin" {
admin = true
}
return &model.Perm{
Admin: admin,
}
}
// convertRepoList is a helper function used to convert a GitHub repository
// list to the common Woodpecker repository structure.
func convertRepoList(from []*github.Repository, private bool) []*model.Repo {

View File

@@ -270,9 +270,9 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
for i := 0; i < len(data); i++ {
select {
case err, _ := <-errc:
case err := <-errc:
errors = append(errors, err)
case fileMeta, _ := <-fc:
case fileMeta := <-fc:
files = append(files, fileMeta)
}
}
@@ -464,7 +464,7 @@ func repoStatus(c context.Context, client *github.Client, r *model.Repo, b *mode
return err
}
var reDeploy = regexp.MustCompile(".+/deployments/(\\d+)")
var reDeploy = regexp.MustCompile(`.+/deployments/(\d+)`)
func deploymentStatus(ctx context.Context, client *github.Client, r *model.Repo, b *model.Build, link string) error {
matches := reDeploy.FindStringSubmatch(b.Link)

View File

@@ -150,11 +150,6 @@ var (
Token: "cfcd2084",
}
fakeUserNoRepos = &model.User{
Login: "octocat",
Token: "repos_not_found",
}
fakeRepo = &model.Repo{
Owner: "octocat",
Name: "Hello-World",
@@ -170,8 +165,4 @@ var (
Name: "repo_not_found",
FullName: "test_name/repo_not_found",
}
fakeBuild = &model.Build{
Commit: "9ecad50",
}
)

View File

@@ -61,7 +61,7 @@ func createRepoHook(c *gin.Context) {
URL string `json:"url"`
} `json:"config"`
}{}
c.BindJSON(&in)
_ = c.BindJSON(&in)
if in.Type != "gogs" ||
in.Conf.Type != "json" ||
in.Conf.URL != "http://localhost" {