add(gitea-api): issues and milestones getters
This implements the api getters for extracting the issues and milestones for a given gitea repository. WIP for #1.
This commit is contained in:
16
internal/gitea/gitea.go
Normal file
16
internal/gitea/gitea.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package gitea
|
||||
|
||||
var API_PATH = "/api/v1"
|
||||
|
||||
type Gitea struct {
|
||||
base_url string
|
||||
}
|
||||
|
||||
func NewGitea(base_url string) (gitea Gitea) {
|
||||
gitea.base_url = base_url
|
||||
return
|
||||
}
|
||||
|
||||
func (gitea *Gitea) Url() string {
|
||||
return gitea.base_url + API_PATH
|
||||
}
|
||||
@@ -1 +1,58 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PullRequest struct {
|
||||
Merged bool
|
||||
Merged_at time.Time
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
Id uint
|
||||
Url string
|
||||
Html_url string
|
||||
Number uint
|
||||
User User
|
||||
Original_author string
|
||||
Original_author_id uint
|
||||
Title string
|
||||
Body string
|
||||
Ref string
|
||||
Assets []string
|
||||
Labels []string
|
||||
Milestone Milestone
|
||||
Assignee User
|
||||
Assignees []User
|
||||
State string
|
||||
Is_locked bool
|
||||
Comments uint
|
||||
Created_at time.Time
|
||||
Updated_at time.Time
|
||||
Closed_at time.Time
|
||||
Due_date time.Time
|
||||
Pull_request PullRequest
|
||||
Repository Repository
|
||||
Pin_order uint
|
||||
}
|
||||
|
||||
func (gitea *Gitea) GetIssues(repo Repository) ([]Issue, error) {
|
||||
url := fmt.Sprintf("%s/repos/%s/issues?state=all", gitea.Url(), repo.Full_name)
|
||||
response, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
var data []Issue
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
// NOTE: remove this if I do not want to store everything from the json result in the struct
|
||||
decoder.DisallowUnknownFields() // remain if every field shall be extracted
|
||||
if err = decoder.Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
@@ -1 +1,38 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Milestone struct {
|
||||
Id uint
|
||||
Title string
|
||||
Description string
|
||||
State string
|
||||
Open_issues uint
|
||||
Closed_issues uint
|
||||
Created_at time.Time
|
||||
Updated_at time.Time
|
||||
Due_on time.Time
|
||||
Closed_at time.Time
|
||||
}
|
||||
|
||||
func (gitea *Gitea) GetMilestones(repo Repository) ([]Milestone, error) {
|
||||
url := fmt.Sprintf("%s/repos/%s/milestones?state=all", gitea.Url(), repo.Full_name)
|
||||
response, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
var data []Milestone
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
// NOTE: remove this if I do not want to store everything from the json result in the struct
|
||||
decoder.DisallowUnknownFields() // remain if every field shall be extracted
|
||||
if err = decoder.Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
17
internal/gitea/repository.go
Normal file
17
internal/gitea/repository.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package gitea
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Repository struct {
|
||||
Id uint
|
||||
Name string
|
||||
Owner string
|
||||
Full_name string
|
||||
}
|
||||
|
||||
func NewRepository(name, owner string) (repo Repository) {
|
||||
repo.Name = name
|
||||
repo.Owner = owner
|
||||
repo.Full_name = fmt.Sprintf("%s/%s", owner, name)
|
||||
return
|
||||
}
|
||||
27
internal/gitea/user.go
Normal file
27
internal/gitea/user.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package gitea
|
||||
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
Id uint
|
||||
Login string
|
||||
Login_name string
|
||||
Full_name string
|
||||
Email string
|
||||
Avatar_url string
|
||||
Language string
|
||||
Is_admin bool
|
||||
Last_login time.Time
|
||||
Created time.Time
|
||||
Restricted bool
|
||||
Active bool
|
||||
Prohibit_login bool
|
||||
Location string
|
||||
Website string
|
||||
Description string
|
||||
Visibility string
|
||||
Followers_count uint
|
||||
Following_count uint
|
||||
Starred_repos_count uint
|
||||
Username string
|
||||
}
|
||||
Reference in New Issue
Block a user