PijulPushRecord.kt
/**
* Dracon - An IntelliJ-Pijul integration.
* Copyright 2021 JonathanxD <jhrldev@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.github.jonathanxd.dracon.actions
import com.github.jonathanxd.dracon.dialog.PijulChangesDialog
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.pijul.NonZeroExitStatusCode
import com.github.jonathanxd.dracon.pijul.SuccessStatusCode
import com.github.jonathanxd.dracon.pijul.pijul
import com.intellij.notification.Notification
import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.vcs.ProjectLevelVcsManager
class PijulPushRecord : DumbAwareAction() {
private val PUSH_GROUP =
NotificationGroup.createIdWithTitle("Push Changes", DraconBundle.message("push.notification.group.id"))
override fun actionPerformed(e: AnActionEvent) {
val project = e.project!!
val vcsManager = ProjectLevelVcsManager.getInstance(project)
val root = vcsManager.allVcsRoots.first().path.toNioPath()
val record = pijul(project).pushInTerminal(project, root) {
if(!it.connectAndRetrieveContent()) {
Notifications.Bus.notify(
Notification(
PUSH_GROUP,
DraconBundle.message("editor-server.timeout.title"),
DraconBundle.message("editor-server.timeout.text"),
NotificationType.ERROR,
),
project
)
}
if (it.connected()) {
PijulChangesDialog(project, root, it, it.content(),
DraconBundle.message("action.Pijul.Push.text"),
DraconBundle.message("push.button.text")).showAndGet()
}
}
if (record.statusCode is SuccessStatusCode) {
Notifications.Bus.notify(
Notification(
PUSH_GROUP,
DraconBundle.message("push.notification.title"),
DraconBundle.message("push.notification.success"),
NotificationType.INFORMATION,
),
project
)
} else {
record.statusCode as NonZeroExitStatusCode
Notifications.Bus.notify(
Notification(
PUSH_GROUP,
DraconBundle.message("push.notification.title"),
DraconBundle.message("push.notification.failure", record.statusCode.exitCode, record.statusCode.message),
NotificationType.ERROR,
),
project
)
}
}
}