@@ -18,35 +18,34 @@ var removed int = 0
1818func main () {
1919 parseCmdFlags ()
2020 cfg , err := GetConfig (configPath )
21- if err != nil {
22- fmt .Printf ("Could not parse configuration yaml: %v\n " , err )
23- os .Exit (1 )
24- }
21+ handleError (err , "[ERR] Could not parse configuration yaml\n " , true )
2522
2623 client := getGithubClient (cfg )
2724
2825 var wg sync.WaitGroup
2926
30- issues , _ , _ := client .Issues .ListByRepo (context .Background (), cfg .Repo .Owner , cfg .Repo .Name , nil )
27+ issues , _ , err := client .Issues .ListByRepo (context .Background (), cfg .Repo .Owner , cfg .Repo .Name , nil )
28+ handleError (err , "[ERR] Could not connect to GitHub API, check API token?\n " , true )
29+
3130 wg .Add (len (issues ))
3231
3332 for _ , issue := range issues {
3433 go deleteIssueReactions (& wg , client , cfg , * issue .Number )
3534 }
3635 wg .Wait ()
37- fmt .Printf ("Successfully removed %d issue reactions from repo %v\n " , removed , cfg .Repo )
36+ fmt .Printf ("Removed %d issue reactions from repo %v\n " , removed , cfg .Repo )
3837}
3938
4039func deleteIssueReactions (wg * sync.WaitGroup , client * github.Client , cfg * Config , issueNumber int ) {
4140 defer wg .Done ()
4241 ctx := context .Background ()
43- reactions , _ , _ := client .Reactions .ListIssueReactions (ctx , cfg .Repo .Owner , cfg .Repo .Name , issueNumber , nil )
42+ reactions , _ , err := client .Reactions .ListIssueReactions (ctx , cfg .Repo .Owner , cfg .Repo .Name , issueNumber , nil )
43+ handleError (err , fmt .Sprintf ("[WARN] Could not list reactions for issue %d" , issueNumber ), false )
4444 for _ , reaction := range reactions {
4545 if * reaction .User .Login == cfg .Auth .Login {
4646 _ , err := client .Reactions .DeleteIssueReaction (ctx , cfg .Repo .Owner , cfg .Repo .Name , issueNumber , * reaction .ID )
4747 if err != nil {
48- fmt .Println ("[ERR] Could not delete reaction " , reaction )
49- fmt .Println (err )
48+ fmt .Fprintf (os .Stderr , "[WARN] Could not delete reaction %v\n error:\n %v" , reaction , err )
5049 } else {
5150 removed ++
5251 }
@@ -72,3 +71,13 @@ func getGithubClient(cfg *Config) *github.Client {
7271 tc := oauth2 .NewClient (ctx , ts )
7372 return github .NewClient (tc )
7473}
74+
75+ func handleError (err error , msg string , fatal bool ) {
76+ if err != nil {
77+ fmt .Fprintf (os .Stderr , msg )
78+ fmt .Fprintf (os .Stderr , "%v\n " , err )
79+ if fatal {
80+ os .Exit (1 )
81+ }
82+ }
83+ }
0 commit comments