blob: 84cd39f515385e0683753f1e8a437a57cb00ecbe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package com.getbootstrap.savage.server
import scala.collection.JavaConverters._
import com.getbootstrap.savage.github.{SavageBranch, GitHubActorWithLogging}
import com.getbootstrap.savage.github.util.RichRepositoryId
import com.getbootstrap.savage.util.{SuccessfulExit, ErrorExit, SimpleSubprocess}
class BranchDeleter extends GitHubActorWithLogging {
override def receive = {
case branch:SavageBranch => {
val repoService = new RepositoryService()
gitHubClient.repos.get(settings.TestRepoId).br
val maybeRepoBranch = repoService.getBranches(settings.TestRepoId).asScala.find{ _.getName == branch.branch.name }
maybeRepoBranch match {
case None => log.info(s"Nothing to delete; ${branch} does not exist in ${settings.TestRepoId}")
case Some(repoBranch) => {
val remote = settings.TestRepoId.asPushRemote
val process = SimpleSubprocess(Seq("git", "push", remote, ":" + branch.branch.name))
log.info(s"Deleting ${branch} from remote ${remote}")
process.run() match {
case SuccessfulExit(_) => log.info(s"Successfully deleted ${branch} in ${remote}")
case ErrorExit(exitValue, output) => log.error(s"Error deleting ${branch} in ${remote} :\nExit code: ${exitValue}\n${output}")
}
}
}
}
}
}
|