<commit_before>import { Repository } from '../../../models/repository'
import { IAPIRepository } from '../../api'
import { GitStore } from '../git-store'
import { urlMatchesRemote } from '../../repository-matching'

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.defaultRemote) {
    return
  }
  if (!repository.gitHubRepository) {
    return
  }

  const updatedRemoteUrl = apiRepo.clone_url
  const urlsMatch = urlMatchesRemote(updatedRemoteUrl, gitStore.defaultRemote)

  const remoteUrlUnchanged =
    gitStore.defaultRemote &&
    gitStore.defaultRemote.url === repository.gitHubRepository.cloneURL

  if (remoteUrlUnchanged && !urlsMatch) {
    // Frankenstein the existing remote url to have the updated user/repo path
    const updatedUrl = new URL(gitStore.defaultRemote.url)
    updatedUrl.pathname = new URL(updatedRemoteUrl).pathname
    await gitStore.setRemoteURL(
      gitStore.defaultRemote.name,
      updatedUrl.toString()
    )
  }
}<commit_msg>More robust url check<commit_after>import { Repository } from '../../../models/repository'
import { IAPIRepository } from '../../api'
import { GitStore } from '../git-store'
import { urlMatchesRemote } from '../../repository-matching'

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.defaultRemote) {
    return
  }
  if (!repository.gitHubRepository) {
    return
  }

  const updatedRemoteUrl = apiRepo.clone_url
  const urlsMatch = urlMatchesRemote(updatedRemoteUrl, gitStore.defaultRemote)

  const remoteUrlUnchanged =
    gitStore.defaultRemote &&
    urlMatchesRemote(
      repository.gitHubRepository.cloneURL,
      gitStore.defaultRemote
    )

  if (remoteUrlUnchanged && !urlsMatch) {
    // Frankenstein the existing remote url to have the updated user/repo path
    const updatedUrl = new URL(gitStore.defaultRemote.url)
    updatedUrl.pathname = new URL(updatedRemoteUrl).pathname
    await gitStore.setRemoteURL(
      gitStore.defaultRemote.name,
      updatedUrl.toString()
    )
  }
}
{'fraction_non_alphanumeric': 0.10093230644507499, 'fraction_numerical': 0.0, 'mean_word_length': 3.6566037735849055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '926544', 'n_tokens_mistral': 704, 'n_tokens_neox': 702, 'n_words': 194}