Skip to content

Commit ecdcc1a

Browse files
author
jguerreiro
committed
feat(exporter): add support for jsonl
1 parent ca6f589 commit ecdcc1a

File tree

6 files changed

+70
-12
lines changed

6 files changed

+70
-12
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
default_stages: [commit]
22
repos:
33
- repo: git://github.com/dnephin/pre-commit-golang
4-
rev: v0.3.5
4+
rev: v0.4.0
55
hooks:
66
- id: go-fmt
77
- id: go-imports
88
- id: golangci-lint
99
- repo: https://github.com/Woile/commitizen
10-
rev: v2.17.4
10+
rev: v2.17.6
1111
hooks:
1212
- id: commitizen
1313
# don't forget to run pre-commit install --hook-type commit-msg for this hook to run
1414
stages: [commit-msg]
1515

1616
- repo: https://github.com/pre-commit/mirrors-prettier # to format JSON, YAML and markdown files among others
17-
rev: v2.2.1
17+
rev: v2.3.0
1818
hooks:
1919
- id: prettier
2020

2121
- repo: https://github.com/gitguardian/gg-shield
22-
rev: v1.4.0
22+
rev: v1.5.0
2323
hooks:
2424
- id: ggshield
2525
language_version: python3

exporter/output.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package exporter
2+
3+
import (
4+
"encoding/json"
5+
"io"
6+
"srcfingerprint"
7+
)
8+
9+
type ExportGitFile struct {
10+
RepositoryName string `json:"repository_name"` // nolint
11+
RepositoryPrivate bool `json:"private"`
12+
srcfingerprint.GitFile
13+
}
14+
15+
type Exporter interface {
16+
AddElement(gitFile *ExportGitFile) error
17+
Close() error
18+
}
19+
20+
type JSONExporter struct {
21+
elements []*ExportGitFile
22+
encoder *json.Encoder
23+
}
24+
25+
func NewJSONExporter(output io.Writer) Exporter {
26+
return &JSONExporter{
27+
elements: []*ExportGitFile{},
28+
encoder: json.NewEncoder(output),
29+
}
30+
}
31+
32+
func (e *JSONExporter) AddElement(gitFile *ExportGitFile) error {
33+
e.elements = append(e.elements, gitFile)
34+
35+
return nil
36+
}
37+
38+
func (e *JSONExporter) Close() error {
39+
return e.encoder.Encode(e.elements)
40+
}
41+
42+
type JSONLExporter struct {
43+
encoder *json.Encoder
44+
}
45+
46+
func NewJSONLExporter(output io.Writer) Exporter {
47+
return &JSONLExporter{
48+
encoder: json.NewEncoder(output),
49+
}
50+
}
51+
52+
func (e *JSONLExporter) AddElement(gitFile *ExportGitFile) error {
53+
return e.encoder.Encode(gitFile)
54+
}
55+
56+
func (e *JSONLExporter) Close() error {
57+
return nil
58+
}

provider/bitbucket.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/suhaibmujahid/go-bitbucket-server/bitbucket"
1515
)
1616

17-
// Provider is capable of gathering Bitbucket server repositories from an org.
17+
// BitbucketProvider is capable of gathering Bitbucket server repositories from an org.
1818
type BitbucketProvider struct {
1919
client *bitbucket.Client
2020
transport *AuthHeaderTransport
@@ -86,7 +86,7 @@ func NewAuthHeaderTransport(T http.RoundTripper, token string) *AuthHeaderTransp
8686
}
8787
}
8888

89-
// NewProvider creates a new Github Provider.
89+
// NewBitbucketProvider creates a new Bitbucket provider.
9090
func NewBitbucketProvider(token string, options Options) Provider {
9191
// BaseURL should be like http://localhost:7990/rest/api/1.0/
9292
if options.BaseURL == "" {

provider/generic_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77
)
88

9-
// Generic Repository Structure.
9+
// Repository Structure. Generic.
1010
type Repository struct {
1111
name string
1212
sshURL string

provider/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
DefaultGithubAPIURL = "https://api.github.com/"
1919
)
2020

21-
// Provider is capable of gathering Github repositories from an org.
21+
// GitHubProvider is capable of gathering Github repositories from an org.
2222
type GitHubProvider struct {
2323
client *github.Client
2424
options Options
@@ -36,7 +36,7 @@ func createFromGithubRepo(r *github.Repository) *Repository {
3636
}
3737
}
3838

39-
// NewProvider creates a new Github Provider.
39+
// NewGitHubProvider creates a new Github Provider.
4040
func NewGitHubProvider(token string, options Options) Provider {
4141
client := github.NewClient(oauth2.NewClient(
4242
context.TODO(),

provider/gitlab.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import (
1212
)
1313

1414
const (
15-
// DefaultGithubAPIURL is the default API URL.
15+
// DefaultGitLabAPIURL is the default API URL.
1616
DefaultGitLabAPIURL = "https://gitlab.com/api/v4"
1717
)
1818

1919
// ErrGroupNotFound is the error returned when group can not be found.
2020
var ErrGroupNotFound = errors.New("group not found")
2121

22-
// Provider represents a Gitlab Provider. It can gather the list of repositories a given user.
22+
// GitLabProvider represents a Gitlab Provider. It can gather the list of repositories a given user.
2323
type GitLabProvider struct {
2424
token string
2525
client *gitlab.Client
2626
options Options
2727
}
2828

29-
// NewProvider creates a Provider given a token.
29+
// NewGitLabProvider creates a Provider given a token.
3030
// If accessing private repositories, token must not be empty.
3131
func NewGitLabProvider(token string, options Options) Provider {
3232
GitLabBaseURL := DefaultGitLabAPIURL

0 commit comments

Comments
 (0)