Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit e400728

Browse files
authored
Merge pull request #1659 from github/fixes/github-fork-limit-functionality
Limiting functionality in the beta repo fork functionality
2 parents ec382fb + 45c073c commit e400728

17 files changed

+175
-226
lines changed

src/GitHub.App/Models/Account.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public Account(Octokit.Account account, IObservable<BitmapSource> bitmapSource)
8080

8181
public long PrivateReposInPlan { get; private set; }
8282

83-
public string AvatarUrl { get; private set; }
83+
public string AvatarUrl { get; set; }
8484

8585
public BitmapSource Avatar
8686
{

src/GitHub.App/SampleData/ForkRepositoryExecuteViewModelDesigner.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public ForkRepositoryExecuteViewModelDesigner()
3030

3131
public IObservable<object> Done => null;
3232

33+
public IObservable<object> Back => null;
34+
3335
public string Title => null;
3436

3537
public IRepositoryModel SourceRepository { get; set; }
@@ -40,6 +42,8 @@ public ForkRepositoryExecuteViewModelDesigner()
4042

4143
public IReactiveCommand<Repository> CreateFork => null;
4244

45+
public IReactiveCommand<object> BackCommand => null;
46+
4347
public bool ResetMasterTracking { get; set; } = true;
4448

4549
public bool AddUpstream { get; set; } = true;

src/GitHub.App/SampleData/ForkRepositorySelectViewModelDesigner.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public ForkRepositorySelectViewModelDesigner()
1414
{
1515
Accounts = new[]
1616
{
17-
new AccountDesigner { Login = "Myself" },
18-
new AccountDesigner { Login = "MyOrg1" },
19-
new AccountDesigner { Login = "MyOrg2" },
20-
new AccountDesigner { Login = "MyOrg3" },
21-
new AccountDesigner { Login = "a-long-org-name" },
17+
new AccountDesigner { Login = "Myself", AvatarUrl = "https://identicons.github.com/myself.png" },
18+
new AccountDesigner { Login = "MyOrg1", AvatarUrl = "https://identicons.github.com/myorg1.png" },
19+
new AccountDesigner { Login = "MyOrg2", AvatarUrl = "https://identicons.github.com/myorg2.png" },
20+
new AccountDesigner { Login = "MyOrg3", AvatarUrl = "https://identicons.github.com/myorg3.png" },
21+
new AccountDesigner { Login = "a-long-org-name", AvatarUrl = "https://identicons.github.com/a-long-org-name.png" },
2222
};
2323

2424
ExistingForks = new[]

src/GitHub.App/Services/RepositoryForkService.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public IObservable<Repository> ForkRepository(IApiClient apiClient, IRepositoryM
4141
log.Verbose("ForkRepository Source:{SourceOwner}/{SourceName} To:{DestinationOwner}", sourceRepository.Owner, sourceRepository.Name, repositoryFork.Organization ?? "[Current User]");
4242
log.Verbose("ForkRepository updateOrigin:{UpdateOrigin} addUpstream:{AddUpstream} trackMasterUpstream:{TrackMasterUpstream}", updateOrigin, addUpstream, trackMasterUpstream);
4343

44-
RecordForkRepositoryUsage(updateOrigin, addUpstream, trackMasterUpstream).Forget();
44+
usageTracker.IncrementCounter(model => model.NumberOfReposForked).Forget();
4545

4646
return Observable.Defer(() => apiClient.ForkRepository(sourceRepository.Owner, sourceRepository.Name, repositoryFork)
4747
.ObserveOn(RxApp.MainThreadScheduler)
@@ -63,26 +63,6 @@ public IObservable<Repository> ForkRepository(IApiClient apiClient, IRepositoryM
6363
});
6464
}
6565

66-
private async Task RecordForkRepositoryUsage(bool updateOrigin, bool addUpstream, bool trackMasterUpstream)
67-
{
68-
await usageTracker.IncrementCounter(model => model.NumberOfReposForked);
69-
70-
if (updateOrigin)
71-
{
72-
await usageTracker.IncrementCounter(model => model.NumberOfOriginsUpdatedWhenForkingRepo);
73-
}
74-
75-
if (addUpstream)
76-
{
77-
await usageTracker.IncrementCounter(model => model.NumberOfUpstreamsAddedWhenForkingRepo);
78-
}
79-
80-
if (trackMasterUpstream)
81-
{
82-
await usageTracker.IncrementCounter(model => model.NumberOfTrackMasterUpstreamWhenForkingRepo);
83-
}
84-
}
85-
8666
public IObservable<object> SwitchRemotes(IRepositoryModel destinationRepository, bool updateOrigin, bool addUpstream, bool trackMasterUpstream)
8767
{
8868
return Observable.Defer(() => Observable.Return(new object())

src/GitHub.App/ViewModels/Dialog/ForkRepositoryExecuteViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ IRepositoryForkService repositoryForkService
4545
.Subscribe(tuple => CanResetMasterTracking = tuple.Item1 && tuple.Item2);
4646

4747
CreateFork = ReactiveCommand.CreateAsyncObservable(OnCreateFork);
48+
BackCommand = ReactiveCommand.Create();
4849
}
4950

5051
public IRepositoryModel SourceRepository { get; private set; }
@@ -55,10 +56,14 @@ IRepositoryForkService repositoryForkService
5556

5657
public IReactiveCommand<Repository> CreateFork { get; }
5758

59+
public IReactiveCommand<object> BackCommand { get; }
60+
5861
public string Title => Resources.ForkRepositoryTitle;
5962

6063
public IObservable<object> Done => CreateFork.Where(repository => repository != null);
6164

65+
public IObservable<object> Back => BackCommand.AsObservable();
66+
6267
public async Task InitializeAsync(ILocalRepositoryModel sourceRepository, IAccount destinationAccount, IConnection connection)
6368
{
6469
var modelService = await modelServiceFactory.CreateAsync(connection);
@@ -125,21 +130,22 @@ public bool AddUpstream
125130
set { this.RaiseAndSetIfChanged(ref addUpstream, value); }
126131
}
127132

128-
bool canResetMasterTracking = true;
133+
bool canResetMasterTracking;
129134
public bool CanResetMasterTracking
130135
{
131136
get { return canResetMasterTracking; }
132137
private set { this.RaiseAndSetIfChanged(ref canResetMasterTracking, value); }
133138
}
134139

135-
bool resetMasterTracking = true;
140+
bool resetMasterTracking;
136141
public bool ResetMasterTracking
137142
{
138143
get { return resetMasterTracking; }
139144
set { this.RaiseAndSetIfChanged(ref resetMasterTracking, value); }
140145
}
141146

142147
string error = null;
148+
143149
public string Error
144150
{
145151
get { return error; }

src/GitHub.App/ViewModels/Dialog/ForkRepositorySelectViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ void BuildAccounts(IReadOnlyList<IAccount> accessibleAccounts, ILocalRepositoryM
108108

109109
Accounts = readOnlyList.Where(arg => arg.Fork == null).Select(arg => arg.Account).ToList();
110110
ExistingForks = readOnlyList.Where(arg => arg.Fork != null).Select(arg => arg.Fork).ToList();
111+
112+
// HACK: Our avatar cache only provides avatars in a very small size, but we want to
113+
// display them 100x100 in the Fork view. For now, wse the AvatarUrl directly to get
114+
// the avatar, appending "s=100" to the URL to get the correct size.
115+
foreach (Account account in Accounts)
116+
{
117+
account.AvatarUrl += "&s=100";
118+
}
111119
}
112120
}
113121
}

src/GitHub.App/ViewModels/Dialog/ForkRepositoryViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public ForkRepositoryViewModel(
3333

3434
selectPage.SwitchOrigin.Subscribe(x => ShowSwitchRepositoryPath((IRemoteRepositoryModel)x));
3535
selectPage.Done.Subscribe(x => ShowExecutePage((IAccount)x).Forget());
36+
executePage.Back.Subscribe(x => ShowSelectPage().Forget());
3637
}
3738

3839
public ILocalRepositoryModel Repository { get; private set; }
@@ -47,7 +48,12 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
4748
{
4849
Repository = repository;
4950
Connection = connection;
50-
await selectPage.InitializeAsync(repository, connection);
51+
await ShowSelectPage();
52+
}
53+
54+
async Task ShowSelectPage()
55+
{
56+
await selectPage.InitializeAsync(Repository, Connection);
5157
Content = selectPage;
5258
}
5359

src/GitHub.Exports.Reactive/ViewModels/Dialog/IForkRepositoryExecuteViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public interface IForkRepositoryExecuteViewModel : IDialogContentViewModel
2323
/// </summary>
2424
IReactiveCommand<Repository> CreateFork { get; }
2525

26+
IReactiveCommand<object> BackCommand { get; }
27+
2628
bool ResetMasterTracking { get; set; }
2729

2830
bool AddUpstream { get; set; }
@@ -34,6 +36,7 @@ public interface IForkRepositoryExecuteViewModel : IDialogContentViewModel
3436
bool CanResetMasterTracking { get; }
3537

3638
string Error { get; }
39+
IObservable<object> Back { get; }
3740

3841
/// <summary>
3942
/// Initializes the view model.

src/GitHub.Exports/Models/UsageModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ public class MeasuresModel
7373
public int NumberOfGitHubConnectSectionClones { get; set; }
7474
public int NumberOfShowRepoForkDialogClicks { get; set; }
7575
public int NumberOfReposForked { get; set; }
76-
public int NumberOfOriginsUpdatedWhenForkingRepo { get; set; }
77-
public int NumberOfUpstreamsAddedWhenForkingRepo { get; set; }
78-
public int NumberOfTrackMasterUpstreamWhenForkingRepo { get; set; }
7976
public int ExecuteGoToSolutionOrPullRequestFileCommand { get; set; }
8077
public int NumberOfPRDetailsNavigateToEditor { get; set; } // Should rename to NumberOfNavigateToEditor
8178
public int NumberOfNavigateToPullRequestFileDiff { get; set; }

src/GitHub.TeamFoundation.14/Home/ForkNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public override async void Invalidate()
9797
{
9898
IsVisible = false;
9999

100-
if ((packageSettings?.ForkButton ?? false) && await IsAGitHubRepo())
100+
if ((packageSettings?.ForkButton ?? false) && await IsAGitHubDotComRepo())
101101
{
102102
var connection = await ConnectionManager.GetConnection(ActiveRepo);
103103
IsVisible = connection?.IsLoggedIn ?? false;

src/GitHub.VisualStudio.UI/Base/TeamExplorerItemBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ protected async Task<bool> IsAGitHubRepo()
141141
return origin == RepositoryOrigin.DotCom || origin == RepositoryOrigin.Enterprise;
142142
}
143143

144+
protected async Task<bool> IsAGitHubDotComRepo()
145+
{
146+
var origin = await GetRepositoryOrigin();
147+
return origin == RepositoryOrigin.DotCom;
148+
}
149+
144150
protected async Task<bool> IsUserAuthenticated()
145151
{
146152
if (SimpleApiClient == null)

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@
359359
<DependentUpon>OptionsControl.xaml</DependentUpon>
360360
</Compile>
361361
<Compile Include="Views\ContentView.cs" />
362-
<Compile Include="Views\Dialog\ForkRepositorySwitchView.xaml.cs">
363-
<DependentUpon>ForkRepositorySwitchView.xaml</DependentUpon>
364-
</Compile>
365362
<Compile Include="Views\Dialog\ForkRepositoryExecuteView.xaml.cs">
366363
<DependentUpon>ForkRepositoryExecuteView.xaml</DependentUpon>
367364
</Compile>
@@ -526,10 +523,6 @@
526523
<Generator>MSBuild:Compile</Generator>
527524
<CustomToolNamespace>GitHub.VisualStudio.UI</CustomToolNamespace>
528525
</Page>
529-
<Page Include="Views\Dialog\ForkRepositorySwitchView.xaml">
530-
<Generator>MSBuild:Compile</Generator>
531-
<SubType>Designer</SubType>
532-
</Page>
533526
<Page Include="Views\Dialog\ForkRepositoryExecuteView.xaml">
534527
<SubType>Designer</SubType>
535528
<Generator>MSBuild:Compile</Generator>

src/GitHub.VisualStudio/Views/Dialog/ForkRepositoryExecuteView.xaml

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,96 @@
66
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
77
xmlns:sampleData="clr-namespace:GitHub.SampleData;assembly=GitHub.App"
88
xmlns:ui="https://github.com/github/VisualStudio"
9+
VerticalAlignment="Top"
910
Margin="8"
11+
xmlns:cache="clr-namespace:GitHub.UI.Helpers;assembly=GitHub.UI"
1012
mc:Ignorable="d" d:DesignWidth="300" Height="315.179">
1113

14+
<Control.Resources>
15+
<ResourceDictionary>
16+
<ResourceDictionary.MergedDictionaries>
17+
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
18+
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI.Reactive;component/SharedDictionary.xaml" />
19+
</ResourceDictionary.MergedDictionaries>
20+
21+
<!-- Disable links until we make them work-->
22+
<Style TargetType="Hyperlink">
23+
<Setter Property="IsEnabled" Value="False"/>
24+
<Setter Property="Foreground" Value="Black"/>
25+
</Style>
26+
27+
</ResourceDictionary>
28+
</Control.Resources>
29+
1230
<d:DesignProperties.DataContext>
1331
<sampleData:ForkRepositoryExecuteViewModelDesigner/>
1432
</d:DesignProperties.DataContext>
1533

16-
<StackPanel>
17-
<TextBlock TextWrapping="Wrap">
34+
<StackPanel Margin="0 8 0 0">
35+
<TextBlock FontSize="16" TextWrapping="Wrap">
1836
You're about to fork the
1937
<Hyperlink>
2038
<Run Text="{Binding SourceRepository.Owner, Mode=OneWay}"/>/<Run Text="{Binding SourceRepository.Name, Mode=OneWay}"/>
2139
</Hyperlink>
2240
repository to
2341
<Hyperlink>
2442
<Run Text="{Binding DestinationRepository.Owner, Mode=OneWay}"/>/<Run Text="{Binding DestinationRepository.Name, Mode=OneWay}"/>
25-
</Hyperlink>. This operation will:
43+
</Hyperlink>.
2644
</TextBlock>
2745

28-
<ItemsControl Margin="8,16,8,8">
29-
<ItemsControl.Resources>
30-
<Style x:Key="ItemBorder" TargetType="Border">
31-
<Setter Property="Background" Value="#10000000"/>
32-
<Setter Property="CornerRadius" Value="3"/>
33-
<Setter Property="Margin" Value="4"/>
34-
<Setter Property="Padding" Value="4,8"/>
35-
</Style>
36-
<Style TargetType="CheckBox">
37-
<Setter Property="Margin" Value="0,1,6,0"/>
38-
<Setter Property="VerticalAlignment" Value="Center"/>
39-
</Style>
40-
</ItemsControl.Resources>
41-
<Border Style="{StaticResource ItemBorder}">
42-
<DockPanel>
43-
<CheckBox IsChecked="True" IsEnabled="False"/>
44-
<TextBlock>Fork the repository</TextBlock>
45-
</DockPanel>
46-
</Border>
47-
<Border Style="{StaticResource ItemBorder}">
48-
<DockPanel>
49-
<CheckBox IsChecked="{Binding UpdateOrigin}"/>
50-
<TextBlock TextWrapping="Wrap">
51-
Update your local repository's <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">origin</Run> to point to
52-
<Hyperlink><Run Text="{Binding DestinationRepository.CloneUrl, Mode=OneWay}"/></Hyperlink>
53-
</TextBlock>
54-
</DockPanel>
55-
</Border>
56-
<Border Style="{StaticResource ItemBorder}">
57-
<DockPanel>
58-
<CheckBox IsChecked="{Binding AddUpstream}" IsEnabled="{Binding CanAddUpstream}" />
59-
<TextBlock TextWrapping="Wrap">
60-
Add an <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">upstream</Run> remote pointing to
61-
<Hyperlink><Run Text="{Binding SourceRepository.CloneUrl, Mode=OneWay}"/></Hyperlink>
62-
</TextBlock>
63-
</DockPanel>
64-
</Border>
65-
<Border Style="{StaticResource ItemBorder}">
66-
<DockPanel>
67-
<CheckBox IsChecked="{Binding ResetMasterTracking}" IsEnabled="{Binding CanResetMasterTracking}" />
68-
<TextBlock TextWrapping="Wrap">
69-
Set the <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">master</Run> branch to track
70-
<Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">upstream/master</Run>
71-
</TextBlock>
72-
</DockPanel>
73-
</Border>
74-
<Border Style="{StaticResource ItemBorder}">
75-
<StackPanel >
76-
<Button Click="repoForkButton_OnClick">Fork Repo</Button>
77-
<TextBlock TextWrapping="Wrap"
78-
Foreground="Red"
79-
Text="{Binding Error, Mode=OneWay}"
80-
HorizontalAlignment="Center"
81-
Visibility="{Binding Error, Converter={ui:NullToVisibilityConverter}}"/>
46+
<TextBlock Margin="0 16 0 0" FontSize="14">This operation will:</TextBlock>
47+
48+
<StackPanel Orientation="Vertical">
49+
<Border Margin="0 8 0 4" CornerRadius="2" Background="#ffeff1f5" Padding="8 16">
50+
<StackPanel>
51+
<Grid Margin="0 0 0 0">
52+
<Grid.ColumnDefinitions>
53+
<ColumnDefinition Width="Auto" />
54+
<ColumnDefinition Width="*" />
55+
</Grid.ColumnDefinitions>
56+
57+
<ui:OcticonImage Grid.Column="0" Icon="repo_forked" Background="Red" Height="16" Width="16" />
58+
<TextBlock Margin="8 0 0 0" Grid.Column="1" TextWrapping="Wrap">Fork the repository</TextBlock>
59+
</Grid>
60+
61+
<Grid Margin="0 16 0 0">
62+
<Grid.ColumnDefinitions>
63+
<ColumnDefinition Width="Auto" />
64+
<ColumnDefinition Width="*" />
65+
</Grid.ColumnDefinitions>
66+
<ui:OcticonImage Grid.Column="0" Icon="home" Height="16" Width="16" />
67+
68+
<TextBlock Margin="8 0 0 0" Grid.Column="1" TextWrapping="Wrap">
69+
Update your local repository's <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">origin</Run> to point to
70+
<Hyperlink><Run Text="{Binding DestinationRepository.CloneUrl, Mode=OneWay}"/></Hyperlink>
71+
</TextBlock>
72+
</Grid>
73+
74+
<Grid Margin="0 16 0 0" >
75+
<Grid.ColumnDefinitions>
76+
<ColumnDefinition Width="Auto" />
77+
<ColumnDefinition Width="*" />
78+
</Grid.ColumnDefinitions>
79+
80+
<ui:OcticonImage Grid.Column="0" Icon="globe" Height="16" Width="16" />
81+
<TextBlock Margin="8 0 0 0" Grid.Column="1" TextWrapping="Wrap">
82+
Add an <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">upstream</Run> remote pointing to
83+
<Hyperlink><Run Text="{Binding SourceRepository.CloneUrl, Mode=OneWay}"/></Hyperlink>
84+
</TextBlock>
85+
</Grid>
86+
</StackPanel>
87+
</Border>
88+
89+
<TextBlock TextWrapping="Wrap"
90+
Margin="0 4"
91+
Foreground="Red"
92+
Text="{Binding Error, Mode=OneWay}"
93+
Visibility="{Binding Error, Converter={ui:NullToVisibilityConverter}}"
94+
HorizontalAlignment="Left" />
95+
<StackPanel Margin="0 8" Orientation="Horizontal" HorizontalAlignment="Right">
96+
<Button HorizontalAlignment="Right" Padding="16 4" BorderThickness="0" Margin="0 0 4 0" Click="backButton_OnClick">Back</Button>
97+
<Button HorizontalAlignment="Right" Padding="16 4" BorderThickness="0" Click="repoForkButton_OnClick">Fork Repository</Button>
8298
</StackPanel>
83-
</Border>
84-
</ItemsControl>
99+
</StackPanel>
85100
</StackPanel>
86101
</UserControl>

0 commit comments

Comments
 (0)