Skip to content

Commit 0154803

Browse files
authored
feat: add dry run + fix searchQueryIssues
1 parent 7729e40 commit 0154803

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

cmd/run/command.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
const (
1010
flagLogLevel = "log-level"
1111
flagGitHubToken = "github-token"
12+
flagDryRun = "dry-run"
1213
flagPluginURL = "plugin-url"
1314
flagGithubSearchQueries = "github-search-queries"
1415
flagGithubSearchQueriesIssues = "github-search-queries-issues"
@@ -41,6 +42,12 @@ func Command() *cli.Command {
4142
EnvVars: []string{strcase.ToSNAKE(flagGitHubToken)},
4243
Required: true,
4344
},
45+
&cli.BoolFlag{
46+
Name: flagDryRun,
47+
Usage: "Dry run mode.",
48+
EnvVars: []string{strcase.ToSNAKE(flagDryRun)},
49+
Value: true,
50+
},
4451
&cli.StringFlag{
4552
Name: flagPluginURL,
4653
Usage: "Plugin Service URL",

cmd/run/config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ type Config struct {
1010
GithubToken string
1111
PluginURL string
1212

13+
DryRun bool
14+
1315
GithubSearchQueries []string
1416
GithubSearchQueriesIssues []string
1517

@@ -20,8 +22,9 @@ func buildConfig(cliCtx *cli.Context) Config {
2022
return Config{
2123
GithubToken: cliCtx.String(flagGitHubToken),
2224
PluginURL: cliCtx.String(flagPluginURL),
25+
DryRun: cliCtx.Bool(flagDryRun),
2326
GithubSearchQueries: cliCtx.StringSlice(flagGithubSearchQueries),
24-
GithubSearchQueriesIssues: cliCtx.StringSlice(flagGithubSearchQueries),
27+
GithubSearchQueriesIssues: cliCtx.StringSlice(flagGithubSearchQueriesIssues),
2528
Tracing: tracer.Config{
2629
Address: cliCtx.String(flagTracingAddress),
2730
Insecure: cliCtx.Bool(flagTracingInsecure),

cmd/run/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func run(ctx context.Context, cfg Config) error {
3434
srcs = &sources.GoProxy{Client: gpClient}
3535
}
3636

37-
scrapper := core.NewScrapper(ghClient, gpClient, pgClient, srcs, tTracer, cfg.GithubSearchQueries, cfg.GithubSearchQueriesIssues)
37+
scrapper := core.NewScrapper(ghClient, gpClient, pgClient, cfg.DryRun, srcs, tTracer, cfg.GithubSearchQueries, cfg.GithubSearchQueriesIssues)
3838

3939
return scrapper.Run(ctx)
4040
}

pkg/core/scrapper.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ type Scrapper struct {
6666
gp *goproxy.Client
6767
pg pluginClient
6868

69+
dryRun bool
70+
6971
searchQueries []string
7072
searchQueriesIssues []string
7173

@@ -76,12 +78,14 @@ type Scrapper struct {
7678
}
7779

7880
// NewScrapper creates a new Scrapper instance.
79-
func NewScrapper(gh *github.Client, gp *goproxy.Client, pgClient pluginClient, sources Sources, tracer trace.Tracer, searchQueries, searchQueriesIssues []string) *Scrapper {
81+
func NewScrapper(gh *github.Client, gp *goproxy.Client, pgClient pluginClient, dryRun bool, sources Sources, tracer trace.Tracer, searchQueries, searchQueriesIssues []string) *Scrapper {
8082
return &Scrapper{
8183
gh: gh,
8284
gp: gp,
8385
pg: pgClient,
8486

87+
dryRun: dryRun,
88+
8589
searchQueries: searchQueries,
8690
searchQueriesIssues: searchQueriesIssues,
8791

@@ -141,6 +145,13 @@ func (s *Scrapper) Run(ctx context.Context) error {
141145
Title: github.String(issueTitle),
142146
Body: github.String(safeIssueBody(err)),
143147
}
148+
149+
if s.dryRun {
150+
logger.Info().Msg("Dry run, not creating the issue")
151+
logger.Debug().Interface("issue", issue).Send()
152+
continue
153+
}
154+
144155
_, _, err = s.gh.Issues.Create(ctx, repository.GetOwner().GetLogin(), repository.GetName(), issue)
145156
if err != nil {
146157
span.RecordError(err)
@@ -150,6 +161,12 @@ func (s *Scrapper) Run(ctx context.Context) error {
150161
continue
151162
}
152163

164+
if s.dryRun {
165+
logger.Info().Msg("Dry run, not storing the plugin")
166+
logger.Debug().Interface("data", data).Send()
167+
continue
168+
}
169+
153170
err = s.store(logger.WithContext(ctx), data)
154171
if err != nil {
155172
span.RecordError(err)

pkg/core/scrapper_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestScrapper_store(t *testing.T) {
162162
t.Run(test.desc, func(t *testing.T) {
163163
t.Parallel()
164164

165-
scrapper := NewScrapper(nil, nil, test.pgClient, nil, noop.NewTracerProvider().Tracer("test"), nil, nil)
165+
scrapper := NewScrapper(nil, nil, test.pgClient, true, nil, noop.NewTracerProvider().Tracer("test"), nil, nil)
166166

167167
data := &plugin.Plugin{Name: "test"}
168168
err := scrapper.store(context.Background(), data)
@@ -334,7 +334,7 @@ func TestScrapper_process(t *testing.T) {
334334
gpClient := goproxy.NewClient("")
335335
srcs := &sources.GitHub{Client: ghClient}
336336

337-
scrapper := NewScrapper(ghClient, gpClient, pgClient, srcs, noop.NewTracerProvider().Tracer("test"), []string{"topic:traefik-plugin language:Go archived:false is:public"}, []string{"is:open is:issue is:public author:traefiker"})
337+
scrapper := NewScrapper(ghClient, gpClient, pgClient, true, srcs, noop.NewTracerProvider().Tracer("test"), []string{"topic:traefik-plugin language:Go archived:false is:public"}, []string{"is:open is:issue is:public author:traefiker"})
338338

339339
repository, _, err := ghClient.Repositories.Get(ctx, owner, repo)
340340
require.NoError(t, err)
@@ -359,7 +359,7 @@ func TestScrapper_process_all(t *testing.T) {
359359
gpClient := goproxy.NewClient("")
360360
srcs := &sources.GitHub{Client: ghClient}
361361

362-
scrapper := NewScrapper(ghClient, gpClient, pgClient, srcs, noop.NewTracerProvider().Tracer("test"), []string{"topic:traefik-plugin language:Go archived:false is:public"}, []string{"is:open is:issue is:public author:traefiker"})
362+
scrapper := NewScrapper(ghClient, gpClient, pgClient, true, srcs, noop.NewTracerProvider().Tracer("test"), []string{"topic:traefik-plugin language:Go archived:false is:public"}, []string{"is:open is:issue is:public author:traefiker"})
363363

364364
reposWithExistingIssue, err := scrapper.searchReposWithExistingIssue(ctx)
365365
require.NoError(t, err)

0 commit comments

Comments
 (0)