{"action":"created","comment":{"url":"https://api.github.com/repos/github/VisualStudio/pulls/comments/75091322","id":75091322,"diff_hunk":"@@ -11,63 +11,85 @@\n using System.Linq;\n using GitHub.Validation;\n using GitHub.Extensions;\n-using NullGuard;\n using GitHub.App;\n using System.Reactive.Subjects;\n using System.Reactive;\n using System.Diagnostics.CodeAnalysis;\n using Octokit;\n using NLog;\n+using LibGit2Sharp;\n+using System.Reactive.Threading.Tasks;\n+using GitHub.Factories;\n \n namespace GitHub.ViewModels\n {\n+    [NullGuard.NullGuard(NullGuard.ValidationFlags.None)]\n     [ExportViewModel(ViewType = UIViewType.PRCreation)]\n     [PartCreationPolicy(CreationPolicy.NonShared)]\n     [SuppressMessage(\"Microsoft.Design\", \"CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable\")]\n     public class PullRequestCreationViewModel : BaseViewModel, IPullRequestCreationViewModel\n     {\n         static readonly Logger log = LogManager.GetCurrentClassLogger();\n \n+        readonly ObservableAsPropertyHelper<IRepositoryModel> githubRepository;\n+        readonly ObservableAsPropertyHelper<bool> isExecuting;\n         readonly IRepositoryHost repositoryHost;\n-        readonly ISimpleRepositoryModel activeRepo;\n-        readonly IPullRequestService service;\n-        readonly Subject<Unit> initializationComplete = new Subject<Unit>();\n-        bool initialized;\n+        readonly IObservable<IRepositoryModel> githubObs;\n \n         [ImportingConstructor]\n         PullRequestCreationViewModel(\n              IConnectionRepositoryHostMap connectionRepositoryHostMap, ITeamExplorerServiceHolder teservice,\n              IPullRequestService service, INotificationService notifications)\n-             : this(connectionRepositoryHostMap.CurrentRepositoryHost, teservice.ActiveRepo, service, notifications)\n+             : this(connectionRepositoryHostMap?.CurrentRepositoryHost, teservice?.ActiveRepo, service,\n+                   notifications)\n          {}\n \n         public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepositoryModel activeRepo,\n             IPullRequestService service, INotificationService notifications)\n         {\n+            Extensions.Guard.ArgumentNotNull(repositoryHost, nameof(repositoryHost));\n+            Extensions.Guard.ArgumentNotNull(activeRepo, nameof(activeRepo));\n+            Extensions.Guard.ArgumentNotNull(service, nameof(service));\n+            Extensions.Guard.ArgumentNotNull(notifications, nameof(notifications));\n+\n             this.repositoryHost = repositoryHost;\n-            this.activeRepo = activeRepo;\n-            this.service = service;\n \n-            var repo = GitService.GitServiceHelper.GetRepo(activeRepo.LocalPath);\n-            this.WhenAny(x => x.Branches, x => x.Value)\n+            githubObs = repositoryHost.ApiClient.GetRepository(activeRepo.Owner, activeRepo.Name)\n+                .Select(r => new RepositoryModel(r))\n+                .PublishLastAndConnect();\n+\n+            githubRepository = githubObs.ToProperty(this, x => x.GitHubRepository);\n+\n+            this.WhenAnyValue(x => x.GitHubRepository)\n+                .WhereNotNull()\n+                .Subscribe(r =>\n+            {\n+                TargetBranch = r.IsFork ? r.Parent.DefaultBranch : r.DefaultBranch;\n+            });\n+\n+            SourceBranch = activeRepo.CurrentBranch;\n+            service.GetPullRequestTemplate(activeRepo)\n+                .Subscribe(x => Description = x ?? String.Empty);\n+\n+            this.WhenAnyValue(x => x.Branches)\n                 .WhereNotNull()\n+                .Where(_ => TargetBranch != null)\n                 .Subscribe(x =>\n                 {\n-                    // what do we do if there's no master?\n-                    TargetBranch = x.FirstOrDefault(b => b.Name == \"master\");\n-                    SourceBranch = x.FirstOrDefault(b => b.Name == repo.Head.FriendlyName);\n+                    if (!x.Any(t => t.Equals(TargetBranch)))\n+                        TargetBranch = GitHubRepository.IsFork ? GitHubRepository.Parent.DefaultBranch : GitHubRepository.DefaultBranch;\n                 });\n \n-            var titleObs = this.WhenAny(x => x.PRTitle, x => x.Value);\n+            var titleObs = this.WhenAnyValue(x => x.PRTitle);\n             TitleValidator = ReactivePropertyValidator.ForObservable(titleObs)\n                 .IfNullOrEmpty(Resources.PullRequestCreationTitleValidatorEmpty);\n \n             var branchObs = this.WhenAny(\n-                x => x.TargetBranch,\n-                x => x.SourceBranch,\n-                (target, source) => new { Source = source.Value, Target = target.Value })\n-                .Where(_ => initialized)\n-                .Merge(initializationComplete.Select(_ => new { Source = SourceBranch, Target = TargetBranch }));\n+                    x => x.TargetBranch,\n+                    x => x.SourceBranch,\n+                    (target, source) => new { Source = source.Value, Target = target.Value })\n+                .Where(_ => Initialized)\n+                .Merge(this.WhenAnyValue(x => x.Initialized).Where(x => x).Select(_ => new { Source = SourceBranch, Target = TargetBranch }));","path":"src/GitHub.App/ViewModels/PullRequestCreationViewModel.cs","position":101,"original_position":101,"commit_id":"220ce431ec773afa419d8e1ca62b2bd955d2f114","original_commit_id":"220ce431ec773afa419d8e1ca62b2bd955d2f114","user":{"login":"grokys","id":1775141,"avatar_url":"https://avatars.githubusercontent.com/u/1775141?v=3","gravatar_id":"","url":"https://api.github.com/users/grokys","html_url":"https://github.com/grokys","followers_url":"https://api.github.com/users/grokys/followers","following_url":"https://api.github.com/users/grokys/following{/other_user}","gists_url":"https://api.github.com/users/grokys/gists{/gist_id}","starred_url":"https://api.github.com/users/grokys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grokys/subscriptions","organizations_url":"https://api.github.com/users/grokys/orgs","repos_url":"https://api.github.com/users/grokys/repos","events_url":"https://api.github.com/users/grokys/events{/privacy}","received_events_url":"https://api.github.com/users/grokys/received_events","type":"User","site_admin":true},"body":"Good change to remove the `initializationComplete`! However I think this could be further simplified:\r\n\r\n```\r\n            var branchObs = this.WhenAnyValue(\r\n                    x => x.Initialized,\r\n                    x => x.TargetBranch,\r\n                    x => x.SourceBranch,\r\n                    (init, target, source) => new { Initialized = init, Source = source, Target = target })\r\n                .Where(x => x.Initialized);\r\n```","created_at":"2016-08-17T09:34:12Z","updated_at":"2016-08-17T09:34:12Z","html_url":"https://github.com/github/VisualStudio/pull/502#discussion_r75091322","pull_request_url":"https://api.github.com/repos/github/VisualStudio/pulls/502","_links":{"self":{"href":"https://api.github.com/repos/github/VisualStudio/pulls/comments/75091322"},"html":{"href":"https://github.com/github/VisualStudio/pull/502#discussion_r75091322"},"pull_request":{"href":"https://api.github.com/repos/github/VisualStudio/pulls/502"}}},"pull_request":{"url":"https://api.github.com/repos/github/VisualStudio/pulls/502","id":80958027,"html_url":"https://github.com/github/VisualStudio/pull/502","diff_url":"https://github.com/github/VisualStudio/pull/502.diff","patch_url":"https://github.com/github/VisualStudio/pull/502.patch","issue_url":"https://api.github.com/repos/github/VisualStudio/issues/502","number":502,"state":"open","locked":false,"title":"PR Creation: Push local branches and handle forks properly","user":{"login":"shana","id":310137,"avatar_url":"https://avatars.githubusercontent.com/u/310137?v=3","gravatar_id":"","url":"https://api.github.com/users/shana","html_url":"https://github.com/shana","followers_url":"https://api.github.com/users/shana/followers","following_url":"https://api.github.com/users/shana/following{/other_user}","gists_url":"https://api.github.com/users/shana/gists{/gist_id}","starred_url":"https://api.github.com/users/shana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shana/subscriptions","organizations_url":"https://api.github.com/users/shana/orgs","repos_url":"https://api.github.com/users/shana/repos","events_url":"https://api.github.com/users/shana/events{/privacy}","received_events_url":"https://api.github.com/users/shana/received_events","type":"User","site_admin":true},"body":"Fixes #501\r\n\r\nWhen creating PRs, we should do the following\r\n\r\n- [x] Push local commits\r\n- [x] Set local branch to track remote branch if it's not\r\n- [x] If local branch is tracking a differently-named remote branch, use that remote branch name as the source for the PR\r\n- [x] If the repo is a fork, list all branches from both local and upstream and set upstream master as the default PR target branch","created_at":"2016-08-11T13:33:32Z","updated_at":"2016-08-17T09:34:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e6ef420ac8af453b9a23d35d0327d13129128c1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/github/VisualStudio/pulls/502/commits","review_comments_url":"https://api.github.com/repos/github/VisualStudio/pulls/502/comments","review_comment_url":"https://api.github.com/repos/github/VisualStudio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/github/VisualStudio/issues/502/comments","statuses_url":"https://api.github.com/repos/github/VisualStudio/statuses/220ce431ec773afa419d8e1ca62b2bd955d2f114","head":{"label":"github:fixes/501-push-new-branch-on-pr-creation","ref":"fixes/501-push-new-branch-on-pr-creation","sha":"220ce431ec773afa419d8e1ca62b2bd955d2f114","user":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":38325182,"name":"VisualStudio","full_name":"github/VisualStudio","owner":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/VisualStudio","description":"GitHub Extension for Visual Studio","fork":false,"url":"https://api.github.com/repos/github/VisualStudio","forks_url":"https://api.github.com/repos/github/VisualStudio/forks","keys_url":"https://api.github.com/repos/github/VisualStudio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/VisualStudio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/VisualStudio/teams","hooks_url":"https://api.github.com/repos/github/VisualStudio/hooks","issue_events_url":"https://api.github.com/repos/github/VisualStudio/issues/events{/number}","events_url":"https://api.github.com/repos/github/VisualStudio/events","assignees_url":"https://api.github.com/repos/github/VisualStudio/assignees{/user}","branches_url":"https://api.github.com/repos/github/VisualStudio/branches{/branch}","tags_url":"https://api.github.com/repos/github/VisualStudio/tags","blobs_url":"https://api.github.com/repos/github/VisualStudio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/VisualStudio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/VisualStudio/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/VisualStudio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/VisualStudio/statuses/{sha}","languages_url":"https://api.github.com/repos/github/VisualStudio/languages","stargazers_url":"https://api.github.com/repos/github/VisualStudio/stargazers","contributors_url":"https://api.github.com/repos/github/VisualStudio/contributors","subscribers_url":"https://api.github.com/repos/github/VisualStudio/subscribers","subscription_url":"https://api.github.com/repos/github/VisualStudio/subscription","commits_url":"https://api.github.com/repos/github/VisualStudio/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/VisualStudio/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/VisualStudio/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/VisualStudio/issues/comments{/number}","contents_url":"https://api.github.com/repos/github/VisualStudio/contents/{+path}","compare_url":"https://api.github.com/repos/github/VisualStudio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/VisualStudio/merges","archive_url":"https://api.github.com/repos/github/VisualStudio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/VisualStudio/downloads","issues_url":"https://api.github.com/repos/github/VisualStudio/issues{/number}","pulls_url":"https://api.github.com/repos/github/VisualStudio/pulls{/number}","milestones_url":"https://api.github.com/repos/github/VisualStudio/milestones{/number}","notifications_url":"https://api.github.com/repos/github/VisualStudio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/VisualStudio/labels{/name}","releases_url":"https://api.github.com/repos/github/VisualStudio/releases{/id}","deployments_url":"https://api.github.com/repos/github/VisualStudio/deployments","created_at":"2015-06-30T18:11:40Z","updated_at":"2016-08-16T23:09:22Z","pushed_at":"2016-08-16T19:17:59Z","git_url":"git://github.com/github/VisualStudio.git","ssh_url":"git@github.com:github/VisualStudio.git","clone_url":"https://github.com/github/VisualStudio.git","svn_url":"https://github.com/github/VisualStudio","homepage":"https://visualstudio.github.com","size":26628,"stargazers_count":503,"watchers_count":503,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":204,"mirror_url":null,"open_issues_count":72,"forks":204,"open_issues":72,"watchers":503,"default_branch":"master"}},"base":{"label":"github:master","ref":"master","sha":"35ef2984e42146685626c6e19d86237f6ec88d04","user":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":38325182,"name":"VisualStudio","full_name":"github/VisualStudio","owner":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/VisualStudio","description":"GitHub Extension for Visual Studio","fork":false,"url":"https://api.github.com/repos/github/VisualStudio","forks_url":"https://api.github.com/repos/github/VisualStudio/forks","keys_url":"https://api.github.com/repos/github/VisualStudio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/VisualStudio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/VisualStudio/teams","hooks_url":"https://api.github.com/repos/github/VisualStudio/hooks","issue_events_url":"https://api.github.com/repos/github/VisualStudio/issues/events{/number}","events_url":"https://api.github.com/repos/github/VisualStudio/events","assignees_url":"https://api.github.com/repos/github/VisualStudio/assignees{/user}","branches_url":"https://api.github.com/repos/github/VisualStudio/branches{/branch}","tags_url":"https://api.github.com/repos/github/VisualStudio/tags","blobs_url":"https://api.github.com/repos/github/VisualStudio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/VisualStudio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/VisualStudio/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/VisualStudio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/VisualStudio/statuses/{sha}","languages_url":"https://api.github.com/repos/github/VisualStudio/languages","stargazers_url":"https://api.github.com/repos/github/VisualStudio/stargazers","contributors_url":"https://api.github.com/repos/github/VisualStudio/contributors","subscribers_url":"https://api.github.com/repos/github/VisualStudio/subscribers","subscription_url":"https://api.github.com/repos/github/VisualStudio/subscription","commits_url":"https://api.github.com/repos/github/VisualStudio/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/VisualStudio/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/VisualStudio/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/VisualStudio/issues/comments{/number}","contents_url":"https://api.github.com/repos/github/VisualStudio/contents/{+path}","compare_url":"https://api.github.com/repos/github/VisualStudio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/VisualStudio/merges","archive_url":"https://api.github.com/repos/github/VisualStudio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/VisualStudio/downloads","issues_url":"https://api.github.com/repos/github/VisualStudio/issues{/number}","pulls_url":"https://api.github.com/repos/github/VisualStudio/pulls{/number}","milestones_url":"https://api.github.com/repos/github/VisualStudio/milestones{/number}","notifications_url":"https://api.github.com/repos/github/VisualStudio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/VisualStudio/labels{/name}","releases_url":"https://api.github.com/repos/github/VisualStudio/releases{/id}","deployments_url":"https://api.github.com/repos/github/VisualStudio/deployments","created_at":"2015-06-30T18:11:40Z","updated_at":"2016-08-16T23:09:22Z","pushed_at":"2016-08-16T19:17:59Z","git_url":"git://github.com/github/VisualStudio.git","ssh_url":"git@github.com:github/VisualStudio.git","clone_url":"https://github.com/github/VisualStudio.git","svn_url":"https://github.com/github/VisualStudio","homepage":"https://visualstudio.github.com","size":26628,"stargazers_count":503,"watchers_count":503,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":204,"mirror_url":null,"open_issues_count":72,"forks":204,"open_issues":72,"watchers":503,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/github/VisualStudio/pulls/502"},"html":{"href":"https://github.com/github/VisualStudio/pull/502"},"issue":{"href":"https://api.github.com/repos/github/VisualStudio/issues/502"},"comments":{"href":"https://api.github.com/repos/github/VisualStudio/issues/502/comments"},"review_comments":{"href":"https://api.github.com/repos/github/VisualStudio/pulls/502/comments"},"review_comment":{"href":"https://api.github.com/repos/github/VisualStudio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/github/VisualStudio/pulls/502/commits"},"statuses":{"href":"https://api.github.com/repos/github/VisualStudio/statuses/220ce431ec773afa419d8e1ca62b2bd955d2f114"}}}}
{"actor":{"display_login":"grokys"}}