Skip to content

Every repository gets adopted - #2903

Merged
niik merged 41 commits into
masterfrom
forks-make-everything-complicated
Oct 11, 2017
Merged

niik merged 41 commits into
masterfrom
forks-make-everything-complicated

Conversation

@joshaber

@joshaber joshaber commented Sep 28, 2017 •

Copy link
Copy Markdown
Contributor

In support of #2364.

Save GitHub repository parents, so that we can later use them to add the upstream remote.

This is a pretty big refactoring of the repositories store, along with a change to how we change (ha!) our models.

Since the Beginning of Time, our models have been immutable. When we wanted to change a property, we'd call a with* method which would return a new copy of the model with the changed property. Then we'd pass the changed object to a store method which would update the database, etc.

This was less than ideal for a few reasons. It meant changes took two steps: (1) change the object, (2) pass the changed object to the store. It also got confusing as to which was the source of truth: the model object we changed in memory, or the model object we get from the store? It was easy to accidentally change a model in memory without updating the store, or update the store but not used the updated model.

This PR changes it so that stores are entirely in charge of changes. Their change methods return the updated object. Models should, generally speaking, originate from stores.

/cc @desktop/core

@joshaber joshaber changed the title Forks make everything complicated Refactor RepositoriesStore Sep 29, 2017
@joshaber joshaber changed the title Refactor RepositoriesStore Every repository gets adopted Sep 29, 2017
@joshaber joshaber added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 29, 2017
@joshaber

Copy link
Copy Markdown
Contributor Author

This is ready 🙏

@niik niik self-assigned this Oct 2, 2017

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. A few questions and requests for documentation.

return table.toCollection().each(repo => {
const key = `${repo.ownerID}+${repo.name}`
if (seenKeys.has(key)) {
table.delete(repo.id!)

This comment was marked as spam.

})
}

private conditionalVersion(

This comment was marked as spam.

public owners: Dexie.Table<IDatabaseOwner, number>

public constructor(name: string) {
public constructor(name: string, requestedVersion?: number) {

This comment was marked as spam.

import { getHTMLURL } from './api'
import { parseRemote } from './remote-parsing'

export interface IMatchedGitHubRepository {

This comment was marked as spam.

readonly htmlURL: string | null
readonly defaultBranch: string | null
readonly cloneURL: string | null
readonly parentID: number | null

This comment was marked as spam.

const existingOwner = await this.db.owners
.where('[endpoint+login]')
.equals([endpoint, login])
.limit(1)

This comment was marked as spam.

return `${this.owner.login}/${this.name}`
}

public get fork(): boolean {

This comment was marked as spam.

const login = gitHubRepository.owner.login.toLowerCase()
const owner = await this.putOwner(endpoint, login)

const existingRepo = await this.db.gitHubRepositories

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@joshaber

joshaber commented Oct 9, 2017

Copy link
Copy Markdown
Contributor Author

🍯

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely!

const login = gitHubRepository.owner.login.toLowerCase()
const owner = await this.putOwner(endpoint, login)

const existingRepo = await this.db.gitHubRepositories

This comment was marked as spam.

@niik
niik merged commit 4a012b3 into master Oct 11, 2017
@niik
niik deleted the forks-make-everything-complicated branch October 11, 2017 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants