Skip to content

Commit

Permalink
Refactor config and github config
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Feb 24, 2022
1 parent 1681fd7 commit 217c550
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 333 deletions.
13 changes: 6 additions & 7 deletions cmd/self-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/Masterminds/semver/v3"
"github.com/b4b4r07/afx/pkg/config"
"github.com/b4b4r07/afx/pkg/errors"
"github.com/b4b4r07/afx/pkg/github"
"github.com/b4b4r07/afx/pkg/helpers/templates"
"github.com/creativeprojects/go-selfupdate"
"github.com/fatih/color"
Expand Down Expand Up @@ -110,18 +110,17 @@ func (c *selfUpdateCmd) selectTag(args []string) error {
return errors.Wrap(err, "failed to get input from console")
}

release := config.GitHubRelease{
Name: "afx",
Client: http.DefaultClient,
Assets: config.Assets{},
Filename: "",
release := github.Release{
Name: "afx",
Client: http.DefaultClient,
Assets: github.Assets{},
}

rel := gjson.Get(string(body), fmt.Sprintf("#(tag_name==\"%s\")", tag))
assets := rel.Get("assets")
assets.ForEach(func(key, value gjson.Result) bool {
name := value.Get("name").String()
release.Assets = append(release.Assets, config.Asset{
release.Assets = append(release.Assets, github.Asset{
Name: name,
Home: filepath.Join(os.Getenv("HOME"), ".afx"),
Path: filepath.Join(os.Getenv("HOME"), ".afx", name),
Expand Down
24 changes: 0 additions & 24 deletions pkg/config/gist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package config

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"path/filepath"

Expand All @@ -28,28 +26,6 @@ type Gist struct {
DependsOn []string `yaml:"depends-on"`
}

func NewGist(owner, id string) (Gist, error) {
type data struct {
Description string `json:"description"`
}
resp, err := http.Get(fmt.Sprintf("https://api.github.com/gists/%s", id))
if err != nil {
return Gist{}, err
}
defer resp.Body.Close()
var d data
err = json.NewDecoder(resp.Body).Decode(&d)
if err != nil {
return Gist{}, err
}
return Gist{
Name: id,
Owner: owner,
ID: id,
Description: d.Description,
}, nil
}

// Init is
func (c Gist) Init() error {
var errs errors.Errors
Expand Down
Loading

0 comments on commit 217c550

Please sign in to comment.