-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: Add #body-in-changelog option to PR/commit bodies #554
Merged
hubertdeng123
merged 1 commit into
getsentry:master
from
BYK:byk/feat/BODY_IN_CHANGELOG
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { SimpleGit } from 'simple-git'; | ||
import type { SimpleGit } from 'simple-git'; | ||
import { logger } from '../logger'; | ||
|
||
import { getGlobalGitHubConfig } from '../config'; | ||
|
@@ -12,6 +12,7 @@ import { getVersion } from './version'; | |
export const DEFAULT_CHANGELOG_PATH = 'CHANGELOG.md'; | ||
export const DEFAULT_UNRELEASED_TITLE = 'Unreleased'; | ||
export const SKIP_CHANGELOG_MAGIC_WORD = '#skip-changelog'; | ||
export const BODY_IN_CHANGELOG_MAGIC_WORD = '#body-in-changelog'; | ||
const DEFAULT_CHANGESET_BODY = '- No documented changes.'; | ||
const VERSION_HEADER_LEVEL = 2; | ||
const SUBSECTION_HEADER_LEVEL = VERSION_HEADER_LEVEL + 1; | ||
|
@@ -214,8 +215,10 @@ interface Commit { | |
author?: string; | ||
hash: string; | ||
title: string; | ||
body: string; | ||
hasPRinTitle: boolean; | ||
pr: string | null; | ||
prBody?: string | null; | ||
milestone: string | null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this used anywhere? seems like it is always undefined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comes from the spread GitHub API response somewhere in the code. |
||
} | ||
|
||
|
@@ -224,7 +227,7 @@ interface Milestone { | |
description: string | null; | ||
state: 'OPEN' | 'CLOSED'; | ||
} | ||
type MilestoneWithPRs = Milestone & { | ||
type MilestoneWithPRs = Partial<Milestone> & { | ||
prs: PullRequest[]; | ||
}; | ||
|
||
|
@@ -242,6 +245,17 @@ function formatCommit(commit: Commit): string { | |
if (commit.author) { | ||
text = `${text} by @${commit.author}`; | ||
} | ||
let body = ''; | ||
if (commit.prBody?.includes(BODY_IN_CHANGELOG_MAGIC_WORD)) { | ||
body = commit.prBody; | ||
} else if (commit.body.includes(BODY_IN_CHANGELOG_MAGIC_WORD)) { | ||
body = commit.body; | ||
} | ||
body = body.replace(BODY_IN_CHANGELOG_MAGIC_WORD, ''); | ||
if (body) { | ||
text += `\n ${body}`; | ||
} | ||
|
||
return text; | ||
} | ||
|
||
|
@@ -270,20 +284,24 @@ export async function generateChangesetFromGit( | |
continue; | ||
} | ||
|
||
const commit = (commits[hash] = { | ||
const commit = { | ||
hash: hash, | ||
title: gitCommit.title, | ||
body: gitCommit.body, | ||
hasPRinTitle: Boolean(gitCommit.pr), | ||
...githubCommit, | ||
}); | ||
}; | ||
commits[hash] = commit; | ||
|
||
if (!githubCommit) { | ||
missing.push(commit); | ||
} | ||
if (!commit.milestone) { | ||
leftovers.push(commit); | ||
} else { | ||
const milestone = milestones[commit.milestone] || { prs: [] }; | ||
const milestone = milestones[commit.milestone] || { | ||
prs: [] as PullRequest[], | ||
}; | ||
// We _know_ the PR exists as milestones are attached to PRs | ||
milestone.prs.push({ | ||
author: commit.author as string, | ||
|
@@ -296,7 +314,7 @@ export async function generateChangesetFromGit( | |
|
||
if (missing.length > 0) { | ||
logger.warn( | ||
`The following commits were not found on GitHub:`, | ||
'The following commits were not found on GitHub:', | ||
missing.map(commit => `${commit.hash.slice(0, 8)} ${commit.title}`) | ||
); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be expected in the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. This is a "trick case" where it still gets folded up in the associated milestone.
Should probably clarify the text to express this then.