Merge pull request #11332 from desktop/update-fork-behavior

Update repository after changing fork behavior
This commit is contained in:
Markus Olsson 2021-01-11 11:37:12 +01:00 committed by GitHub
commit 1c488e94f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -0,0 +1,17 @@
/**
* Types which can safely be coerced to strings without losing information.
* As an example `1234.toString()` doesn't lose any information whereas
* `({ foo: bar }).toString()` does (`[Object object]`).
*/
type HashableType = number | string | boolean | undefined | null
/**
* Creates a string representation of the provided arguments.
*
* This is a helper function used to create a string representation of
* an object based on its properties for the purposes of simple equality
* comparisons.
*/
export function createEqualityHash(...items: HashableType[]) {
return items.join('+')
}

View file

@ -1,3 +1,4 @@
import { createEqualityHash } from './equality-hash'
import { Owner } from './owner'
export type GitHubRepositoryPermission = 'read' | 'write' | 'admin' | null
@ -29,7 +30,7 @@ export class GitHubRepository {
public readonly permissions: GitHubRepositoryPermission = null,
public readonly parent: GitHubRepository | null = null
) {
this.hash = [
this.hash = createEqualityHash(
this.name,
this.owner.login,
this.dbID,
@ -40,8 +41,8 @@ export class GitHubRepository {
this.issuesEnabled,
this.isArchived,
this.permissions,
this.parent?.hash,
].join('+')
this.parent?.hash
)
}
public get endpoint(): string {

View file

@ -7,6 +7,7 @@ import {
ForkContributionTarget,
} from './workflow-preferences'
import { assertNever, fatalError } from '../lib/fatal-error'
import { createEqualityHash } from './equality-hash'
function getBaseName(path: string): string {
const baseName = Path.basename(path)
@ -61,14 +62,14 @@ export class Repository {
this.mainWorkTree = { path }
this.name = (gitHubRepository && gitHubRepository.name) || getBaseName(path)
this.hash = [
this.hash = createEqualityHash(
path,
this.id,
gitHubRepository?.hash,
this.missing,
this.workflowPreferences,
this.isTutorialRepository,
].join('+')
this.workflowPreferences.forkContributionTarget,
this.isTutorialRepository
)
}
public get path(): string {