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

Commit ed8d0e8

Browse files
authored
Merge pull request #502 from github/fixes/501-push-new-branch-on-pr-creation
PR Creation: Push local branches and handle forks properly
2 parents 7c0e155 + f1ad348 commit ed8d0e8

File tree

57 files changed

+1964
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1964
-343
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,10 @@ public IObservable<Branch> GetBranches(string owner, string repo)
259259
{
260260
return gitHubClient.Repository.GetAllBranches(owner, repo);
261261
}
262+
263+
public IObservable<Repository> GetRepository(string owner, string repo)
264+
{
265+
return gitHubClient.Repository.Get(owner, repo);
266+
}
262267
}
263268
}

src/GitHub.App/Controllers/UIController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ void ConfigureUIHandlingStates()
339339
.OnEntry(tr => RunView(UIViewType.PRCreation, CalculateDirection(tr)))
340340
.PermitDynamic(Trigger.Next, () => Go(Trigger.Next))
341341
.PermitDynamic(Trigger.Cancel, () => Go(Trigger.Cancel))
342-
.PermitDynamic(Trigger.Finish, () => Go(Trigger.Finish));
342+
.PermitDynamic(Trigger.Finish, () => Go(Trigger.Finish))
343+
.OnExit(() => DisposeView(activeFlow, UIViewType.PRCreation));
343344

344345
uiStateMachine.Configure(UIViewType.Login)
345346
.OnEntry(tr => RunView(UIViewType.Login, CalculateDirection(tr)))

src/GitHub.App/GitHub.App.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
<Compile Include="Factories\UIFactory.cs" />
128128
<Compile Include="GlobalSuppressions.cs" />
129129
<Compile Include="Infrastructure\LoggingConfiguration.cs" />
130-
<Compile Include="Models\BranchModel.cs" />
131130
<Compile Include="Models\PullRequestModel.cs" />
132131
<Compile Include="Resources.Designer.cs">
133132
<AutoGen>True</AutoGen>

src/GitHub.App/Models/Account.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Globalization;
44
using System.Reactive.Linq;
55
using System.Windows.Media.Imaging;
6+
using GitHub.Primitives;
67
using NullGuard;
8+
using Octokit;
79
using ReactiveUI;
810

911
namespace GitHub.Models
@@ -33,6 +35,19 @@ public Account(
3335
.Subscribe(x => avatar = x);
3436
}
3537

38+
public Account(Octokit.Account account)
39+
{
40+
Login = account.Login;
41+
IsUser = (account as User) != null;
42+
Uri htmlUrl;
43+
IsEnterprise = Uri.TryCreate(account.HtmlUrl, UriKind.Absolute, out htmlUrl)
44+
&& !HostAddress.IsGitHubDotComUri(htmlUrl);
45+
PrivateReposInPlan = account.Plan != null ? account.Plan.PrivateRepos : 0;
46+
OwnedPrivateRepos = account.OwnedPrivateRepos;
47+
IsOnFreePlan = PrivateReposInPlan == 0;
48+
HasMaximumPrivateRepositories = OwnedPrivateRepos >= PrivateReposInPlan;
49+
}
50+
3651
public bool IsOnFreePlan { get; private set; }
3752

3853
public bool HasMaximumPrivateRepositories { get; private set; }

src/GitHub.App/Models/BranchModel.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/GitHub.App/Models/RepositoryModel.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,28 @@ public RepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate,
1212
: base(name, cloneUrl)
1313
{
1414
Id = id;
15-
Owner = ownerAccount;
15+
OwnerAccount = ownerAccount;
16+
IsFork = isFork;
1617
SetIcon(isPrivate, isFork);
18+
// this is an assumption, we'd have to load the repo information from octokit to know for sure
19+
// probably not worth it for this ctor
20+
DefaultBranch = new BranchModel("master", this);
1721
}
1822

23+
public RepositoryModel(Octokit.Repository repository)
24+
: base(repository.Name, repository.CloneUrl)
25+
{
26+
Id = repository.Id;
27+
IsFork = repository.Fork;
28+
SetIcon(repository.Private, IsFork);
29+
OwnerAccount = new Account(repository.Owner);
30+
DefaultBranch = new BranchModel(repository.DefaultBranch, this);
31+
Parent = repository.Parent != null ? new RepositoryModel(repository.Parent) : null;
32+
if (Parent != null)
33+
Parent.DefaultBranch.DisplayName = Parent.DefaultBranch.Id;
34+
}
35+
36+
#region Equality Things
1937
public void CopyFrom(IRepositoryModel other)
2038
{
2139
if (!Equals(other))
@@ -33,17 +51,17 @@ public override bool Equals([AllowNull]object obj)
3351
if (ReferenceEquals(this, obj))
3452
return true;
3553
var other = obj as RepositoryModel;
36-
return other != null && Id == other.Id;
54+
return Equals(other);
3755
}
3856

39-
bool IEquatable<IRepositoryModel>.Equals([AllowNull]IRepositoryModel other)
57+
public bool Equals([AllowNull]IRepositoryModel other)
4058
{
4159
if (ReferenceEquals(this, other))
4260
return true;
4361
return other != null && Id == other.Id;
4462
}
4563

46-
bool IEquatable<RepositoryModel>.Equals([AllowNull]RepositoryModel other)
64+
public bool Equals([AllowNull]RepositoryModel other)
4765
{
4866
if (ReferenceEquals(this, other))
4967
return true;
@@ -83,11 +101,15 @@ public int CompareTo([AllowNull]RepositoryModel other)
83101
{
84102
return !(lhs == rhs);
85103
}
104+
#endregion
86105

87-
public IAccount Owner { get; }
106+
public IAccount OwnerAccount { get; }
88107
public long Id { get; }
89108
public DateTimeOffset CreatedAt { get; set; }
90109
public DateTimeOffset UpdatedAt { get; set; }
110+
public bool IsFork { get; }
111+
[AllowNull] public IRepositoryModel Parent { [return: AllowNull] get; }
112+
public IBranch DefaultBranch { get; }
91113

92114
internal string DebuggerDisplay
93115
{

src/GitHub.App/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.App/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
<data name="PasswordValidatorEmpty" xml:space="preserve">
172172
<value>Please enter your password</value>
173173
</data>
174+
<data name="PRCreatedUpstream" xml:space="preserve">
175+
<value>The Pull Request has been created at [{0}]({1}).</value>
176+
</data>
174177
<data name="PublishTitle" xml:space="preserve">
175178
<value>Publish repository</value>
176179
</data>

src/GitHub.App/SampleData/PullRequestCreationViewModelDesigner.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public PullRequestCreationViewModelDesigner()
1414
{
1515
Branches = new List<IBranch>
1616
{
17-
new BranchModel { Name = "master" },
18-
new BranchModel { Name = "don/stub-ui" },
19-
new BranchModel { Name = "feature/pr/views" },
20-
new BranchModel { Name = "release-1.0.17.0" }
17+
new BranchModel("master", new SimpleRepositoryModel("http://github.com/user/repo")),
18+
new BranchModel("don/stub-ui", new SimpleRepositoryModel("http://github.com/user/repo")),
19+
new BranchModel("feature/pr/views", new SimpleRepositoryModel("http://github.com/user/repo")),
20+
new BranchModel("release-1.0.17.0", new SimpleRepositoryModel("http://github.com/user/repo")),
2121
}.AsReadOnly();
2222

23-
TargetBranch = new BranchModel { Name = "master" };
23+
TargetBranch = new BranchModel("master", new SimpleRepositoryModel("http://github.com/user/repo"));
2424
SourceBranch = Branches[2];
2525

2626
SelectedAssignee = "Haacked (Phil Haack)";

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ public bool OpenRepository()
496496

497497
public class InfoPanelDesigner
498498
{
499-
public string Message => "This is an informational message for the info panel to test things in design mode.";
499+
public string Message => "This is an informational message for the [info panel](link) to test things in design mode.";
500+
public MessageType MessageType => MessageType.Information;
500501
}
501502
}

0 commit comments

Comments
 (0)