Kiln » gitkiln Read More
Clone URL:  
api.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 kiln import ( "encoding/json" "fmt" "strings" ) // Represents the error JSON returned by Kiln API requests type KilnError struct { // Guaranteed-unique code for Kiln errors Code string `json:"codeError"` // Human-readable description Description string `json:"sError"` } // Represents the project JSON returned from the Kiln API type KilnProject struct { Id int64 `json:"ixProject"` Slug string `json:"sSlug"` Name string `json:"sName"` Description string `json:"sDescription"` DefaultPermission string `json:"permissionDefault"` RepoGroups []KilnRepoGroup } type KilnRepoGroup struct { Id int64 `json:"ixRepoGroup"` ProjectId int64 `json:"ixProject"` Slug string `json:"sSlug"` Name string `json:"sName"` Repos []KilnRepo `json:"repos"` } type KilnRepo struct { Id int64 `json:"ixRepo"` RepoGroupId int64 `json:"ixRepoGroup"` ParentId int64 `json:"ixParent"` IsCentral bool `json:"fCentral"` Slug string `json:"sSlug"` GroupSlug string `json:"sGroupSlug"` ProjectSlug string `json:"sProjectSlug"` GitUrl string `json:"sGitUrl"` GitSshUrl string `json:"sGitSshUrl"` Name string `json:"sName"` Description string `json:"sDescription"` Status string `json:"sStatus"` Size int64 `json:"bytesSize"` Vcs int `json:"vcs"` Creator KilnPerson `json:"personCreator"` DefaultPermission string `json:"permissionDefault"` Branches []KilnRepo `json:"repoBranches"` } type KilnPerson struct { Id int64 `json:"ixPerson"` Name string `json:"sName"` Email string `json:"sEmail"` } func (k *KilnClient) Projects() (projects []KilnProject, err error) { if resp, err := k.apiGet("Project", apiParams{}); err == nil { err = json.Unmarshal(resp, &projects) } return } func (k *KilnClient) IdForRepo(repoPath string) (repoId int64, err error) { parts := strings.Split(repoPath, "/") if len(parts) != 3 { err = fmt.Errorf("unknown repository target: %v", repoPath) return } var projects []KilnProject if projects, err = k.Projects(); err == nil { for _, project := range projects { for _, repoGroup := range project.RepoGroups { for _, repo := range repoGroup.Repos { if strings.EqualFold(repo.ProjectSlug, parts[0]) && strings.EqualFold(repo.GroupSlug, parts[1]) && strings.EqualFold(repo.Slug, parts[2]) { repoId = repo.Id return } } } } } err = fmt.Errorf("repository not found") return } func (k *KilnClient) RelatedRepos(repoId int64) (repos []KilnRepo, err error) { resp, err := k.apiGet(fmt.Sprintf("Repo/%v/Related", repoId), apiParams{}) if err == nil { err = json.Unmarshal(resp, &repos) } return }