import { Repository } from '../../../models/repository'
import { IAPIRepository } from '../../api'
import { GitStore } from '../git-store'

export async function updateRemoteUrl(
  gitStore: GitStore,
  repository: Repository,
  apiRepo: IAPIRepository
): Promise<void> {
  // I'm not sure when these early exit conditions would be met. But when they are
  // we don't have enough information to continue so exit early!
  if (!gitStore.currentRemote) {
    return
  }
  if (!repository.gitHubRepository) {
    return
  }

  const remoteUrl = gitStore.currentRemote.url
  const updatedRemoteUrl = apiRepo.clone_url
  const isProtocolHttps = remoteUrl && remoteUrl.startsWith('https://')
  const usingDefaultRemote =
    gitStore.defaultRemote &&
    gitStore.defaultRemote.url === repository.gitHubRepository.cloneURL

  if (isProtocolHttps && usingDefaultRemote && remoteUrl !== updatedRemoteUrl) {
    await gitStore.setRemoteURL(gitStore.currentRemote.name, updatedRemoteUrl)
  }
}

import { Repository } from '../../../models/repository'
import { IAPIRepository } from '../../api'
import { GitStore } from '../git-store'

export const updateRemoteUrl = async (
  gitStore: GitStore,
  repository: Repository,
  apiRepo: IAPIRepository
): Promise<void> => {
  // I'm not sure when these early exit conditions would be met. But when they are
  // we don't have enough information to continue so exit early!
  if (!gitStore.currentRemote) {
    return
  }
  if (!repository.gitHubRepository) {
    return
  }

  const remoteUrl = gitStore.currentRemote.url
  const updatedRemoteUrl = apiRepo.clone_url
  const isProtocolHttps = remoteUrl && remoteUrl.startsWith('https://')
  const usingDefaultRemote =
    gitStore.defaultRemote &&
    gitStore.defaultRemote.url === repository.gitHubRepository.cloneURL

  if (isProtocolHttps && usingDefaultRemote && remoteUrl !== updatedRemoteUrl) {
    await gitStore.setRemoteURL(gitStore.currentRemote.name, updatedRemoteUrl)
  }
}

--- 
+++ 
@@ -2,11 +2,11 @@
 import { IAPIRepository } from '../../api'
 import { GitStore } from '../git-store'
 
-export const updateRemoteUrl = async (
+export async function updateRemoteUrl(
   gitStore: GitStore,
   repository: Repository,
   apiRepo: IAPIRepository
-): Promise<void> => {
+): Promise<void> {
   // I'm not sure when these early exit conditions would be met. But when they are
   // we don't have enough information to continue so exit early!
   if (!gitStore.currentRemote) {
Use the export function-style rather than export const

Co-Authored-By: Markus Olsson <c00736d1ddeb2cd1f4e803cdc39630b5b2784893@users.noreply.github.com>
