fix(be): remove checking of updates from system info endpoint

This commit is contained in:
Denis Gukov 2022-01-20 19:53:48 +05:00
parent 755dca67e2
commit f6b5a39432
6 changed files with 101 additions and 29 deletions

View File

@ -335,16 +335,16 @@ func getSystemInfo(w http.ResponseWriter, r *http.Request) {
return return
} }
updateAvailable, err := util.CheckUpdate() //updateAvailable, err := util.CheckUpdate()
if err != nil { //if err != nil {
helpers.WriteError(w, err) // helpers.WriteError(w, err)
return // return
} //}
body := map[string]interface{}{ body := map[string]interface{}{
"version": util.Version, "version": util.Version,
"update": updateAvailable, //"update": updateAvailable,
"config": map[string]string{ "config": map[string]string{
"dbHost": dbConfig.Hostname, "dbHost": dbConfig.Hostname,
"dbName": dbConfig.DbName, "dbName": dbConfig.DbName,

View File

@ -55,8 +55,7 @@ func (t *task) getRepoPath() string {
} }
func (t *task) validateRepo() error { func (t *task) validateRepo() error {
path := t.getRepoPath() _, err := os.Stat(t.getRepoPath())
_, err := os.Stat(path)
return err return err
} }
@ -503,7 +502,7 @@ func (t *task) getCommitMessage() (res string, err error) {
return return
} }
func (t *task) updateRepository() error { func (t *task) makeGitCommand() *exec.Cmd {
var gitSSHCommand string var gitSSHCommand string
if t.repository.SSHKey.Type == db.AccessKeySSH { if t.repository.SSHKey.Type == db.AccessKeySSH {
gitSSHCommand = t.repository.SSHKey.GetSshCommand() gitSSHCommand = t.repository.SSHKey.GetSshCommand()
@ -513,28 +512,68 @@ func (t *task) updateRepository() error {
cmd.Dir = util.Config.TmpPath cmd.Dir = util.Config.TmpPath
t.setCmdEnvironment(cmd, gitSSHCommand) t.setCmdEnvironment(cmd, gitSSHCommand)
repoURL, repoTag := t.repository.GitURL, "master" return cmd
if split := strings.Split(repoURL, "#"); len(split) > 1 {
repoURL, repoTag = split[0], split[1]
} }
func (t *task) canRepositoryBePulled() bool {
fetchCmd := t.makeGitCommand()
fetchCmd.Args = append(fetchCmd.Args, "fetch")
t.logCmd(fetchCmd)
err := fetchCmd.Run()
if err != nil {
return false
}
checkCmd := t.makeGitCommand()
checkCmd.Args = append(checkCmd.Args, "merge-base", "--is-ancestor", "HEAD", "origin/"+t.repository.GitBranch)
t.logCmd(checkCmd)
err = checkCmd.Run()
return err != nil
}
func (t *task) cloneRepository() error {
cmd := t.makeGitCommand()
t.log("Cloning repository " + t.repository.GitURL)
cmd.Args = append(cmd.Args, "clone", "--recursive", "--branch", t.repository.GitURL, t.repository.GitBranch, t.getRepoName())
t.logCmd(cmd)
return cmd.Run()
}
func (t *task) pullRepository() error {
cmd := t.makeGitCommand()
t.log("Updating repository " + t.repository.GitURL)
cmd.Dir = t.getRepoPath()
cmd.Args = append(cmd.Args, "pull", "origin", t.repository.GitBranch)
t.logCmd(cmd)
return cmd.Run()
}
func (t *task) updateRepository() error {
err := t.validateRepo() err := t.validateRepo()
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
err = os.RemoveAll(t.getRepoPath())
if err != nil {
return err
}
}
return t.cloneRepository()
}
if t.canRepositoryBePulled() {
err = t.pullRepository()
if err == nil {
return nil
}
}
err = os.RemoveAll(t.getRepoPath())
if err != nil {
return err return err
} }
t.log("Cloning repository " + repoURL) return t.cloneRepository()
cmd.Args = append(cmd.Args, "clone", "--recursive", "--branch", repoTag, repoURL, t.getRepoName())
} else {
t.log("Updating repository " + repoURL)
cmd.Dir = t.getRepoPath()
cmd.Args = append(cmd.Args, "pull", "origin", repoTag)
}
t.logCmd(cmd)
return cmd.Run()
} }
func (t *task) installRequirements() error { func (t *task) installRequirements() error {

View File

@ -6,6 +6,7 @@ type Repository struct {
Name string `db:"name" json:"name" binding:"required"` Name string `db:"name" json:"name" binding:"required"`
ProjectID int `db:"project_id" json:"project_id"` ProjectID int `db:"project_id" json:"project_id"`
GitURL string `db:"git_url" json:"git_url" binding:"required"` GitURL string `db:"git_url" json:"git_url" binding:"required"`
GitBranch string `db:"git_branch" json:"git_branch" binding:"required"`
SSHKeyID int `db:"ssh_key_id" json:"ssh_key_id" binding:"required"` SSHKeyID int `db:"ssh_key_id" json:"ssh_key_id" binding:"required"`
Removed bool `db:"removed" json:"removed"` Removed bool `db:"removed" json:"removed"`

View File

@ -5,6 +5,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/go-gorp/gorp/v3" "github.com/go-gorp/gorp/v3"
"regexp" "regexp"
"strings"
"time" "time"
) )
@ -85,6 +86,26 @@ func (d *SqlDb) applyMigration(version *Version) error {
return err return err
} }
switch version.VersionString() {
case "2.8.26":
rows, err2 := d.sql.Query("SELECT id, git_url FROM project__repositories")
if err2 == nil {
defer rows.Close()
for rows.Next() {
var id, url string
if err3 := rows.Scan(&id, &url); err3 != nil {
branch := "master"
if parts := strings.Split(url, "#"); len(parts) > 1 {
url, branch = parts[0], parts[1]
}
_, _ = d.sql.Exec("UPDATE project__repositories "+
"SET git_url = ?, git_branch = ? "+
"WHERE id = ?", url, branch, id)
}
}
}
}
fmt.Println() fmt.Println()
return tx.Commit() return tx.Commit()

View File

@ -0,0 +1 @@
alter table `project__repository` add git_branch varchar(255);

View File

@ -22,7 +22,7 @@
<v-text-field <v-text-field
v-model="item.git_url" v-model="item.git_url"
label="Repository URL" label="URL"
:rules="[v => !!v || 'Repository is required']" :rules="[v => !!v || 'Repository is required']"
required required
:disabled="formSaving" :disabled="formSaving"
@ -30,6 +30,16 @@
@click:append-outer="showHelpDialog('url')" @click:append-outer="showHelpDialog('url')"
></v-text-field> ></v-text-field>
<v-text-field
v-model="item.git_branch"
label="Branch"
:rules="[v => !!v || 'Branch is required']"
required
:disabled="formSaving"
append-outer-icon="mdi-help-circle"
@click:append-outer="showHelpDialog('url')"
></v-text-field>
<v-select <v-select
v-model="item.ssh_key_id" v-model="item.ssh_key_id"
label="Access Key" label="Access Key"