11package org .ck .githubsecurityscanalerts .action ;
22
3+ import com .intellij .ide .passwordSafe .PasswordSafe ;
4+ import com .intellij .notification .NotificationGroupManager ;
5+ import com .intellij .notification .NotificationType ;
36import com .intellij .openapi .actionSystem .ActionUpdateThread ;
47import com .intellij .openapi .actionSystem .AnActionEvent ;
8+ import com .intellij .openapi .application .ApplicationManager ;
59import com .intellij .openapi .diagnostic .Logger ;
610import com .intellij .openapi .project .DumbAwareAction ;
711import com .intellij .openapi .wm .ToolWindow ;
1317import org .ck .githubsecurityscanalerts .store .alerts .AlertsStore ;
1418import org .ck .githubsecurityscanalerts .store .settings .ProjectSettings ;
1519import org .ck .githubsecurityscanalerts .store .settings .ProjectSettingsStore ;
20+ import org .ck .githubsecurityscanalerts .store .settings .StoreUtil ;
1621import org .ck .githubsecurityscanalerts .ui .tool .AlertsPanel ;
1722import org .jetbrains .annotations .NotNull ;
1823
@@ -31,40 +36,57 @@ public void update(AnActionEvent e) {
3136 .setEnabled (
3237 !state .getGithubRepo ().isEmpty ()
3338 && !state .getGithubOwner ().isEmpty ()
34- && !state .getGithubToken ().isEmpty ());
39+ && PasswordSafe .getInstance ()
40+ .getPassword (StoreUtil .getTokenAttributes (e .getProject ()))
41+ != null );
3542 }
3643
3744 @ Override
3845 public void actionPerformed (AnActionEvent e ) {
39- final ProjectSettings state = e .getProject ().getService (ProjectSettingsStore .class ).getState ();
40- final Alerts savedAlerts = e .getProject ().getService (AlertsStore .class ).getState ();
41-
42- Set <Alert > alerts =
43- new GithubClient (state .getGithubToken ())
44- .fetchAlerts (state .getGithubOwner (), state .getGithubRepo ());
45-
46- LOGGER .warn ("fetched %d alerts" .formatted (alerts .size ()));
47-
48- savedAlerts .setAlerts (
49- alerts .stream ()
50- .map (
51- alert ->
52- new org .ck .githubsecurityscanalerts .store .alerts .Alert (
53- alert .rule ().id (),
54- getRuleName (alert ),
55- alert .most_recent_instance ().location ().path (),
56- alert .most_recent_instance ().location ().start_line (),
57- alert .most_recent_instance ().location ().start_column ()))
58- .toList ());
59-
60- ToolWindowManager toolWindowManager = ToolWindowManager .getInstance (e .getProject ());
61- ToolWindow gitHubSecurityAlerts =
62- toolWindowManager .getToolWindow ("GitHub Security Scan Alerts" );
63- for (Content content : gitHubSecurityAlerts .getContentManager ().getContents ()) {
64- if (content .getComponent () instanceof AlertsPanel alertsPanel ) {
65- alertsPanel .init ();
66- }
67- }
46+ ApplicationManager .getApplication ()
47+ .executeOnPooledThread (
48+ () -> {
49+ final ProjectSettings state =
50+ e .getProject ().getService (ProjectSettingsStore .class ).getState ();
51+ final Alerts savedAlerts = e .getProject ().getService (AlertsStore .class ).getState ();
52+
53+ Set <Alert > alerts =
54+ new GithubClient (
55+ PasswordSafe .getInstance ()
56+ .getPassword (StoreUtil .getTokenAttributes (e .getProject ())))
57+ .fetchAlerts (state .getGithubOwner (), state .getGithubRepo ());
58+
59+ LOGGER .warn ("fetched %d alerts" .formatted (alerts .size ()));
60+
61+ savedAlerts .setAlerts (
62+ alerts .stream ()
63+ .map (
64+ alert ->
65+ new org .ck .githubsecurityscanalerts .store .alerts .Alert (
66+ alert .rule ().id (),
67+ getRuleName (alert ),
68+ alert .most_recent_instance ().location ().path (),
69+ alert .most_recent_instance ().location ().start_line (),
70+ alert .most_recent_instance ().location ().start_column ()))
71+ .toList ());
72+
73+ NotificationGroupManager .getInstance ()
74+ .getNotificationGroup ("GitHub Security Scan Alerts" )
75+ .createNotification (
76+ "Downloaded %d alerts" .formatted (savedAlerts .getAlerts ().size ()),
77+ NotificationType .INFORMATION )
78+ .setImportant (true )
79+ .notify (e .getProject ());
80+
81+ ToolWindowManager toolWindowManager = ToolWindowManager .getInstance (e .getProject ());
82+ ToolWindow gitHubSecurityAlerts =
83+ toolWindowManager .getToolWindow ("GitHub Security Scan Alerts" );
84+ for (Content content : gitHubSecurityAlerts .getContentManager ().getContents ()) {
85+ if (content .getComponent () instanceof AlertsPanel alertsPanel ) {
86+ alertsPanel .init ();
87+ }
88+ }
89+ });
6890 }
6991
7092 @ Override
0 commit comments