Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR support #3

Open
wants to merge 5 commits into
base: feature/change-master-branch
Choose a base branch
from

Conversation

greglockwood
Copy link
Owner

@greglockwood greglockwood commented Jan 9, 2021

PR Description
realyze#30 Added ability to customise the base branch
👉 #3 Draft PR support
#4 Cater for body being nullish or empty
#5 Putting the table back in 'table of contents'!
#6 Added support to print links to PRs in terminal
#7 Work when remote URL doesn't have .git suffix
realyze#31 [combined branch]

Which problem does this PR solve?

I personally have found that the PRs created by pr-train are often not ready to be seen by others on the team yet.

I regularly find myself having to add the following:

  • A good PR description (aside from the ToC)
  • A common pre-amble for each PR in the chain to provide context for the entire chain of changes
  • A self-review to explain my thinking in some places
  • Hand-picked reviewers

Thus, utilizing the ability to create draft PRs, which suppress notifications to code owners and others via Slack/email is handy until I have added all those details.

I would go so far as to say that I wish for the tool to always create draft PRs unless I override this behaviour.

Main changes

Added a command-line option, --draft, to create PRs in draft mode.

Added a prs.draft-by-default setting to the .pr-train.yml config file to enable draft PRs to be the default. In this case, the command-line option becomes --no-draft to override the default behaviour on a per-command basis.

Related documents/resources

Create a pull request GitHub REST API docs.

Suggested CR ordering of files?

  1. cfg_template.yml
  2. README.md
  3. github.js
  4. index.js

How I tested it works

I tested the following scenarios:

  1. No draft-by-default setting in config file, no --draft command-line flag set. PRs created in non-draft status, maintaining the current behaviour.
  2. draft-by-default: true setting in config file, no --draft command-line flag set. PRs created in draft status, which is correct.
  3. draft-by-default: true setting in config file, --no-draft command-line flag set. PRs created in non-draft status, which is correct.
  4. No draft-by-default setting in config file, --draft command-line flag set. PRs created in draft status, which is correct.

cfg_template.yml Outdated
# Create new PRs in draft mode by default. This will prevent them from notifying anybody
# until you are ready. This option can be overridden on the command line using the
# -d/--draft or --no-draft options, which set draft mode to true or false, respectively.
draft-by-default: true
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be commented out by default?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...I leaning towards yes, commented out by default? I personally don't use draft PRs much - I just don't assign reviewers until the PR is ready.

@@ -130,7 +135,7 @@ function getBranchesInCurrentTrain(branchConfig) {
*/
function getCombinedBranch(branchConfig) {
const combinedBranch = /** @type {Object<string, {combined: boolean}>} */ branchConfig.find(cfg => {
if (typeof cfg === 'string') {
if (!cfg || typeof cfg === 'string') {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfg can be nullish if you make the mistake (as I did) of not indenting the combined: true line for the combined branch.

Copy link
Collaborator

@realyze realyze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @greglockwood ! I just left a few questions to clarify before we can merge.

cfg_template.yml Outdated
# Create new PRs in draft mode by default. This will prevent them from notifying anybody
# until you are ready. This option can be overridden on the command line using the
# -d/--draft or --no-draft options, which set draft mode to true or false, respectively.
draft-by-default: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...I leaning towards yes, commented out by default? I personally don't use draft PRs much - I just don't assign reviewers until the PR is ready.

index.js Outdated
.option('-b, --base <base>', `Specify the base branch to use for the first and combined PRs.`, defaultBase)
.option('-c, --create-prs', 'Create GitHub PRs from your train branches');
.option('-b, --base <base>', `Specify the base branch to use for the first and combined PRs.`, defaultBase);
if (draftByDefault) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's necessary to have this if here? I think it might be better to simply always show all the options (so that the user knows what they can do) - I'd say it's somewhat unusual to change what flags are allowed based on what defaults are set?

@greglockwood greglockwood force-pushed the feature/support-drafts branch from ed49e02 to e83af0e Compare January 18, 2021 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants