-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow creating an alias for repositories #12000
Changes from all commits
ec079ef
af875e1
f8ca091
09102b6
7a83268
318db91
62b3da8
b8eb98d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import { WorkflowPreferences } from '../../models/workflow-preferences' | |
import { clearTagsToPush } from './helpers/tags-to-push-storage' | ||
import { IMatchedGitHubRepository } from '../repository-matching' | ||
import { shallowEquals } from '../equality' | ||
import { enableRepositoryAliases } from '../feature-flag' | ||
|
||
/** The store for local repositories. */ | ||
export class RepositoriesStore extends TypedBaseStore< | ||
|
@@ -132,6 +133,7 @@ export class RepositoriesStore extends TypedBaseStore< | |
? await this.findGitHubRepositoryByID(repo.gitHubRepositoryID) | ||
: await Promise.resolve(null), // Dexie gets confused if we return null | ||
repo.missing, | ||
enableRepositoryAliases() ? repo.alias : null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents the alias from being loaded from persistence, so we can forget about checking the feature flag in many other places 😅 |
||
repo.workflowPreferences, | ||
repo.isTutorialRepository | ||
) | ||
|
@@ -194,6 +196,7 @@ export class RepositoriesStore extends TypedBaseStore< | |
return await this.db.repositories.put({ | ||
...(existingRepo?.id !== undefined && { id: existingRepo.id }), | ||
path, | ||
alias: null, | ||
gitHubRepositoryID: ghRepo.dbID, | ||
missing: false, | ||
lastStashCheckDate: null, | ||
|
@@ -228,6 +231,7 @@ export class RepositoriesStore extends TypedBaseStore< | |
gitHubRepositoryID: null, | ||
missing: false, | ||
lastStashCheckDate: null, | ||
alias: null, | ||
} | ||
const id = await this.db.repositories.add(dbRepo) | ||
return this.toRepository({ id, ...dbRepo }) | ||
|
@@ -261,11 +265,27 @@ export class RepositoriesStore extends TypedBaseStore< | |
repository.id, | ||
repository.gitHubRepository, | ||
missing, | ||
repository.alias, | ||
repository.workflowPreferences, | ||
repository.isTutorialRepository | ||
) | ||
} | ||
|
||
/** | ||
* Update the alias for the specified repository. | ||
* | ||
* @param repository The repository to update. | ||
* @param alias The new alias to use. | ||
*/ | ||
public async updateRepositoryAlias( | ||
repository: Repository, | ||
alias: string | null | ||
): Promise<void> { | ||
await this.db.repositories.update(repository.id, { alias }) | ||
|
||
this.emitUpdatedRepositories() | ||
} | ||
|
||
/** | ||
* Update the workflow preferences for the specified repository. | ||
* | ||
|
@@ -295,6 +315,7 @@ export class RepositoriesStore extends TypedBaseStore< | |
repository.id, | ||
repository.gitHubRepository, | ||
false, | ||
repository.alias, | ||
repository.workflowPreferences, | ||
repository.isTutorialRepository | ||
) | ||
|
@@ -421,6 +442,7 @@ export class RepositoriesStore extends TypedBaseStore< | |
repo.id, | ||
ghRepo, | ||
repo.missing, | ||
repo.alias, | ||
repo.workflowPreferences, | ||
repo.isTutorialRepository | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,7 @@ import { CherryPickCommit } from './drag-elements/cherry-pick-commit' | |
import classNames from 'classnames' | ||
import { dragAndDropManager } from '../lib/drag-and-drop-manager' | ||
import { MoveToApplicationsFolder } from './move-to-applications-folder' | ||
import { ChangeRepositoryAlias } from './change-repository-alias/change-repository-alias-dialog' | ||
|
||
const MinuteInMilliseconds = 1000 * 60 | ||
const HourInMilliseconds = MinuteInMilliseconds * 60 | ||
|
@@ -2048,6 +2049,15 @@ export class App extends React.Component<IAppProps, IAppState> { | |
/> | ||
) | ||
} | ||
case PopupType.ChangeRepositoryAlias: { | ||
return ( | ||
<ChangeRepositoryAlias | ||
dispatcher={this.props.dispatcher} | ||
repository={popup.repository} | ||
onDismissed={onPopupDismissedFn} | ||
/> | ||
) | ||
} | ||
default: | ||
return assertNever(popup, `Unknown popup type: ${popup}`) | ||
} | ||
|
@@ -2367,8 +2377,9 @@ export class App extends React.Component<IAppProps, IAppState> { | |
let icon: OcticonSymbol | ||
let title: string | ||
if (repository) { | ||
const alias = repository instanceof Repository ? repository.alias : null | ||
icon = iconForRepository(repository) | ||
title = repository.name | ||
title = alias ?? repository.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the title of the drop down that shows the current repository. |
||
} else if (this.state.repositories.length > 0) { | ||
icon = OcticonSymbol.repo | ||
title = __DARWIN__ ? 'Select a Repository' : 'Select a repository' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as React from 'react' | ||
|
||
import { Dispatcher } from '../dispatcher' | ||
import { nameOf, Repository } from '../../models/repository' | ||
import { Dialog, DialogContent, DialogFooter } from '../dialog' | ||
import { OkCancelButtonGroup } from '../dialog/ok-cancel-button-group' | ||
import { TextBox } from '../lib/text-box' | ||
|
||
interface IChangeRepositoryAliasProps { | ||
readonly dispatcher: Dispatcher | ||
readonly onDismissed: () => void | ||
readonly repository: Repository | ||
} | ||
|
||
interface IChangeRepositoryAliasState { | ||
readonly newAlias: string | ||
} | ||
|
||
export class ChangeRepositoryAlias extends React.Component< | ||
IChangeRepositoryAliasProps, | ||
IChangeRepositoryAliasState | ||
> { | ||
public constructor(props: IChangeRepositoryAliasProps) { | ||
super(props) | ||
|
||
this.state = { newAlias: props.repository.alias ?? props.repository.name } | ||
} | ||
|
||
public render() { | ||
const repository = this.props.repository | ||
const verb = repository.alias === null ? 'Create' : 'Change' | ||
|
||
return ( | ||
<Dialog | ||
id="change-repository-alias" | ||
title={ | ||
__DARWIN__ ? `${verb} Repository Alias` : `${verb} repository alias` | ||
} | ||
onDismissed={this.props.onDismissed} | ||
onSubmit={this.changeAlias} | ||
> | ||
<DialogContent> | ||
<p>Choose a new alias for the repository "{nameOf(repository)}". </p> | ||
<p> | ||
<TextBox | ||
value={this.state.newAlias} | ||
onValueChanged={this.onNameChanged} | ||
/> | ||
</p> | ||
{repository.gitHubRepository !== null && ( | ||
<p className="description"> | ||
This will not affect the original repository name on GitHub. | ||
</p> | ||
)} | ||
</DialogContent> | ||
|
||
<DialogFooter> | ||
<OkCancelButtonGroup | ||
okButtonText={__DARWIN__ ? `${verb} Alias` : `${verb} alias`} | ||
okButtonDisabled={this.state.newAlias.length === 0} | ||
/> | ||
</DialogFooter> | ||
</Dialog> | ||
) | ||
} | ||
|
||
private onNameChanged = (newAlias: string) => { | ||
this.setState({ newAlias }) | ||
} | ||
|
||
private changeAlias = () => { | ||
this.props.dispatcher.changeRepositoryAlias( | ||
this.props.repository, | ||
this.state.newAlias | ||
) | ||
this.props.onDismissed() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ export function groupRepositories( | |
const { aheadBehind, changedFilesCount } = | ||
localRepositoryStateLookup.get(r.id) || fallbackValue | ||
const repositoryText = | ||
r instanceof Repository ? [r.name, nameOf(r)] : [r.name] | ||
r instanceof Repository ? [r.alias ?? r.name, nameOf(r)] : [r.name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This basically makes sure the alias is used to look for matches when the user filters the repository list. |
||
|
||
return { | ||
text: repositoryText, | ||
|
@@ -132,8 +132,10 @@ export function makeRecentRepositoriesGroup( | |
for (const id of recentRepositories) { | ||
const repository = repositories.find(r => r.id === id) | ||
if (repository !== undefined) { | ||
const existingCount = names.get(repository.name) || 0 | ||
names.set(repository.name, existingCount + 1) | ||
const alias = repository instanceof Repository ? repository.alias : null | ||
const name = alias ?? repository.name | ||
const existingCount = names.get(name) || 0 | ||
names.set(name, existingCount + 1) | ||
Comment on lines
-135
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list of names is used to detect duplicates in the |
||
} | ||
} | ||
|
||
|
@@ -147,11 +149,13 @@ export function makeRecentRepositoriesGroup( | |
|
||
const { aheadBehind, changedFilesCount } = | ||
localRepositoryStateLookup.get(id) || fallbackValue | ||
const repositoryAlias = | ||
repository instanceof Repository ? repository.alias : null | ||
const repositoryText = | ||
repository instanceof Repository | ||
? [repository.name, nameOf(repository)] | ||
? [repositoryAlias ?? repository.name, nameOf(repository)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also for the repository list filter. |
||
: [repository.name] | ||
const nameCount = names.get(repository.name) || 0 | ||
const nameCount = names.get(repositoryAlias ?? repository.name) || 0 | ||
Comment on lines
-154
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we actually check if the repo alias or name is duplicated and need disambiguation. |
||
items.push({ | ||
text: repositoryText, | ||
id: id.toString(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, creating/changing/removing the alias of the current repo, would move the current repo into the Recents list, which doesn't make sense.