2024-03-16 14:08:19 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-03-16 17:44:01 -05:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-03-16 14:08:19 -05:00
|
|
|
|
2024-03-16 17:44:01 -05:00
|
|
|
"code.gitea.io/sdk/gitea"
|
2024-03-16 17:05:19 -05:00
|
|
|
"github.com/akamensky/argparse"
|
2024-03-16 14:08:19 -05:00
|
|
|
)
|
|
|
|
|
2024-03-16 17:25:18 -05:00
|
|
|
var config Configuration
|
2024-03-16 17:44:01 -05:00
|
|
|
var Clients map[string]*gitea.Client
|
2024-03-16 17:25:18 -05:00
|
|
|
|
2024-03-16 17:05:19 -05:00
|
|
|
func summary() {
|
|
|
|
fmt.Println("Summary")
|
2024-03-16 17:44:01 -05:00
|
|
|
for name, client := range Clients {
|
|
|
|
server_version, _, err := client.ServerVersion()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Failed to get server version! (%s)\n", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("%s - %s\n", name, server_version)
|
|
|
|
}
|
2024-03-16 17:05:19 -05:00
|
|
|
}
|
|
|
|
|
2024-03-16 14:08:19 -05:00
|
|
|
func main() {
|
2024-03-16 17:05:19 -05:00
|
|
|
parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics")
|
|
|
|
Summary := parser.NewCommand("summary", "Generate a summary of a user's activity.")
|
2024-03-16 17:25:18 -05:00
|
|
|
config_path := parser.String("c", "config", &argparse.Options{Required: false, Help: "Configuration file", Default: "./config.lua"})
|
2024-03-16 17:44:01 -05:00
|
|
|
server_option := parser.String("s", "server", &argparse.Options{Required: false, Help: "Specific server to use"})
|
2024-03-16 17:05:19 -05:00
|
|
|
|
|
|
|
parse_err := parser.Parse(os.Args)
|
|
|
|
if parse_err != nil {
|
|
|
|
fmt.Print(parser.Usage(parse_err))
|
2024-03-16 17:25:18 -05:00
|
|
|
return
|
2024-03-16 14:08:19 -05:00
|
|
|
}
|
2024-03-16 17:05:19 -05:00
|
|
|
|
2024-03-16 17:44:01 -05:00
|
|
|
Clients = make(map[string]*gitea.Client)
|
2024-03-16 17:25:18 -05:00
|
|
|
config = Configuration{}
|
|
|
|
if err := config.Parse(*config_path); err != nil {
|
|
|
|
panic("Failed to parse configuration file")
|
2024-03-16 14:08:19 -05:00
|
|
|
}
|
2024-03-16 17:05:19 -05:00
|
|
|
|
2024-03-16 17:44:01 -05:00
|
|
|
for _, server := range config.servers {
|
|
|
|
if *server_option != "" && strings.ToLower(server.servername) != strings.ToLower(*server_option) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
client, err := gitea.NewClient(server.url)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Failed to create Gitea client! (%s)\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
Clients[server.servername] = client
|
|
|
|
}
|
|
|
|
if len(Clients) == 0 {
|
|
|
|
println("No servers configured / specified")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-03-16 17:05:19 -05:00
|
|
|
if Summary.Happened() {
|
|
|
|
summary()
|
|
|
|
}
|
2024-03-16 14:08:19 -05:00
|
|
|
}
|