|
|
@@ -1,8 +1,10 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"bufio" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
@@ -494,11 +496,46 @@ func GetRate(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func downloadCode(repo *models.Repository, codePath string) error { |
|
|
|
if err := git.Clone(repo.CloneLink().HTTPS, codePath, git.CloneRepoOptions{}); err != nil { |
|
|
|
if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{}); err != nil { |
|
|
|
log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
configFile, err := os.OpenFile(codePath + "/.git/config", os.O_RDWR, 0666) |
|
|
|
if err != nil { |
|
|
|
log.Error("open file(%s) failed:%v", codePath + "/,git/config", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
defer configFile.Close() |
|
|
|
|
|
|
|
pos := int64(0) |
|
|
|
reader := bufio.NewReader(configFile) |
|
|
|
for { |
|
|
|
line, err := reader.ReadString('\n') |
|
|
|
if err != nil { |
|
|
|
if err == io.EOF { |
|
|
|
log.Error("not find the remote-url") |
|
|
|
return nil |
|
|
|
} else { |
|
|
|
log.Error("read error: %v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if strings.Contains(line, "url") && strings.Contains(line, ".git"){ |
|
|
|
bytes := []byte("\turl = " + repo.CloneLink().HTTPS + "\n") |
|
|
|
_, err := configFile.WriteAt(bytes, pos) |
|
|
|
if err != nil { |
|
|
|
log.Error("WriteAt failed:%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
pos += int64(len(line)) |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|