Skip to content

Commit

Permalink
added github url parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Simple-MAX committed Sep 29, 2022
1 parent 4f50148 commit 03d9c07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/github/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ const (
ProtoPortDir = "ProtoPort"
)

func GithubGetContent(url string, subpath string, pat string, publicRepo bool) ([]types.GithubContentApi, error) {
var contents []types.GithubContentApi
func GithubUrlParser(url string, subpath string) string {

url = strings.Replace(url, "/tree/main", "/contents", 1)

if subpath != "" {
url = strings.Replace(url, "https://github.com/", "https://api.github.com/repos/", 1) + "/contents/" + subpath
url = strings.Replace(url, "https://github.com/", "https://api.github.com/repos/", 1) + subpath
} else {
url = strings.Replace(url, "https://github.com/", "https://api.github.com/repos/", 1) + "/contents"
url = strings.Replace(url, "https://github.com/", "https://api.github.com/repos/", 1)
}

return url
}

func GithubGetContent(url string, subpath string, pat string, publicRepo bool) ([]types.GithubContentApi, error) {
var contents []types.GithubContentApi

url = GithubUrlParser(url, subpath)

req, err := http.NewRequest("GET", url, nil)

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/protoc/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -94,6 +95,7 @@ func BuildProto(protoPath, output, protoFile string, lang string) error {
command.Stderr = &stderr
err := command.Run()
if err != nil {
log.Println(fmt.Sprint(err) + ": " + stderr.String())
return fmt.Errorf("error building proto file")
}

Expand Down

0 comments on commit 03d9c07

Please sign in to comment.