Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nmaas Janitor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nmaas
nmaas Janitor
Commits
a87e1ebc
Commit
a87e1ebc
authored
6 years ago
by
Michał Bień
Browse files
Options
Downloads
Patches
Plain Diff
Finished nmaas-janitor
parent
d8be9254
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/service/v1/config-service.go
+16
-5
16 additions, 5 deletions
pkg/service/v1/config-service.go
with
16 additions
and
5 deletions
pkg/service/v1/config-service.go
+
16
−
5
View file @
a87e1ebc
...
...
@@ -80,6 +80,7 @@ func (s *configServiceServer) PrepareDataJsonFromRepository(api *gitlab.Client,
//List files
tree
,
_
,
err
:=
s
.
gitAPI
.
Repositories
.
ListTree
(
repoId
,
nil
)
if
err
!=
nil
||
len
(
tree
)
==
0
{
log
.
Print
(
err
)
return
nil
,
status
.
Errorf
(
codes
.
NotFound
,
"Cannot find any config files"
)
}
...
...
@@ -97,9 +98,10 @@ func (s *configServiceServer) PrepareDataJsonFromRepository(api *gitlab.Client,
if
file
.
Type
!=
"blob"
{
continue
}
data
,
_
,
err
:=
s
.
gitAPI
.
Repositor
ies
.
RawBlobContent
(
repoId
,
file
.
ID
)
opt
:=
&
gitlab
.
GetRawFileOptions
{
Ref
:
gitlab
.
String
(
"master"
)}
data
,
_
,
err
:=
s
.
gitAPI
.
Repositor
yFiles
.
GetRawFile
(
repoId
,
file
.
Name
,
opt
)
if
err
!=
nil
{
log
.
Print
(
err
)
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"Error while reading file from Gitlab!"
)
}
...
...
@@ -119,21 +121,30 @@ func (s *configServiceServer) PrepareDataJsonFromRepository(api *gitlab.Client,
//Parse repository files into string:string map for configmap creator
func
(
s
*
configServiceServer
)
PrepareDataMapFromRepository
(
api
*
gitlab
.
Client
,
repoId
int
)
(
map
[
string
][]
byte
,
error
)
{
compiledMap
:=
make
(
map
[
string
][]
byte
)
//List files
tree
,
_
,
err
:=
s
.
gitAPI
.
Repositories
.
ListTree
(
repoId
,
nil
)
if
err
!=
nil
||
len
(
tree
)
==
0
{
if
err
!=
nil
{
log
.
Print
(
err
)
return
nil
,
status
.
Errorf
(
codes
.
NotFound
,
"Cannot find any config files"
)
}
if
len
(
tree
)
==
0
{
log
.
Printf
(
"There are no files to config in repo %d"
,
repoId
)
return
compiledMap
,
nil
}
//Start parsing
compiledMap
:=
make
(
map
[
string
][]
byte
)
for
_
,
file
:=
range
tree
{
if
file
.
Type
!=
"blob"
{
continue
}
data
,
_
,
err
:=
s
.
gitAPI
.
RepositoryFiles
.
GetRawFile
(
repoId
,
file
.
Name
,
nil
)
opt
:=
&
gitlab
.
GetRawFileOptions
{
Ref
:
gitlab
.
String
(
"master"
)}
data
,
_
,
err
:=
s
.
gitAPI
.
RepositoryFiles
.
GetRawFile
(
repoId
,
file
.
Name
,
opt
)
if
err
!=
nil
{
log
.
Print
(
err
)
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"Error while reading file from Gitlab!"
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment