Review feedback: add comments, rename things…

Co-Authored-By: Markus Olsson <634063+niik@users.noreply.github.com>
This commit is contained in:
Sergio Padrino 2021-01-11 11:16:25 +01:00 committed by Markus Olsson
parent 8d211caaff
commit f982fe550f
4 changed files with 25 additions and 13 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,4 +1,4 @@
import { createHash } from './hash'
import { createEqualityHash } from './equality-hash'
import { Owner } from './owner'
export type GitHubRepositoryPermission = 'read' | 'write' | 'admin' | null
@ -30,7 +30,7 @@ export class GitHubRepository {
public readonly permissions: GitHubRepositoryPermission = null,
public readonly parent: GitHubRepository | null = null
) {
this.hash = createHash([
this.hash = createEqualityHash(
this.name,
this.owner.login,
this.dbID,
@ -41,8 +41,8 @@ export class GitHubRepository {
this.issuesEnabled,
this.isArchived,
this.permissions,
this.parent?.hash,
])
this.parent?.hash
)
}
public get endpoint(): string {

View file

@ -1,5 +0,0 @@
type HashableType = number | string | boolean | undefined | null
export function createHash(items: HashableType[]) {
return items.join('+')
}

View file

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