-
Notifications
You must be signed in to change notification settings - Fork 0
/
importextensions.go
67 lines (58 loc) · 1.48 KB
/
importextensions.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
package main
// Import is the data that is required by the import endpoint.
type Import struct {
// used in refresh only
TokenID uint `json:"tokenId" example:"0"`
Token string `json:"token" example:"sample token"`
User string `json:"user" example:"sample user name"`
URL string `json:"url" example:"https://gitlab.local"`
UploadURL string `json:"uploadUrl" example:""`
// used in refresh only
ProviderID uint `json:"providerId" example:"0"`
// used in refresh only
ProjectID uint `json:"projectId" example:"0"`
Project string `json:"project" example:"sample project name"`
Group string `json:"group" example:"default"`
}
type operationType int
const (
getOperation operationType = iota
putOperation
invalidOperation
)
type entity int
const (
tokenEntity entity = iota
projectEntity
)
type importType int
const (
importProject importType = iota
importGroup
importAllGroups
invalidImport
)
func (i Import) getOperationType(entity entity) operationType {
if entity == tokenEntity {
if i.TokenID == 0 {
return putOperation
}
return getOperation
} else if entity == projectEntity {
if i.ProjectID == 0 {
return putOperation
}
return getOperation
}
return invalidOperation
}
func (i Import) whatToImport() importType {
if i.Project != "" && i.Group != "" {
return importProject
} else if i.Project == "" && i.Group != "" {
return importGroup
} else if i.Project == "" && i.Group == "" {
return importAllGroups
}
return invalidImport
}