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

Commit

Permalink
feat(pull-request): open editor when description is empty
Browse files Browse the repository at this point in the history
This will open user's editor when they submit a new pr and
leave the --description or --title empty

re #34
  • Loading branch information
Ryan Garant committed Nov 4, 2019
1 parent 6892014 commit 68c55b1
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/cmds/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { startsWith } from 'lodash'
import * as marked from 'marked'
import { produce } from 'immer'
import * as TerminalRenderer from 'marked-terminal'
import { openUrl, userRanValidFlags } from '../utils'
import { openUrl, userRanValidFlags, userLeftMsgEmpty, openFileInEditor } from '../utils'
import * as wrap from 'wordwrap'
import * as git from '../git'

Expand Down Expand Up @@ -821,35 +821,50 @@ function sortPullsByComplexity_(pulls, direction) {
}

async function submit(options, user) {
let description = options.description
let title = options.title
let pullBranch = options.pullBranch || options.currentBranch

if (testing) {
pullBranch = 'test'
}

git.push(options.config.default_remote, pullBranch)
if (userLeftMsgEmpty(title)) {
title = openFileInEditor(
'temp-gh-pr-title.txt',
`# Add a issue title message on the next line\n${git.getLastCommitMessage(pullBranch)}`
)
}

// If user passes an empty title and description, --description will get merged into options.title
// Need to reference the original title not the potentially modified one
if (userLeftMsgEmpty(options.title) || userLeftMsgEmpty(description)) {
description = openFileInEditor(
'temp-gh-pr-body.md',
'<!-- Add an pr body message in markdown format below -->'
)
}

var payload: any = {
const payload: any = {
mediaType: {
previews: ['shadow-cat'],
},
owner: user,
base: options.branch,
head: `${options.user}:${pullBranch}`,
repo: options.repo,
title: title,
...(options.issue ? { issue: options.issue } : {}),
...(options.draft ? { draft: options.draft } : {}),
...(options.description ? { body: options.description } : {}),
}

try {
if (options.issue) {
payload.issue = options.issue
var { data } = await options.GitHub.pulls.createFromIssue(payload)
} else {
payload.title = options.title || git.getLastCommitMessage(pullBranch)
git.push(options.config.default_remote, pullBranch)

var { data } = await options.GitHub.pulls.create(payload)
}
const method = payload.issue ? 'createFromIssue' : 'create'

var { data } = await options.GitHub.pulls[method](payload)
} catch (err) {
var { originalError, pull } = await checkPullRequestIntegrity_(options, err)

Expand Down

0 comments on commit 68c55b1

Please sign in to comment.