forked from apache/incubator-devlake
/
commit_collector.go
56 lines (48 loc) · 1.58 KB
/
commit_collector.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
package tasks
import (
"github.com/merico-dev/lake/plugins/core"
"github.com/merico-dev/lake/plugins/helper"
)
const RAW_COMMIT_TABLE = "gitlab_api_commit"
var CollectCommitsMeta = core.SubTaskMeta{
Name: "collectApiCommits",
EntryPoint: CollectApiCommits,
EnabledByDefault: true,
Description: "Collect commit data from gitlab api",
}
type GitlabApiCommit struct {
GitlabId string `json:"id"`
Title string
Message string
ProjectId int
ShortId string `json:"short_id"`
AuthorName string `json:"author_name"`
AuthorEmail string `json:"author_email"`
AuthoredDate core.Iso8601Time `json:"authored_date"`
CommitterName string `json:"committer_name"`
CommitterEmail string `json:"committer_email"`
CommittedDate core.Iso8601Time `json:"committed_date"`
WebUrl string `json:"web_url"`
Stats struct {
Additions int
Deletions int
Total int
}
}
func CollectApiCommits(taskCtx core.SubTaskContext) error {
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_COMMIT_TABLE)
collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
RawDataSubTaskArgs: *rawDataSubTaskArgs,
ApiClient: data.ApiClient,
PageSize: 100,
Incremental: false,
UrlTemplate: "projects/{{ .Params.ProjectId }}/repository/commits",
Query: GetQuery,
Concurrency: 20,
ResponseParser: GetRawMessageFromResponse,
})
if err != nil {
return err
}
return collector.Execute()
}