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

Commit

Permalink
feat: display only enabled merge methods (#23)
Browse files Browse the repository at this point in the history
Ask github about enabled merge methods

ISSUES CLOSED: #21
  • Loading branch information
KnisterPeter authored Nov 18, 2016
1 parent 693da3f commit b1ef991
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,36 @@ class Extension {
});
}

private async getMergeMethdod(): Promise<MergeMethod> {
if (vscode.workspace.getConfiguration('github').has('preferedMergeMethod')) {
return vscode.workspace.getConfiguration('github').get<MergeMethod>('preferedMergeMethod');
private async getMergeMethdod(): Promise<MergeMethod|undefined> {
const preferedMethod = vscode.workspace.getConfiguration('github').get<MergeMethod>('preferedMergeMethod');
if (preferedMethod) {
return preferedMethod;
}
const items: MergeOptionItems[] = [
{
const items: MergeOptionItems[] = [];
const enabledMethods = await this.githubManager.getEnabledMergeMethods();
if (enabledMethods.has('merge')) {
items.push({
label: 'Create merge commit',
description: '',
method: 'merge'
},
{
});
}
if (enabledMethods.has('squash')) {
items.push({
label: 'Squash and merge',
description: '',
method: 'squash'
},
{
});
}
if (enabledMethods.has('rebase')) {
items.push({
label: 'Rebase and merge',
description: '',
method: 'rebase'
}
];
return (await vscode.window.showQuickPick(items)).method;
});
}
const selected = await vscode.window.showQuickPick(items);
return selected ? selected.method : undefined;
}

private async mergePullRequest(): Promise<void> {
Expand Down
16 changes: 16 additions & 0 deletions src/github-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ export class GitHubManager {
return (await this.github.getRepository(owner, repository)).body.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 set = new Set();
if (repo.body.allow_merge_commit) {
set.add('merge');
}
if (repo.body.allow_squash_merge) {
set.add('squash');
}
if (repo.body.allow_rebase_merge) {
set.add('rebase');
}
return set;
}

public async getPullRequestForCurrentBranch(): Promise<PullRequest|undefined> {
const [owner, repository] = await git.getGitHubOwnerAndRepository(this.cwd);
const branch = await git.getCurrentBranch(this.cwd);
Expand Down
4 changes: 4 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export interface GitHubResponse<T> {

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

export type MergeMethod = 'merge' | 'squash' | 'rebase';
Expand Down Expand Up @@ -166,6 +169,7 @@ namespace impl {

export class GitHubBlueprint implements GitHub {

@Headers('Accept: application/vnd.github.polaris-preview')
@Get('/repos/:owner/:repo')
public getRepository(_owner: string, _repo: string): any {/* */}

Expand Down

0 comments on commit b1ef991

Please sign in to comment.