Refined-github: Use first commit for PR title and description

Created on 9 Jul 2020  Â·  6Comments  Â·  Source: sindresorhus/refined-github

If your branch has just one commit, then GitHub will use that commit message as the PR title and description, which is nice.

However, if your branch has more than one commit, then GitHub uses the branch name as the PR title and leaves the description blank.

I would rather GitHub always use the first commit in a PR branch as the PR title and description.

Example URL: https://github.com/zachwhaley/squashed-merge-message/compare/pr-title-example?expand=1

Screenshots:

Current:
Screen Shot 2020-07-09 at 11 03 29 AM

Desired:
Screen Shot 2020-07-09 at 11 03 59 AM

enhancement help wanted

All 6 comments

I don’t think that the first commit (of many) is consistently descriptive of of whole PR; sometimes it is, sometimes it isn’t.

@fregante but it's better then the branch name

I don’t think that the first commit (of many) is consistently descriptive of of whole PR; sometimes it is, sometimes it isn’t.

For me this fits with my workflow where my first commit has a good message and all, but then I often keep testing and make smaller fixup commits. Since I use Squashed merges I find it easier to just add basic commits instead of using --amend or --rebase.

I know for some, this might go against their workflow as they might fine tune a list of commits, but I figured it was worth adding a suggestion :)

POC https://github.com/yakov116/refined-github/tree/pr-parent-commit


Details

This does the trick

import select from 'select-dom';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
import * as textFieldEdit from 'text-field-edit';

import features from '.';
import {looseParseInt} from '../github-helpers';

async function init(): Promise<void | false> {
const commitCount = await elementReady<HTMLElement>('.overall-summary > ul > li:nth-child(1) .text-emphasized')!;

if (looseParseInt(commitCount?.textContent!) < 2) {
return false;
}

const [prTitle, ...prMessage] = select('#commits_bucket .commit-message code a')!.title.split(/\n\n/);

textFieldEdit.set(
select<HTMLInputElement>('.discussion-topic-header input')!,
prTitle
);
textFieldEdit.insert(
select<HTMLTextAreaElement>('#new_pull_request textArea[aria-label="Comment body"]')!,
prMessage.join('\n\n')
);
}

void features.add({
id: __filebasename,
description: 'Sync a new pr message when there is more then one commit.',
screenshot: ''
}, {
include: [
pageDetect.isCompare
],
waitForDomReady: false,
init
});

@fregante what would the feature be called?

Not to beat a dead horse or anything, but just want to throw this out there: @zachwhaley's described workflow is the exact opposite of mine. My branches tend to look like:

A tiny fix for something I noticed while working
A small refactor that will make my feature easier
Setting up the foundation for my feature
✨The Feature!✨

So for me, the _last_ commit message tends to be a better descriptor for my PR's.

Not sure this is true for anyone else or if I'm the odd man out, but I wanted to throw it out there in case there are others like me. Either way, it's easy enough to just disable this option for me, and thank you all for the excellent project, it makes a huge difference in my day-to-day. 🙇🙇🙇

Was this page helpful?
0 / 5 - 0 ratings