Skip to content

Commit 2785c4f

Browse files
authored
Merge pull request #193 from mattpolzin/feature/189/use-issue-for-pr-description
Populate PR descriptions with GitHub issue context when available
2 parents bd91668 + cc7c631 commit 2785c4f

File tree

12 files changed

+149
-74
lines changed

12 files changed

+149
-74
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% harmony(1) Version 5.6.0 | Harmony User's Guide
1+
% harmony(1) Version 5.7.0 | Harmony User's Guide
22

33
# NAME
44
Harmony - Harmonize with coworkers around GitHub reviewing
@@ -312,7 +312,7 @@ organization.
312312

313313
Running `harmony list <team>` will list the members of the given GitHub Team.
314314

315-
## `pr [--draft] [#label, ...]`
315+
## `pr [--draft] [-i/--into {<branch-name>}] [#label, ...]`
316316
With a branch checked out will reach out to GitHub to determine if there is an
317317
open PR for that branch. If there is a PR, Harmony will print a URI that can be
318318
used to view the PR. If there is not a PR, Harmony will help you create one. New
@@ -328,6 +328,14 @@ editor. If you do not have an `EDITOR` environment variable set, you will still
328328
be able to enter a description from the command line but PR templates are only
329329
supported when an `EDITOR` is specified.
330330

331+
If you are creating a new PR from a branch that refers to a GitHub issue (and
332+
you have GitHub branch parsing enabled in your harmony config) then harmony will
333+
prepend the issue information onto your new PR description in a commented out
334+
block for you to reference or copy into the PR description as needed.
335+
336+
You can specify the branch to merge into via the `--into` CLI argument if you
337+
want to as an alternative to the interactive prompt.
338+
331339
You can also specify any number of labels to apply by prefixing them with '#'.
332340
For example, `harmony pr #backport #bugfix` would create a PR and apply the
333341
`backport` and `bugfix` labels.
@@ -351,6 +359,12 @@ Create a PR for the current branch and add the `urgent` label:
351359
harmony pr #urgent
352360
```
353361

362+
Create a pull request that will merge into the hypothetical pre-existing
363+
`release/2_0` branch:
364+
```shell
365+
harmony pr --into release/2_0
366+
```
367+
354368
## `quick [--bugfix]`
355369
Helps you create a new GitHub issue and a branch to work on that issue all in
356370
one go. The branch name will be structured such that if you have GitHub branch

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let
2727
nodeDependencies = buildNpmPackage {
2828
name = "harmony-npm-deps";
2929
src = ./.;
30-
npmDepsHash = "sha256-jfMZ3ayRV4gNAMdDvPsr4zkPPIM5hb/Mw/Wg00cWXr0=";
30+
npmDepsHash = "sha256-ZVHA0Qr6FPliGTOJ4TZTXVxAOwmg+Z55+kKd7Z1RAyA=";
3131
dontNpmBuild = true;
3232
dontBuild = true;
3333

flake.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

harmony.ipkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package harmony
2-
version = 5.6.0
2+
version = 5.7.0
33
authors = "Mathew Polzin"
44
license = "MIT"
55
brief = "Harmony GitHub collaboration tool"

man/harmony.1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated by Pandoc 3.7.0.2
22
.\"
3-
.TH "harmony" "1" "" "Version 5.6.0" "Harmony User\(cqs Guide"
3+
.TH "harmony" "1" "" "Version 5.7.0" "Harmony User\(cqs Guide"
44
.SH NAME
55
Harmony \- Harmonize with coworkers around GitHub reviewing
66
.SH SYNOPSIS
@@ -380,7 +380,7 @@ configured GitHub organization.
380380
.PP
381381
Running \f[CR]harmony list <team>\f[R] will list the members of the
382382
given GitHub Team.
383-
.SS \f[CR]pr [\-\-draft] [#label, ...]\f[R]
383+
.SS \f[CR]pr [\-\-draft] [\-i/\-\-into {<branch\-name>}] [#label, ...]\f[R]
384384
With a branch checked out will reach out to GitHub to determine if there
385385
is an open PR for that branch.
386386
If there is a PR, Harmony will print a URI that can be used to view the
@@ -401,6 +401,15 @@ If you do not have an \f[CR]EDITOR\f[R] environment variable set, you
401401
will still be able to enter a description from the command line but PR
402402
templates are only supported when an \f[CR]EDITOR\f[R] is specified.
403403
.PP
404+
If you are creating a new PR from a branch that refers to a GitHub issue
405+
(and you have GitHub branch parsing enabled in your harmony config) then
406+
harmony will prepend the issue information onto your new PR description
407+
in a commented out block for you to reference or copy into the PR
408+
description as needed.
409+
.PP
410+
You can specify the branch to merge into via the \f[CR]\-\-into\f[R] CLI
411+
argument if you want to as an alternative to the interactive prompt.
412+
.PP
404413
You can also specify any number of labels to apply by prefixing them
405414
with `#'.
406415
For example, \f[CR]harmony pr #backport #bugfix\f[R] would create a PR
@@ -428,6 +437,13 @@ Create a PR for the current branch and add the \f[CR]urgent\f[R] label:
428437
.EX
429438
harmony pr #urgent
430439
.EE
440+
.PP
441+
Create a pull request that will merge into the hypothetical
442+
pre\-existing \f[CR]release/2_0\f[R] branch:
443+
.IP
444+
.EX
445+
harmony pr \-\-into release/2_0
446+
.EE
431447
.SS \f[CR]quick [\-\-bugfix]\f[R]
432448
Helps you create a new GitHub issue and a branch to work on that issue
433449
all in one go.

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mattpolzin/harmony",
3-
"version": "5.6.0",
3+
"version": "5.7.0",
44
"engines": {
55
"node": ">=18.0.0"
66
},

src/AppVersion.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module AppVersion
44

55
export
66
appVersion : String
7-
appVersion = "5.6.0"
7+
appVersion = "5.7.0"
88

99
export
1010
printVersion : HasIO io => io ()

src/Commands/PullRequest.idr

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Data.Config
66
import Data.Either
77
import Data.Fin.Extra
88
import Data.Fuel
9+
import Data.Issue
910
import Data.List
1011
import Data.List1
1112
import Data.Nat
@@ -265,39 +266,50 @@ convertPRToDraft @{config} pr = do
265266
prId <- getPullRequestGraphQlId config.org config.repo pr.number
266267
markPullRequestDraft prId
267268

268-
parseTitleAndBodyPrefix : Config => (branch : String) -> (String, String)
269-
parseTitleAndBodyPrefix @{config} branch =
269+
githubTitleAndBodyPrefix : Config => Octokit => (branch: String) -> Promise' (String, String)
270+
githubTitleAndBodyPrefix @{config} branch =
271+
case issueNumber of
272+
Nothing => pure ("", "")
273+
Just issue => pure $
274+
(""
275+
, !(issueDescriptionPrefix issue) ++ "\n\n" ++ (relatedToPrefix issue)
276+
)
277+
278+
where
279+
issueNumber : Maybe String
280+
issueNumber = parseGithubIssueNumber branch
281+
282+
relatedToPrefix : String -> String
283+
relatedToPrefix issue = "Related to #\{issue}"
284+
285+
issueDescriptionPrefix : String -> Promise' String
286+
issueDescriptionPrefix issueNumber = do
287+
issue <- getIssue config.org config.repo issueNumber
288+
pure """
289+
<!--
290+
## GitHub Issue
291+
\{issue.title}
292+
--
293+
\{issue.body}
294+
-->
295+
"""
296+
297+
||| The title prefix is to be prepended to the new PR title.
298+
||| The body prefix is to be prepended to the new PR body.
299+
|||
300+
||| The idea in either case is to pass along the information parsed from the
301+
||| branch name to GitHub either via the PR's title or part of its body so that
302+
||| an issue referenced by the branch is tracked in relation to the new PR.
303+
|||
304+
||| If a GitHub issue is found, the body of the GitHub issue is also added
305+
||| (commented out) to the body prefix as additional context.
306+
getTitleAndBodyPrefix : Config => Octokit => (branch : String) -> Promise' (String, String)
307+
getTitleAndBodyPrefix @{config} branch =
270308
case config.branchParsing of
271-
Jira => (fromMaybe "" $ (++ " - ") <$> parseJiraSlug branch, "")
272-
-- ^ Jira slugs become a title prefix
273-
Github => ("", fromMaybe "" $ ("Related to #" ++) <$> parseGithubIssueNumber branch)
274-
-- ^ Github issue numbers become a body prefix
275-
None => ("", "")
276-
277-
namespace TestParseTitlePrefix
278-
testJiraTurnedOff : parseTitleAndBodyPrefix @{Data.Config.simpleDefaults}
279-
"ABCD-1234 - hello"
280-
===
281-
("", "")
282-
testJiraTurnedOff = Refl
283-
284-
-- This one does not reduce very far, but far enough for us to know it is going to parse a Jira prefix if possible
285-
testJiraTurnedOn : parseTitleAndBodyPrefix @{({ branchParsing := Jira } Data.Config.simpleDefaults)}
286-
"ABCD-1234 - hello"
287-
===
288-
(fromMaybe (Delay (fromString ""))
289-
(map (\arg => prim__strAppend arg " - ")
290-
(parseJiraSlug "ABCD-1234 - hello")), "")
291-
testJiraTurnedOn = Refl
292-
293-
-- This one does not reduce very far, but far enough for us to know it is going to parse a Jira prefix if possible
294-
testGithubTurnedOn : parseTitleAndBodyPrefix @{({ branchParsing := Github } Data.Config.simpleDefaults)}
295-
"feature/1234/hi"
296-
===
297-
("", fromMaybe (Delay (fromString ""))
298-
((\arg => fromString "Related to #" ++ arg) <$>
299-
parseGithubIssueNumber (fromString "feature/1234/hi")))
300-
testGithubTurnedOn = Refl
309+
Jira => pure (fromMaybe "" $ (++ " - ") <$> parseJiraSlug branch, "")
310+
-- ^ Jira slugs become a title prefix
311+
Github => githubTitleAndBodyPrefix branch
312+
None => pure ("", "")
301313

302314
export
303315
identifyOrCreatePR : Config => Git => Octokit =>
@@ -382,7 +394,7 @@ identifyOrCreatePR @{config} {isDraft} {intoBranch} branch = do
382394
putStrLn "Creating a new PR for the current branch (\{branch})."
383395
baseBranch <- getBaseBranch
384396

385-
let (titlePrefix, bodyPrefix) = parseTitleAndBodyPrefix branch
397+
(titlePrefix, bodyPrefix) <- getTitleAndBodyPrefix branch
386398

387399
putStrLn "What would you like the title to be?"
388400
putStr titlePrefix

0 commit comments

Comments
 (0)