-
Notifications
You must be signed in to change notification settings - Fork 582
/
softwareComponentApiManager.go
231 lines (198 loc) · 7.04 KB
/
softwareComponentApiManager.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package abaputils
import (
"errors"
"time"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/log"
)
type SoftwareComponentApiManagerInterface interface {
GetAPI(con ConnectionDetailsHTTP, repo Repository) (SoftwareComponentApiInterface, error)
GetPollIntervall() time.Duration
}
type SoftwareComponentApiManager struct {
Client piperhttp.Sender
PollIntervall time.Duration
Force0510 bool
}
func (manager *SoftwareComponentApiManager) GetAPI(con ConnectionDetailsHTTP, repo Repository) (SoftwareComponentApiInterface, error) {
var err0948 error
if !manager.Force0510 {
// Initialize SAP_COM_0948, if it does not work, use SAP_COM_0510
sap_com_0948 := SAP_COM_0948{}
sap_com_0948.init(con, manager.Client, repo)
err0948 = sap_com_0948.initialRequest()
if err0948 == nil {
return &sap_com_0948, nil
}
}
sap_com_0510 := SAP_COM_0510{}
sap_com_0510.init(con, manager.Client, repo)
err0510 := sap_com_0510.initialRequest()
if err0510 == nil {
log.Entry().Infof("SAP_COM_0510 will be replaced by SAP_COM_0948 starting from the SAP BTP, ABAP environment release 2402.")
return &sap_com_0510, nil
}
log.Entry().Errorf("Could not connect via SAP_COM_0948: %s", err0948)
log.Entry().Errorf("Could not connect via SAP_COM_0510: %s", err0510)
return nil, errors.New("Could not initialize API")
}
func (manager *SoftwareComponentApiManager) GetPollIntervall() time.Duration {
if manager.PollIntervall == 0 {
manager.PollIntervall = 5 * time.Second
}
return manager.PollIntervall
}
type SoftwareComponentApiInterface interface {
init(con ConnectionDetailsHTTP, client piperhttp.Sender, repo Repository)
initialRequest() error
setSleepTimeConfig(timeUnit time.Duration, maxSleepTime time.Duration)
getSleepTime(n int) (time.Duration, error)
getUUID() string
GetRepository() (bool, string, error)
Clone() error
Pull() error
CheckoutBranch() error
GetAction() (string, error)
CreateTag(tag Tag) error
GetLogOverview() ([]LogResultsV2, error)
GetLogProtocol(LogResultsV2, int) (result []LogProtocol, count int, err error)
GetExecutionLog() (ExecutionLog, error)
}
/****************************************
* Structs for the A4C_A2G_GHA service *
****************************************/
// ActionEntity struct for the Pull/Import entity A4C_A2G_GHA_SC_IMP
type ActionEntity struct {
Metadata AbapMetadata `json:"__metadata"`
UUID string `json:"uuid"`
Namespace string `json:"namespace"`
ScName string `json:"sc_name"`
ImportType string `json:"import_type"`
BranchName string `json:"branch_name"`
StartedByUser string `json:"user_name"`
Status string `json:"status"`
StatusDescription string `json:"status_descr"`
CommitID string `json:"commit_id"`
StartTime string `json:"start_time"`
ChangeTime string `json:"change_time"`
ToExecutionLog AbapLogs `json:"to_Execution_log"`
ToTransportLog AbapLogs `json:"to_Transport_log"`
ToLogOverview AbapLogsV2 `json:"to_Log_Overview"`
}
// BranchEntity struct for the Branch entity A4C_A2G_GHA_SC_BRANCH
type BranchEntity struct {
Metadata AbapMetadata `json:"__metadata"`
ScName string `json:"sc_name"`
Namespace string `json:"namepsace"`
BranchName string `json:"branch_name"`
ParentBranch string `json:"derived_from"`
CreatedBy string `json:"created_by"`
CreatedOn string `json:"created_on"`
IsActive bool `json:"is_active"`
CommitID string `json:"commit_id"`
CommitMessage string `json:"commit_message"`
LastCommitBy string `json:"last_commit_by"`
LastCommitOn string `json:"last_commit_on"`
}
// CloneEntity struct for the Clone entity A4C_A2G_GHA_SC_CLONE
type CloneEntity struct {
Metadata AbapMetadata `json:"__metadata"`
UUID string `json:"uuid"`
ScName string `json:"sc_name"`
BranchName string `json:"branch_name"`
ImportType string `json:"import_type"`
Namespace string `json:"namepsace"`
Status string `json:"status"`
StatusDescription string `json:"status_descr"`
StartedByUser string `json:"user_name"`
StartTime string `json:"start_time"`
ChangeTime string `json:"change_time"`
}
type RepositoryEntity struct {
Metadata AbapMetadata `json:"__metadata"`
ScName string `json:"sc_name"`
ActiveBranch string `json:"active_branch"`
AvailOnInst bool `json:"avail_on_inst"`
}
// AbapLogs struct for ABAP logs
type AbapLogs struct {
Results []LogResults `json:"results"`
}
type AbapLogsV2 struct {
Results []LogResultsV2 `json:"results"`
}
type LogResultsV2 struct {
Metadata AbapMetadata `json:"__metadata"`
Index int `json:"log_index"`
Name string `json:"log_name"`
Status string `json:"type_of_found_issues"`
Timestamp string `json:"timestamp"`
ToLogProtocol LogProtocolDeferred `json:"to_Log_Protocol"`
}
type ExecutionLog struct {
Value []ExecutionLogValue `json:"value"`
}
type ExecutionLogValue struct {
IndexNo int `json:"index_no"`
Type string `json:"type"`
Descr string `json:"descr"`
Timestamp string `json:"timestamp"`
}
type LogProtocolDeferred struct {
Deferred URI `json:"__deferred"`
}
type URI struct {
URI string `json:"uri"`
}
type LogProtocolResults struct {
Results []LogProtocol `json:"results"`
Count string `json:"__count"`
}
type LogProtocolResultsV4 struct {
Results []LogProtocol `json:"value"`
Count int `json:"@odata.count"`
}
type LogProtocol struct {
// Metadata AbapMetadata `json:"__metadata"`
OverviewIndex int `json:"log_index"`
ProtocolLine int `json:"index_no"`
Type string `json:"type"`
Description string `json:"descr"`
Timestamp string `json:"timestamp"`
}
// LogResults struct for Execution and Transport Log entities A4C_A2G_GHA_SC_LOG_EXE and A4C_A2G_GHA_SC_LOG_TP
type LogResults struct {
Index string `json:"index_no"`
Type string `json:"type"`
Description string `json:"descr"`
Timestamp string `json:"timestamp"`
}
// RepositoriesConfig struct for parsing one or multiple branches and repositories configurations
type RepositoriesConfig struct {
BranchName string
CommitID string
RepositoryName string
RepositoryNames []string
Repositories string
}
type EntitySetsForManageGitRepository struct {
EntitySets []string `json:"EntitySets"`
}
type CreateTagBacklog struct {
RepositoryName string
CommitID string
Tags []Tag
}
type Tag struct {
TagName string
TagDescription string
}
type CreateTagBody struct {
RepositoryName string `json:"sc_name"`
CommitID string `json:"commit_id"`
Tag string `json:"tag_name"`
Description string `json:"tag_description"`
}
type CreateTagResponse struct {
UUID string `json:"uuid"`
}