Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: create PR for fork
Browse files Browse the repository at this point in the history
This implements a more complex pull request creation strategy which enables creating pull requests

in forked repositories.

ISSUES CLOSED: #58
  • Loading branch information
KnisterPeter committed Feb 15, 2017
1 parent 8c08802 commit d1e3794
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@
"title": "Set Personal Access Token...",
"category": "GitHub"
},
{
"command": "extension.createSimplePullRequest",
"title": "Create pull request from current branch (quick)",
"category": "GitHub"
},
{
"command": "extension.createPullRequest",
"title": "Create pull request from current branch",
"title": "Create pull request...",
"category": "GitHub"
},
{
Expand Down
29 changes: 29 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Extension {

context.subscriptions.push(
vscode.commands.registerCommand('extension.setGitHubToken', this.createGithubTokenCommand(context)),
vscode.commands.registerCommand('extension.createSimplePullRequest',
this.wrapCommand(this.createSimplePullRequest)),
vscode.commands.registerCommand('extension.createPullRequest', this.wrapCommand(this.createPullRequest)),
vscode.commands.registerCommand('extension.checkoutPullRequests', this.wrapCommand(this.checkoutPullRequests)),
vscode.commands.registerCommand('extension.browserPullRequest', this.wrapCommand(this.browserPullRequest)),
Expand Down Expand Up @@ -99,7 +101,34 @@ class Extension {
};
}

private async createSimplePullRequest(): Promise<void> {
const pullRequest = await this.githubManager.createPullRequest();
if (pullRequest) {
this.statusBarManager.updateStatus();
vscode.window.showInformationMessage(`Successfully created #${pullRequest.number}`);
}
}

private async createPullRequest(): Promise<void> {
const repository = await this.githubManager.getRepository();
if (repository.parent) {
const items = [{
label: repository.full_name,
description: ''
}, {
label: repository.parent.full_name,
description: ''
}];
const selectedRepository = await vscode.window.showQuickPick(items);
if (selectedRepository) {
console.log(selectedRepository);
}
}
const [owner, repo] = await git.getGitHubOwnerAndRepository(this.cwd);
console.log('o', owner, 'repo', repo);
if (1 + 1 === 2) {
return;
}
const pullRequest = await this.githubManager.createPullRequest();
if (pullRequest) {
this.statusBarManager.updateStatus();
Expand Down
19 changes: 11 additions & 8 deletions src/github-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';

import * as git from './git';
import {getClient, GitHub, GitHubError, PullRequest, ListPullRequestsParameters, CreatePullRequestBody,
PullRequestStatus, Merge, MergeMethod} from './github';
PullRequestStatus, Merge, MergeMethod, Repository} from './github';

export class GitHubManager {

Expand Down Expand Up @@ -30,22 +30,25 @@ export class GitHubManager {
this.github = getClient(token);
}

public async getDefaultBranch(): Promise<string> {
public async getRepository(): Promise<Repository> {
const [owner, repository] = await git.getGitHubOwnerAndRepository(this.cwd);
return (await this.github.getRepository(owner, repository)).body.default_branch;
return (await this.github.getRepository(owner, repository)).body;
}

public async getDefaultBranch(): Promise<string> {
return (await this.getRepository()).default_branch;
}

public async getEnabledMergeMethods(): Promise<Set<MergeMethod>> {
const [owner, repository] = await git.getGitHubOwnerAndRepository(this.cwd);
const repo = await this.github.getRepository(owner, repository);
const repo = await this.getRepository();
const set = new Set();
if (repo.body.allow_merge_commit) {
if (repo.allow_merge_commit) {
set.add('merge');
}
if (repo.body.allow_squash_merge) {
if (repo.allow_squash_merge) {
set.add('squash');
}
if (repo.body.allow_rebase_merge) {
if (repo.allow_rebase_merge) {
set.add('rebase');
}
return set;
Expand Down
5 changes: 5 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ export interface GitHubResponse<T> {
}

export interface Repository {
full_name: string;
default_branch: string;
allow_rebase_merge: boolean;
allow_squash_merge: boolean;
allow_merge_commit: boolean;
parent?: {
full_name: string;
default_branch: string;
};
}

export type MergeMethod = 'merge' | 'squash' | 'rebase';
Expand Down

0 comments on commit d1e3794

Please sign in to comment.