Skip to content

Commit

Permalink
fix: create branch from upstream default branch (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellbanks authored Feb 20, 2023
1 parent 8eae66e commit 84dc9fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/commands/RemoveVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RemoveVersion : CliktCommand(name = "remove"), KoinComponent {
if (!shouldRemoveManifest) return@runBlocking
echo()
val forkRepository = githubImpl.getWingetPkgsFork(this) ?: return@runBlocking
val ref = githubImpl.createBranchFromDefaultBranch(forkRepository, this) ?: return@runBlocking
val ref = githubImpl.createBranchFromUpstreamDefaultBranch(forkRepository, this) ?: return@runBlocking
val directoryContent: MutableList<GHContent> =
forkRepository.getDirectoryContent(githubImpl.baseGitHubPath, ref.ref)
val progress = progressAnimation {
Expand Down
14 changes: 8 additions & 6 deletions src/main/kotlin/data/GitHubImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ class GitHubImpl : KoinComponent {
}
}

fun createBranchFromDefaultBranch(repository: GHRepository, terminal: Terminal): GHRef? {
suspend fun createBranchFromUpstreamDefaultBranch(repository: GHRepository, terminal: Terminal): GHRef? {
return try {
repository.createRef(
/* name = */ "refs/heads/${getBranchName()}",
/* sha = */ repository.getBranch(repository.defaultBranch).shA1
).also { pullRequestBranch = it }
getMicrosoftWinGetPkgs()?.let { upstreamRepository ->
repository.createRef(
/* name = */ "refs/heads/${getBranchName()}",
/* sha = */ upstreamRepository.getBranch(upstreamRepository.defaultBranch).shA1
).also { pullRequestBranch = it }
}
} catch (ioException: IOException) {
terminal.danger(ioException.message ?: "Failed to create branch.")
null
Expand Down Expand Up @@ -175,7 +177,7 @@ class GitHubImpl : KoinComponent {

private suspend fun commitFiles(files: List<Pair<String, String?>>, terminal: Terminal) {
val repository = getWingetPkgsFork(terminal) ?: return
val branch = createBranchFromDefaultBranch(repository, terminal) ?: return
val branch = createBranchFromUpstreamDefaultBranch(repository, terminal) ?: return
repository.createCommit()
?.message(getCommitTitle())
?.parent(branch.getObject()?.sha)
Expand Down

0 comments on commit 84dc9fd

Please sign in to comment.