feat: add Vikunja issues provider and integrate tasks retrieval
Co-authored-by: aider (openai/qwen2.5-coder:32b-instruct-q4_0) <aider@aider.chat>
This commit is contained in:
parent
ef6e0c97d2
commit
1f36c2ef9f
1 changed files with 47 additions and 0 deletions
47
issues/vikunja/vikunja.go
Normal file
47
issues/vikunja/vikunja.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package vikunja
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Status int `json:"status"` // Assuming 1 is for completed tasks
|
||||
}
|
||||
|
||||
func GetTasks(instance, user, from, to string) ([]Task, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/api/v1/user/tasks", instance), nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building vikunja request: %w", err)
|
||||
}
|
||||
q := req.URL.Query()
|
||||
q.Add("user_id", user)
|
||||
q.Add("status", "1") // Assuming 1 is for completed tasks
|
||||
req.URL.RawQuery = q.Encode()
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", os.Getenv("VIKUNJA_TOKEN")))
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error executing vikunja request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
b := bytes.NewBuffer(nil)
|
||||
io.Copy(b, resp.Body)
|
||||
return nil, fmt.Errorf("error talking to vikunja: %s", b.String())
|
||||
}
|
||||
|
||||
var tasks []Task
|
||||
err = json.NewDecoder(resp.Body).Decode(&tasks)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding vikunja response: %w", err)
|
||||
}
|
||||
|
||||
return tasks, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue