This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
project.go
99 lines (91 loc) · 2.28 KB
/
project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package models
import (
"github.com/astaxie/beego/orm"
"errors"
"github.com/satori/go.uuid"
"os/exec"
"os"
"path"
"path/filepath"
)
type Project struct {
Id int `orm:"pk;auto;unique" json:"id"`
ProjectId string `json:"project_id"` //uuid
Name string `json:"name" form:"name"` //name
Type string `json:"type" form:"type"` //github,gitlab
Url string `json:"url" form:"url"` //仓库地址
Path string `json:"path" form:"path"` //file 地址
Branch string `json:"branch" form:"branch"` //分支
MainPath string `json:"main_path" form:"main_path"` //main 文件地址
SecretToken string `json:"secret_token" form:"secret_token"`
Build []*Build `orm:"reverse(many)" json:"-"`
}
// return id,err
func (obj *Project) Add() (string, error) {
u := uuid.NewV1()
obj.ProjectId = u.String()
o := orm.NewOrm()
qs := o.QueryTable("project")
qs = qs.Filter("name", obj.Name)
if count, err := qs.Count(); count != 0 {
if err == nil {
err = errors.New("Already Exist")
}
return "", err
} else {
_, err := o.Insert(obj)
if err != nil {
return "", err
} else {
return obj.ProjectId, nil
}
}
}
//return id,err
func (obj *Project) Delete() (error) {
o := orm.NewOrm()
_, err := o.Delete(obj)
if err != nil {
return err
} else {
return nil
}
}
//return isSuccess,err
func (obj *Project) Update() (error) {
o := orm.NewOrm()
_, err := o.Update(obj)
if err != nil {
return err
} else {
return nil
}
}
//return obj list,err
func (obj *Project) Get() (error) {
o := orm.NewOrm()
qs := o.QueryTable(obj)
err := qs.One(obj)
if err != nil {
return err
} else {
return nil
}
return nil
}
func GetList(page int, pageSize int) ([]*Project) {
qs := orm.NewOrm().QueryTable("project")
qs = qs.Limit(pageSize, page)
var list []*Project
qs.All(&list)
return list
}
func GetWorkSpacePath(project *Project) (string) {
execFileRelativePath, _ := exec.LookPath(os.Args[0])
execDirRelativePath, _ := path.Split(execFileRelativePath)
execDirAbsPath, _ := filepath.Abs(execDirRelativePath)
if _, err := os.Stat(execDirAbsPath + "/workspace/" + project.Name); os.IsNotExist(err) {
os.Mkdir(execDirAbsPath + "/workspace/" + project.Name, 0766)
}
return execDirAbsPath + "/workspace/" + project.Name
}