88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
)
|
|
|
|
// Activity stores an entry in a gitea user's activity feed.
|
|
type Activity struct {
|
|
act_user *gitea.User
|
|
act_user_id int64
|
|
comment gitea.Comment
|
|
comment_id int64
|
|
content string
|
|
created string
|
|
id int64
|
|
is_private bool
|
|
op_type string
|
|
ref_name string
|
|
repo *gitea.Repository
|
|
repo_id int64
|
|
user_id int64
|
|
}
|
|
|
|
// getActivityFeed returns the authenticated user's activity feed.
|
|
func getActivityFeed() []Activity {
|
|
feed := []Activity{}
|
|
for _, server := range config.servers {
|
|
client := Servers[server.servername]
|
|
resp, err := http.Get(fmt.Sprintf("%s/api/v1/users/%s/activities/feeds?limit=15&page=1",
|
|
server.url,
|
|
server.username,
|
|
))
|
|
if err != nil {
|
|
println("Failed to make HTTP request")
|
|
continue
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
var data []map[string]interface{}
|
|
err = json.NewDecoder(resp.Body).Decode(&data)
|
|
if err != nil {
|
|
fmt.Println("Error decoding JSON: "+fmt.Sprint(err))
|
|
continue
|
|
}
|
|
for _, obj := range data {
|
|
act_user, _, err := client.GetUserInfo(obj["act_user"].(map[string]interface{})["login"].(string))
|
|
if err != nil {
|
|
fmt.Println("Error getting user: "+fmt.Sprint(err))
|
|
continue
|
|
}
|
|
var comment gitea.Comment
|
|
if obj["comment"] != nil {
|
|
raw_comment := obj["comment"].(map[string]interface{})
|
|
comment = gitea.Comment{
|
|
Body: raw_comment["body"].(string),
|
|
HTMLURL: raw_comment["html_url"].(string),
|
|
ID: int64(raw_comment["id"].(float64)),
|
|
IssueURL: raw_comment["issue_url"].(string),
|
|
OriginalAuthor: raw_comment["original_author"].(string),
|
|
OriginalAuthorID: int64(raw_comment["original_author_id"].(float64)),
|
|
}
|
|
}
|
|
feed = append(feed, Activity{
|
|
// repo: repo,
|
|
act_user: act_user,
|
|
act_user_id: int64(obj["act_user_id"].(float64)),
|
|
comment: comment,
|
|
comment_id: int64(obj["comment_id"].(float64)),
|
|
content: obj["content"].(string),
|
|
created: obj["created"].(string),
|
|
id: int64(obj["id"].(float64)),
|
|
is_private: obj["is_private"].(bool),
|
|
op_type: obj["op_type"].(string),
|
|
ref_name: obj["ref_name"].(string),
|
|
repo_id: int64(obj["repo_id"].(float64)),
|
|
user_id: int64(obj["user_id"].(float64)),
|
|
})
|
|
}
|
|
}
|
|
return feed
|
|
}
|
|
|
|
|