updated github-to-gogs
This commit is contained in:
parent
61a76e1a06
commit
e3ee834572
24
functions.go
24
functions.go
@ -24,6 +24,7 @@ func (config *Config) GetConfig() error {
|
|||||||
var gogsconfig GogsConfig
|
var gogsconfig GogsConfig
|
||||||
|
|
||||||
flag.Usage = Usage
|
flag.Usage = Usage
|
||||||
|
|
||||||
flag.StringVar(&configfile, "configfile", "github-to-gogs.ini", "config file to use with github-to-gogs section")
|
flag.StringVar(&configfile, "configfile", "github-to-gogs.ini", "config file to use with github-to-gogs section")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -93,15 +94,16 @@ func GetReposFromGitHub(config *Config) ([]GitHubRepo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
respbody, err := GetResponseBody(resp)
|
respbody, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(*respbody, &repopartiallist)
|
err = json.Unmarshal(respbody, &repopartiallist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, elem := range repopartiallist {
|
for _, elem := range repopartiallist {
|
||||||
repofulllist = append(repofulllist, elem)
|
repofulllist = append(repofulllist, elem)
|
||||||
}
|
}
|
||||||
@ -131,15 +133,6 @@ func InvokeGitHub(config *Config, url string) (*http.Response, error) {
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResponseBody converts http responses bodies as bytes slice
|
|
||||||
func GetResponseBody(resp *http.Response) (*[]byte, error) {
|
|
||||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &bodyBytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckGogsExistingRepo checks if there's an existing repository in gogs
|
// CheckGogsExistingRepo checks if there's an existing repository in gogs
|
||||||
func CheckGogsExistingRepo(config *Config, repo GitHubRepo) (bool, error) {
|
func CheckGogsExistingRepo(config *Config, repo GitHubRepo) (bool, error) {
|
||||||
var isexists bool
|
var isexists bool
|
||||||
@ -193,9 +186,9 @@ func (config *Config) GetGogsUserUID() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
respbody, err := GetResponseBody(resp)
|
respbody, err := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
err = json.Unmarshal(*respbody, &gogsorg)
|
err = json.Unmarshal(respbody, &gogsorg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New("Failed to parse user ID from gogs webservice, check auth")
|
err = errors.New("Failed to parse user ID from gogs webservice, check auth")
|
||||||
return err
|
return err
|
||||||
@ -231,7 +224,6 @@ func MigrateReposToGogs(config *Config, wg *sync.WaitGroup, jobs chan GitHubRepo
|
|||||||
elem, more := <-jobs
|
elem, more := <-jobs
|
||||||
if more {
|
if more {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
var resp *http.Response
|
|
||||||
|
|
||||||
existingrepo, err := CheckGogsExistingRepo(config, elem)
|
existingrepo, err := CheckGogsExistingRepo(config, elem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -252,10 +244,12 @@ func MigrateReposToGogs(config *Config, wg *sync.WaitGroup, jobs chan GitHubRepo
|
|||||||
client.Timeout = config.globalconfig.RequestTimeout
|
client.Timeout = config.globalconfig.RequestTimeout
|
||||||
|
|
||||||
fmt.Println(fmt.Sprintf("Migrating repo %s to gogs rest api", elem.Name))
|
fmt.Println(fmt.Sprintf("Migrating repo %s to gogs rest api", elem.Name))
|
||||||
resp, err = client.Do(req)
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 201 {
|
if resp.StatusCode != 201 {
|
||||||
err = fmt.Errorf("Error when migrating repo %s to gogs with status code %d on gogs webservice", elem.Name, resp.StatusCode)
|
err = fmt.Errorf("Error when migrating repo %s to gogs with status code %d on gogs webservice", elem.Name, resp.StatusCode)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user