<commit_before>package webservice

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/url"
	"strings"

	"github.com/flexiant/kdeploy/utils"
)

// FetchKubeFromURL fetches a remote kubeware, extracts it locally, and returns its local path
func FetchKubeFromURL(kubeURL string) (string, error) {
	kubewareURL, err := url.Parse(kubeURL)
	if err != nil {
		return "", err
	}

	if kubewareURL.Host != "github.com" {
		return "", errors.New("We currently only support Github urls")
	}

	path := strings.Split(kubewareURL.Path, "/")
	kubewareName := path[2]

	newPath := append([]string{""}, path[1], path[2], "archive", "master.zip")

	kubewareURL.Path = strings.Join(newPath, "/")

	client, err := NewSimpleWebClient(kubewareURL.String())
	utils.CheckError(err)

	tmpDir, err := ioutil.TempDir("", "kdeploy")
	utils.CheckError(err)

	zipFileLocation, err := client.GetFile(kubewareURL.Path, tmpDir)
	utils.CheckError(err)

	err = utils.Unzip(zipFileLocation, tmpDir)
	utils.CheckError(err)

	return fmt.Sprintf("%s/%s-master/", tmpDir, kubewareName), nil<commit_msg>Avoid panic when incorrect url format.<commit_after>package webservice

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/url"
	"strings"

	"github.com/flexiant/kdeploy/utils"
)

// FetchKubeFromURL fetches a remote kubeware, extracts it locally, and returns its local path
func FetchKubeFromURL(kubeURL string) (string, error) {
	kubewareURL, err := url.Parse(kubeURL)
	if err != nil {
		return "", err
	}

	if kubewareURL.Host != "github.com" {
		return "", errors.New("We currently only support Github urls")
	}

	path := strings.Split(kubewareURL.Path, "/")
	if len(path) != 3 {
		return "", fmt.Errorf("Github URL should have the following format: 'https://github.com/<user>/<repo_name>'")
	}
	kubewareName := path[2]

	newPath := append([]string{""}, path[1], path[2], "archive", "master.zip")

	kubewareURL.Path = strings.Join(newPath, "/")

	client, err := NewSimpleWebClient(kubewareURL.String())
	utils.CheckError(err)

	tmpDir, err := ioutil.TempDir("", "kdeploy")
	utils.CheckError(err)

	zipFileLocation, err := client.GetFile(kubewareURL.Path, tmpDir)
	utils.CheckError(err)

	err = utils.Unzip(zipFileLocation, tmpDir)
	utils.CheckError(err)

	return fmt.Sprintf("%s/%s-master/", tmpDir, kubewareName), nil
{'fraction_non_alphanumeric': 0.1576398062527521, 'fraction_numerical': 0.0030823425803610744, 'mean_word_length': 4.963254593175853, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7419612', 'n_tokens_mistral': 873, 'n_tokens_neox': 840, 'n_words': 176}