Skip to content

Commit

Permalink
update. bugfix #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
blacknon committed Apr 14, 2024
1 parent cc3b80b commit 3b47306
Showing 1 changed file with 56 additions and 34 deletions.
90 changes: 56 additions & 34 deletions client/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,50 +82,72 @@ func (g *GitlabClient) Init(u, token string) (err error) {

// List
func (g *GitlabClient) List(isFile, isSecret bool) (snippetList SnippetList, err error) {
// get snippetList
snippetDataList, _, err := g.client.Snippets.ListSnippets(&gitlab.ListSnippetsOptions{})

// gitlab.Snippet to Interface
for _, snippet := range snippetDataList {
if !isSecret {
//
v := getGitlabVisibilityFromString(snippet.Visibility)
switch v {
case GitlabIsPrivate, GitlabIsInternal:
continue
}
}
// set ListProjectsOptions pageSize
const pageSize = 50

// get Description
title := replaceNewline(snippet.Title, "\\n")
opt := gitlab.ListSnippetsOptions(
gitlab.ListOptions{
Page: 0,
PerPage: pageSize,
},
)

data := SnippetListData{
Client: g,
Platform: g.PlatformName,
Id: strconv.Itoa(snippet.ID),
Title: title,
URL: snippet.WebURL,
Visibility: snippet.Visibility,
for {
// get snippetList
snippetDataList, resp, ferr := g.client.Snippets.ListSnippets(&opt)

// check error
if ferr != nil {
return snippetList, ferr
}

// check file flag
if isFile {
if len(snippet.Files) > 1 {
for _, f := range snippet.Files {
fd := data
fd.URL, _ = url.JoinPath(fd.URL, f.Path)
fd.RawURL = f.RawURL
for _, snippet := range snippetDataList {
if !isSecret {
//
v := getGitlabVisibilityFromString(snippet.Visibility)
switch v {
case GitlabIsPrivate, GitlabIsInternal:
continue
}
}

// get Description
title := replaceNewline(snippet.Title, "\\n")

snippetList = append(snippetList, &fd)
data := SnippetListData{
Client: g,
Platform: g.PlatformName,
Id: strconv.Itoa(snippet.ID),
Title: title,
URL: snippet.WebURL,
Visibility: snippet.Visibility,
}

// check file flag
if isFile {
if len(snippet.Files) > 1 {
for _, f := range snippet.Files {
fd := data
fd.URL, _ = url.JoinPath(fd.URL, f.Path)
fd.RawURL = f.RawURL

snippetList = append(snippetList, &fd)
}
} else {
data.URL, _ = url.JoinPath(data.URL, snippet.FileName)
data.RawURL = snippet.RawURL
snippetList = append(snippetList, &data)
}
} else {
data.URL, _ = url.JoinPath(data.URL, snippet.FileName)
data.RawURL = snippet.RawURL
snippetList = append(snippetList, &data)
}
} else {
snippetList = append(snippetList, &data)
}

if resp.NextPage == 0 {
break
}

opt.Page = resp.NextPage
}

return
Expand Down

0 comments on commit 3b47306

Please sign in to comment.