1
0

Add Golangci Lint (#676)

Increase golangci timeout

Fix installing golangci-lint in ci

Remove mage targets replaced by golangci

Run golint in ci

Add goheader linter

Enable & fix more linters

Fix lint issues

Add mage target to automagically fix issues found by golangci

golangci-lint run --fix

Add golangci config

Add golangci mage target

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/676
Co-Authored-By: konrad <konrad@kola-entertainments.de>
Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2020-10-11 20:10:03 +00:00
parent d56a611be7
commit 699d3d6060
143 changed files with 630 additions and 426 deletions

View File

@ -18,10 +18,11 @@ package migration
import (
"bytes"
"io/ioutil"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/user"
"io/ioutil"
)
// InsertFromStructure takes a fully nested Vikunja data structure and a user and then creates everything for this user

View File

@ -17,12 +17,13 @@
package migration
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestInsertFromStructure(t *testing.T) {

View File

@ -17,12 +17,13 @@
package handler
import (
"net/http"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/migration"
user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler"
"github.com/labstack/echo/v4"
"net/http"
)
// MigrationWeb holds the web migration handler

View File

@ -17,12 +17,13 @@
package migration
import (
"os"
"testing"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/user"
"os"
"testing"
)
// TestMain is the main test function used to bootstrap the test env

View File

@ -17,8 +17,9 @@
package migration
import (
"code.vikunja.io/api/pkg/user"
"time"
"code.vikunja.io/api/pkg/user"
)
// Status represents this migration status

View File

@ -18,6 +18,14 @@ package todoist
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log"
@ -25,12 +33,6 @@ import (
"code.vikunja.io/api/pkg/modules/migration"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"time"
)
// Migration is the todoist migration struct
@ -217,7 +219,7 @@ func (m *Migration) AuthURL() string {
}
func doPost(url string, form url.Values) (resp *http.Response, err error) {
req, err := http.NewRequest("POST", url, strings.NewReader(form.Encode()))
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, strings.NewReader(form.Encode()))
if err != nil {
return
}
@ -342,7 +344,12 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
// Only add the attachment if there's something to download
if len(n.FileAttachment.FileURL) > 0 {
// Download the attachment and put it in the file
resp, err := http.Get(n.FileAttachment.FileURL)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, n.FileAttachment.FileURL, nil)
if err != nil {
return nil, err
}
hc := http.Client{}
resp, err := hc.Do(req)
if err != nil {
return nil, err
}
@ -417,6 +424,7 @@ func getAccessTokenFromAuthToken(authToken string) (accessToken string, err erro
if err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
buf := &bytes.Buffer{}
@ -468,6 +476,7 @@ func (m *Migration) Migrate(u *user.User) (err error) {
if err != nil {
return
}
defer resp.Body.Close()
syncResponse := &sync{}
err = json.NewDecoder(resp.Body).Decode(syncResponse)

View File

@ -17,15 +17,16 @@
package todoist
import (
"io/ioutil"
"strconv"
"testing"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/models"
"github.com/stretchr/testify/assert"
"gopkg.in/d4l3k/messagediff.v1"
"io/ioutil"
"strconv"
"testing"
"time"
)
func TestConvertTodoistToVikunja(t *testing.T) {
@ -43,7 +44,6 @@ func TestConvertTodoistToVikunja(t *testing.T) {
dueTime = dueTime.In(config.GetTimeZone())
nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z")
assert.NoError(t, err)
//nilTime = nilTime.In(config.GetTimeZone())
exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg")
assert.NoError(t, err)

View File

@ -18,6 +18,14 @@ package wunderlist
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log"
@ -25,12 +33,6 @@ import (
"code.vikunja.io/api/pkg/modules/migration"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
)
// Migration represents the implementation of the migration for wunderlist
@ -51,17 +53,17 @@ type wunderlistAuthToken struct {
}
type task struct {
ID int `json:"id"`
AssigneeID int `json:"assignee_id"`
CreatedAt time.Time `json:"created_at"`
CreatedByID int `json:"created_by_id"`
Completed bool `json:"completed"`
CompletedAt time.Time `json:"completed_at"`
DueDate string `json:"due_date"`
ID int `json:"id"`
ListID int `json:"list_id"`
Revision int `json:"revision"`
Starred bool `json:"starred"`
Title string `json:"title"`
Completed bool `json:"completed"`
CompletedAt time.Time `json:"completed_at"`
}
type list struct {
@ -181,7 +183,11 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) (
for _, f := range content.files {
if f.TaskID == t.ID {
// Download the attachment and put it in the file
resp, err := http.Get(f.URL)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, f.URL, nil)
if err != nil {
return nil, err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
@ -296,7 +302,7 @@ func convertWunderlistToVikunja(content *wunderlistContents) (fullVikunjaHierach
}
func makeAuthGetRequest(token *wunderlistAuthToken, urlPart string, v interface{}, urlParams url.Values) error {
req, err := http.NewRequest(http.MethodGet, "https://a.wunderlist.com/api/v1/"+urlPart, nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://a.wunderlist.com/api/v1/"+urlPart, nil)
if err != nil {
return err
}
@ -366,10 +372,16 @@ func (w *Migration) Migrate(user *user.User) (err error) {
if err != nil {
return
}
resp, err := http.Post("https://www.wunderlist.com/oauth/access_token", "application/json", bytes.NewBuffer(jsonAuth))
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, "https://www.wunderlist.com/oauth/access_token", bytes.NewBuffer(jsonAuth))
if err != nil {
return err
}
req.Header.Add("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
authToken := &wunderlistAuthToken{}
err = json.NewDecoder(resp.Body).Decode(authToken)

View File

@ -17,15 +17,16 @@
package wunderlist
import (
"io/ioutil"
"strconv"
"testing"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/models"
"github.com/stretchr/testify/assert"
"gopkg.in/d4l3k/messagediff.v1"
"io/ioutil"
"strconv"
"testing"
"time"
)
func TestWunderlistParsing(t *testing.T) {