Skip to content

Commit

Permalink
POC for fetching latest firmware release from github
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Jun 6, 2019
1 parent e3e68dd commit 32cc974
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmd/github/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"

"github.com/google/go-github/github"
)

func main() {
client := github.NewClient(nil)

release, _, err := client.Repositories.GetLatestRelease(context.Background(), "keepkey", "keepkey-firmware")
if err != nil {
log.Fatal(err)
}

for _, asset := range release.Assets {
fmt.Println(pretty(asset))
if *asset.Name != "blupdater.bin" {
continue
}

resp, err := http.Get(asset.GetBrowserDownloadURL())
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

ioutil.WriteFile(*asset.Name, body, 0644)

}
//release.GetAssetsURL()
}

func pretty(i interface{}) string {

buf, _ := json.MarshalIndent(i, "", " ")
return string(buf)
}

0 comments on commit 32cc974

Please sign in to comment.