@@ -17,6 +17,7 @@ import (
1717 "github.com/alexdor/issue-syncer/storer"
1818 "github.com/lmittmann/tint"
1919 "github.com/spf13/cobra"
20+ "golang.org/x/sync/errgroup"
2021)
2122
2223var (
@@ -75,25 +76,43 @@ var rootCmd = &cobra.Command{
7576 cob .SetContext (context .WithValue (cob .Context (), storer .DryRunKey , true ))
7677 }
7778
78- for i := range WordsToLookFor {
79- WordsToLookFor [i ] = strings .ToLower (WordsToLookFor [i ])
80- }
81- comments , err := parser .ParseDirectory (Path , WordsToLookFor , DirsToSkip , UseGitIgnore )
82- if err != nil {
83- return fmt .Errorf ("failed to parse directory: %w" , err )
84- }
79+ var (
80+ comments []parser.Comment
81+ currentIssues map [string ]storer.Issue
82+ )
8583
86- err = storerToUse .Init (cob .Context ())
87- if err != nil {
88- return fmt .Errorf ("failed to create storer: %w" , err )
89- }
84+ ctx := cob .Context ()
85+ g , gctx := errgroup .WithContext (ctx )
86+
87+ g .Go (func () error {
88+ if err := storerToUse .Init (ctx ); err != nil {
89+ return fmt .Errorf ("failed to initialize storer: %w" , err )
90+ }
91+ var err error
92+ currentIssues , err = storerToUse .FetchCurrentOpenIssues (gctx )
93+ if err != nil {
94+ return fmt .Errorf ("failed to fetch current open issues: %w" , err )
95+ }
96+ return nil
97+ })
98+
99+ g .Go (func () error {
100+ for i := range WordsToLookFor {
101+ WordsToLookFor [i ] = strings .ToLower (WordsToLookFor [i ])
102+ }
103+ var err error
104+ comments , err = parser .ParseDirectory (gctx , Path , WordsToLookFor , DirsToSkip , UseGitIgnore )
105+ if err != nil {
106+ return fmt .Errorf ("failed to parse directory: %w" , err )
107+ }
108+ return nil
109+ })
90110
91- currentIssues , err := storerToUse .FetchCurrentOpenIssues (cob .Context ())
92- if err != nil {
93- return fmt .Errorf ("failed to fetch current open issues: %w" , err )
111+ if err := g .Wait (); err != nil {
112+ return err
94113 }
95114
96- return storer .UpdateIssues (cob . Context () , storerToUse , currentIssues , comments )
115+ return storer .UpdateIssues (ctx , storerToUse , currentIssues , comments )
97116 },
98117}
99118
0 commit comments