Skip to content

Commit 9d10be1

Browse files
committed
fix: failed to collect data from self-hosting gitlab
1 parent a1a6c55 commit 9d10be1

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

plugins/gitlab/gitlab.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package main // must be main for plugin entry point
22

33
import (
44
"context"
5+
"fmt"
6+
"os"
7+
"strconv"
58

69
"github.com/merico-dev/lake/logger" // A pseudo type for Plugin Interface implementation
710
lakeModels "github.com/merico-dev/lake/models"
@@ -146,3 +149,33 @@ func (plugin Gitlab) ApiResources() map[string]map[string]core.ApiResourceHandle
146149

147150
// Export a variable named PluginEntry for Framework to search and load
148151
var PluginEntry Gitlab //nolint
152+
153+
// standalone mode for debugging
154+
func main() {
155+
args := os.Args[1:]
156+
if len(args) < 1 {
157+
panic(fmt.Errorf("Usage: go run ./plugins/gitlab <project_id>"))
158+
}
159+
projectId, err := strconv.ParseFloat(args[0], 64)
160+
if err != nil {
161+
panic(fmt.Errorf("error paring board_id: %w", err))
162+
}
163+
164+
PluginEntry.Init()
165+
progress := make(chan float32)
166+
go func() {
167+
PluginEntry.Execute(
168+
map[string]interface{}{
169+
"projectId": projectId,
170+
},
171+
progress,
172+
context.Background(),
173+
)
174+
if err != nil {
175+
panic(err)
176+
}
177+
}()
178+
for p := range progress {
179+
fmt.Println(p)
180+
}
181+
}

plugins/gitlab/tasks/gitlab_api_client.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func CreateApiClient() *GitlabApiClient {
3737

3838
type GitlabPaginationHandler func(res *http.Response) error
3939

40-
func getTotal(resourceUriFormat string) (int, int, error) {
40+
func getTotal(resourceUriFormat string) (totalInt int, rateLimitPerSecond int, err error) {
4141
// jsut get the first page of results. The response has a head that tells the total pages
4242
page := 0
4343
page_size := 1
@@ -53,16 +53,19 @@ func getTotal(resourceUriFormat string) (int, int, error) {
5353
return 0, 0, err
5454
}
5555

56-
totalInt := -1
56+
totalInt = -1
5757
total := res.Header.Get("X-Total")
5858
if total != "" {
5959
totalInt, err = convertStringToInt(total)
6060
if err != nil {
6161
return 0, 0, err
6262
}
6363
}
64-
64+
rateLimitPerSecond = 100
6565
rateRemaining := res.Header.Get("ratelimit-remaining")
66+
if rateRemaining == "" {
67+
return
68+
}
6669
date, err := http.ParseTime(res.Header.Get("date"))
6770
if err != nil {
6871
return 0, 0, err
@@ -75,8 +78,8 @@ func getTotal(resourceUriFormat string) (int, int, error) {
7578
if err != nil {
7679
return 0, 0, err
7780
}
78-
rateLimitPerSecond := rateLimitInt / int(rateLimitResetTime.Unix()-date.Unix()) * 9 / 10
79-
return totalInt, rateLimitPerSecond, nil
81+
rateLimitPerSecond = rateLimitInt / int(rateLimitResetTime.Unix()-date.Unix()) * 9 / 10
82+
return
8083
}
8184

8285
func convertStringToInt(input string) (int, error) {

0 commit comments

Comments
 (0)