aboutsummaryrefslogtreecommitdiff
path: root/tools/src/updater/main.go
blob: e6e1560eb712b92f26613855c20cfadbcaec7472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
	"flag"
	"fmt"
	"net/http"
        "encoding/json"
        "io/ioutil"
)

func main() {
	helpFlag := flag.Bool("help", false, "Show help information")
        //verboseFlag := flag.Bool("verbose", false, "Print more information")
	//repoFlag := flag.String("repo", "https://neueland.iserlohn-fortress.net/smolbote/downloads", "Repository path")
	//dryRunFlag := flag.Bool("dry-run", false, "Dry run: only check files, do not download")

	flag.Parse()

        branchesRequest := "https://neueland.iserlohn-fortress.net/gitea/api/v1/repos/aqua/smolbote/branches"

	// help flag --> show usage and exit
	if *helpFlag {
		flag.PrintDefaults()
		return
	}

	response, err := http.Get(branchesRequest)
	if err != nil {
		panic(err)
	} else if response.StatusCode != 200 {
		fmt.Printf("Could not get manifest: %s\n", response.Status)
		return
	}
	defer response.Body.Close()

        body, _ := ioutil.ReadAll(response.Body)

        var branches []BranchResponse
        json.Unmarshal(body, &branches)


        for _,v := range(branches) {
            fmt.Printf("%s\t%s %s\n", v.Name, v.Commit.ID, v.Commit.Timestamp)
        }
        fmt.Println("done")

}