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

Commit

Permalink
feat: allow pr body input via dialog or git editor (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanderweele authored and KnisterPeter committed Jan 9, 2017
1 parent 1e3aec1 commit f3e126e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Current it is possible to do the following:
* Checkout one of the open pull requests
* Browse one of the open pull requests in your default browser
* Display pull request and current status (e.g. mergeable, travis build done, ...) in the StatusBar
* Create a new pull request based on the current branch and the last commit
The current branch will be requested to merge into master and the pull request title is the commit message summary.
* Merge current pull rqeuest with either of 'merge', 'squash' or 'rebase' method.
* Create a new pull request based on the current branch and the last commit
The current branch will be requested to merge into master and the pull request title is the commit message summary, or a custom message if configured that way.
* Merge current pull request with either of 'merge', 'squash' or 'rebase' method.
* Configure default branch, merge method and refresh interval.

![Create pull request](images/create-pull-request.png)
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
"github.upstream": {
"type": "string",
"description": "By default the extension get the repository and user from .git/config. For forks where upstream is a different repository this could be configured here (e.g. microsoft/typescript)."
},
"github.customPullRequestDescription": {
"type": "string",
"enum": [
"off",
"singleLine",
"gitEditor"
],
"default": "off",
"description": "By default the pull request description is the first commit message. When this property is set, the user is asked for a description when creating the PR. This can be a single-line description via an input dialog ('singleLine') or a multi-line markdown description via the editor configured in git ('gitEditor')."
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Extension {

private async checkVersionAndToken(context: vscode.ExtensionContext, token: string|undefined): Promise<void> {
const content = await sander.readFile(join(context.extensionPath, 'package.json'));
const version = JSON.parse(content).version as string;
const version = JSON.parse(content.toString()).version as string;
const storedVersion = context.globalState.get<string|undefined>('version-test');
if (version !== storedVersion && !Boolean(token)) {
context.globalState.update('version-test', version);
Expand Down
33 changes: 33 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as execa from 'execa';
import { resolve } from 'path';
import { readFile, unlink } from 'sander';
import { parse } from 'url';
import * as vscode from 'vscode';

Expand Down Expand Up @@ -63,3 +65,34 @@ export async function getCommitBody(sha: string, cwd: string): Promise<string> {
export async function checkout(cwd: string, branch: string): Promise<void> {
await execa('git', ['checkout', branch], {cwd});
}

export async function getPullRequestBody(sha: string, cwd: string): Promise<string> {
const bodyMethod = vscode.workspace.getConfiguration('github').get<string>('customPullRequestDescription');

switch (bodyMethod) {
case 'singleLine':
return getSingleLinePullRequestBody();
case 'gitEditor':
return getGitEditorPullRequestBody(cwd);
case 'off':
default:
return getCommitBody(sha, cwd);
}
}

async function getSingleLinePullRequestBody(): Promise<string> {
return await vscode.window.showInputBox({prompt: 'Pull request description'});
}

async function getGitEditorPullRequestBody(cwd: string): Promise<string> {
const path = resolve(cwd, 'PR_EDITMSG');

const [editorName, ...params] = (await execa('git', ['config', '--get', 'core.editor'])).stdout.split(' ');
await execa(editorName, [...params, path]);

const fileContents = (await readFile(path)).toString();

await unlink(path);

return fileContents;
}
2 changes: 1 addition & 1 deletion src/github-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class GitHubManager {
title: await git.getCommitMessage(firstCommit, this.cwd),
head: `${owner}:${branch}`,
base: await this.getDefaultBranch(),
body: await git.getCommitBody(firstCommit, this.cwd)
body: await git.getPullRequestBody(firstCommit, this.cwd)
};
this.channel.appendLine('Create pull request:');
this.channel.appendLine(JSON.stringify(body, undefined, ' '));
Expand Down
3 changes: 2 additions & 1 deletion typings/sander.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
declare module 'sander' {
export function readFile(path: string): Promise<string>;
export function readFile(path: string): Promise<Buffer>;
export function unlink(path: string): Promise<undefined>;
}

0 comments on commit f3e126e

Please sign in to comment.