mirror of
https://github.com/packwiz/packwiz.git
synced 2025-11-19 01:24:32 +01:00
github: standardize language + fix api requests
language: - funcs, vars, log messages, etc. api requests: - make all requests use the makeGet() function - include packwiz user agent Signed-off-by: unilock <unilock@fennet.rentals>
This commit is contained in:
@@ -3,9 +3,7 @@ package github
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/packwiz/packwiz/cmd"
|
||||
@@ -16,7 +14,7 @@ import (
|
||||
var githubCmd = &cobra.Command{
|
||||
Use: "github",
|
||||
Aliases: []string{"gh"},
|
||||
Short: "Manage github-based mods",
|
||||
Short: "Manage projects released on GitHub",
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -27,7 +25,7 @@ func init() {
|
||||
func fetchRepo(slug string) (Repo, error) {
|
||||
var repo Repo
|
||||
|
||||
res, err := http.Get(githubApiUrl + "repos/" + slug)
|
||||
res, err := ghDefaultClient.getRepo(slug)
|
||||
if err != nil {
|
||||
return repo, err
|
||||
}
|
||||
@@ -45,7 +43,7 @@ func fetchRepo(slug string) (Repo, error) {
|
||||
}
|
||||
|
||||
if repo.FullName == "" {
|
||||
return repo, errors.New("invalid json while fetching mod: " + slug)
|
||||
return repo, errors.New("invalid json while fetching project: " + slug)
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
@@ -53,14 +51,12 @@ func fetchRepo(slug string) (Repo, error) {
|
||||
|
||||
type Repo struct {
|
||||
ID int `json:"id"`
|
||||
NodeID string `json:"node_id"` // TODO: use this with GH API, instead of name (to acct. for repo renames?) + store in mod.pw.toml
|
||||
Name string `json:"name"` // "hello_world"
|
||||
FullName string `json:"full_name"` // "owner/hello_world"
|
||||
}
|
||||
|
||||
type Release struct {
|
||||
URL string `json:"url"`
|
||||
NodeID string `json:"node_id"` // TODO: probably also use this with GH API
|
||||
TagName string `json:"tag_name"`
|
||||
TargetCommitish string `json:"target_commitish"` // The branch of the release
|
||||
Name string `json:"name"`
|
||||
@@ -87,13 +83,10 @@ func (u Asset) getSha256() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp, err := http.Get(u.BrowserDownloadURL)
|
||||
resp, err := ghDefaultClient.makeGet(u.BrowserDownloadURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return "", fmt.Errorf("invalid response status: %v", resp.StatusCode)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user