Github: fix notification levels

This commit is contained in:
Aleksey Pivovarov
2013-06-27 15:05:20 +04:00
parent 9aec51de1d
commit 1b95135e2b
3 changed files with 22 additions and 26 deletions
@@ -26,7 +26,7 @@ import git4idea.Notificator;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.io.IOException;
/**
* @author Aleksey Pivovarov
@@ -51,9 +51,8 @@ public class GithubNotifications {
Notificator.getInstance(project).notify(notification);
}
public static void showError(@NotNull Project project, @NotNull String title, @NotNull IOException e) {
Notification notification =
new Notification(GITHUB_NOTIFICATION_GROUP, title, GithubUtil.getErrorTextFromException(e), NotificationType.ERROR);
public static void showError(@NotNull Project project, @NotNull String title, @NotNull Exception e) {
Notification notification = new Notification(GITHUB_NOTIFICATION_GROUP, title, e.getMessage(), NotificationType.ERROR);
Notificator.getInstance(project).notify(notification);
}
@@ -106,8 +106,8 @@ public class GithubRebaseAction extends DumbAwareAction {
final String login = GithubSettings.getInstance().getLogin();
final int index = pushUrl.lastIndexOf(login);
if (index == -1) {
GithubNotifications.showErrorDialog(project, "Github remote repository doesn't seem to be your own repository: " + pushUrl,
CANNOT_PERFORM_GITHUB_REBASE);
GithubNotifications
.showWarningDialog(project, CANNOT_PERFORM_GITHUB_REBASE, "Github remote repository doesn't seem to be your own repository: " + pushUrl);
return;
}
String repoName = pushUrl.substring(index + login.length() + 1);
@@ -130,14 +130,14 @@ public class GithubRebaseAction extends DumbAwareAction {
}
});
if (repositoryInfoRef.isNull()) {
GithubNotifications.showErrorDialog(project, "Github repository doesn't seem to be your own repository: " + pushUrl,
CANNOT_PERFORM_GITHUB_REBASE);
GithubNotifications
.showWarning(project, CANNOT_PERFORM_GITHUB_REBASE, "Github repository doesn't seem to be your own repository: " + pushUrl);
return;
}
if (!repositoryInfoRef.get().isFork()) {
GithubNotifications
.showErrorDialog(project, CANNOT_PERFORM_GITHUB_REBASE, "Github repository '" + finalRepoName + "' is not a forked one");
.showWarning(project, CANNOT_PERFORM_GITHUB_REBASE, "Github repository '" + finalRepoName + "' is not a forked one");
return;
}
@@ -191,16 +191,16 @@ public class GithubRebaseAction extends DumbAwareAction {
addRemoteHandler.addParameters("add", remoteForForkParentRepo.get(), parentRepoUrl);
addRemoteHandler.run();
if (addRemoteHandler.getExitCode() != 0) {
GithubNotifications
.showErrorDialog(project, CANNOT_PERFORM_GITHUB_REBASE, "Failed to add GitHub remote: '" + parentRepoUrl + "'");
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, "Failed to add GitHub remote: '" + parentRepoUrl + "'");
return;
}
// catch newly added remote
gitRepository.update();
}
catch (VcsException e1) {
final String message = "Error happened during git operation: " + e1.getMessage();
GithubNotifications.showErrorDialog(project, CANNOT_PERFORM_GITHUB_REBASE, message);
catch (VcsException e) {
GithubNotifications.showError(project, CANNOT_PERFORM_GITHUB_REBASE, e);
return;
}
}
@@ -141,9 +141,6 @@ public class GithubShareAction extends DumbAwareAction {
// check access to private repos (network)
final GithubUser userInfo = GithubUtil.getCurrentUserInfo(auth);
if (userInfo == null) {
return;
}
userInfoRef.set(userInfo);
authRef.set(auth);
}
@@ -157,6 +154,7 @@ public class GithubShareAction extends DumbAwareAction {
return;
}
if (repoNamesRef.isNull() || userInfoRef.isNull()) {
GithubNotifications.showErrorDialog(project, "Failed to connect to GitHub", "Failed to gather user information");
return;
}
@@ -184,7 +182,7 @@ public class GithubShareAction extends DumbAwareAction {
LOG.info("Successfully created GitHub repository");
}
else {
GithubNotifications.showErrorDialog(project, "Create GitHub Repository", "Failed to create new GitHub repository");
GithubNotifications.showError(project, "Creating GitHub Repository", "Failed to create new GitHub repository");
return;
}
@@ -213,12 +211,12 @@ public class GithubShareAction extends DumbAwareAction {
repository.update();
if (addRemoteHandler.getExitCode() != 0) {
GithubNotifications
.showErrorDialog(project, "Failed to add GitHub repository as remote", "Failed to add GitHub repository as remote");
.showError(project, "Failed to add GitHub repository as remote", "Failed to add GitHub repository as remote");
return;
}
}
catch (VcsException e) {
GithubNotifications.showErrorDialog(project, "Failed to add GitHub repository as remote", e.getMessage());
GithubNotifications.showError(project, "Failed to add GitHub repository as remote", e.getMessage());
LOG.info("Failed to add GitHub as remote: " + e.getMessage());
return;
}
@@ -246,7 +244,7 @@ public class GithubShareAction extends DumbAwareAction {
}
}.queue();
if (!exceptionRef.isNull()) {
GithubNotifications.showErrorDialog(project, "Failed to create new GitHub repository", exceptionRef.get().getMessage());
GithubNotifications.showError(project, "Failed to create new GitHub repository", exceptionRef.get());
}
}
@@ -273,7 +271,6 @@ public class GithubShareAction extends DumbAwareAction {
LOG.info("No git detected, creating empty git repo");
indicator.setText("Creating empty git repo");
final GitLineHandler h = new GitLineHandler(project, root, GitCommand.INIT);
//GitHandlerUtil.doSynchronously(h, GitBundle.getString("initializing.title"), h.printableCommandLine());
GitHandlerUtil.runInCurrentThread(h, indicator, true, GitBundle.getString("initializing.title"));
if (!h.errors().isEmpty()) {
GitUIUtil.showOperationErrors(project, h.errors(), "git init");
@@ -302,7 +299,7 @@ public class GithubShareAction extends DumbAwareAction {
// get repository
final GitVcs gitVcs = GitVcs.getInstance(project);
if (gitVcs == null){
GithubNotifications.showErrorDialog(project, "Failed to share", "Cannot find git initialized");
GithubNotifications.showError(project, "Failed to perform initial commit", "Cannot find git initialized");
return false;
}
@@ -313,7 +310,7 @@ public class GithubShareAction extends DumbAwareAction {
}
GitRepository repository = repositoryManager.getRepositoryForRoot(root);
if (repository == null) {
GithubNotifications.showErrorDialog(project, "Failed to share", "Cannot find git repository for root " + root);
GithubNotifications.showError(project, "Failed to perform initial commit", "Cannot find git repository for root " + root);
return false;
}
if (!repository.isFresh()) {
@@ -337,7 +334,7 @@ public class GithubShareAction extends DumbAwareAction {
}, indicator.getModalityState());
final Collection<VirtualFile> files2add = dialog.getSelectedFiles();
if (!dialog.isOK() || files2add.isEmpty()) {
GithubNotifications.showErrorDialog(project, "Failed to commit file during post activities", "No files to commit");
GithubNotifications.showWarning(project, "Failed to commit file during post activities", "No files to commit");
return false;
}
GitFileUtils.addFiles(project, root, files2add);
@@ -351,7 +348,7 @@ public class GithubShareAction extends DumbAwareAction {
}
catch (VcsException e) {
LOG.info("Failed to perform initial commit");
GithubNotifications.showErrorDialog(project, "Failed to commit file during post activities", e.getMessage());
GithubNotifications.showError(project, "Failed to commit file during post activities", e.getMessage());
return false;
}
return true;