Skip to content

Commit

Permalink
Add changelogs option
Browse files Browse the repository at this point in the history
  • Loading branch information
Obi-Dann committed Apr 13, 2021
1 parent 351390f commit 79000a1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 39 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
required: true
path:
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
changelogs:
description: >
Controls whether to fetch release notes from updated dependencies
default: true
runs:
using: 'node12'
main: 'dist/index.js'
39 changes: 26 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/fetchChangelogs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {getManagerConfig, RenovateConfig} from 'renovate/dist/config'
import {getChangeLogJSON} from 'renovate/dist/workers/pr/changelog'
import {UpdatedDependency, UpdatedDependencyWithChangelog} from './types'
import {UpdatedDependency} from './types'

export async function fetchChangelogs(
config: RenovateConfig,
dependencies: UpdatedDependency[]
): Promise<UpdatedDependencyWithChangelog[]> {
const result: UpdatedDependencyWithChangelog[] = []
): Promise<UpdatedDependency[]> {
const result: UpdatedDependency[] = []
for (const updatedDependency of dependencies) {
const {dependency, update, manager} = updatedDependency
const logJSON = await getChangeLogJSON({
Expand All @@ -16,7 +16,7 @@ export async function fetchChangelogs(
...update
})

result.push({...updatedDependency, changelog: logJSON})
result.push({...updatedDependency, changelog: logJSON ?? undefined})
}

return result
Expand Down
26 changes: 16 additions & 10 deletions src/getPrCommentBody.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import {PackageDependency} from 'renovate/dist/manager/types'
import {ChangeLogResult} from 'renovate/dist/workers/pr/changelog'
import {sanitizeMarkdown} from 'renovate/dist/util/markdown'
import {UpdatedDependencyWithChangelog} from './types'
import {UpdatedDependency} from './types'

export const commentTitle = '# Dependency updates summary'
const footer =
'\n---\n\nThis comment content is generated by [Renovate Bot](/~https://github.com/renovatebot/renovate)'

export function getPrCommentBody(
dependencies: UpdatedDependencyWithChangelog[]
): string {
export function getPrCommentBody(dependencies: UpdatedDependency[]): string {
const anyChangeLogs = dependencies.some(x => x.changelog)
const content = dependencies.map(getDependencyChangeContent)

const releaseNotes = anyChangeLogs
? `
---
### Release notes
${content.map(x => x.changelog).join('\n\n')}
`
: ''

return `${commentTitle}
This PR contains the following updates:
<table>
Expand All @@ -19,10 +28,7 @@ ${content.map(x => x.tableRow).join('\n\n')}
</table>
---
### Release notes
${content.map(x => x.changelog).join('\n\n')}
${releaseNotes}
${footer}`
}
Expand All @@ -31,7 +37,7 @@ function getDependencyChangeContent({
dependency,
update,
changelog
}: UpdatedDependencyWithChangelog): {tableRow: string; changelog: string} {
}: UpdatedDependency): {tableRow: string; changelog: string} {
const dependencyLink = getDependencyNameLinked(dependency)
const type = dependency.prettyDepType ?? dependency.depType
const from = update.displayFrom ?? update.currentVersion
Expand All @@ -53,7 +59,7 @@ function getDependencyChangeContent({

function getReleaseNotes(
dependencyLink: string,
changelog: ChangeLogResult | null
changelog: ChangeLogResult | undefined
): string {
const releases =
changelog?.versions?.map(x => {
Expand Down
16 changes: 9 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function run(): Promise<void> {
core.info(`Looking for all dependencies in head`)
const headDependencies = await extractAllDependencies(config)

const updatedDependencies = [
let updatedDependencies = [
...getUpdatedDependencies(baseDependencies, headDependencies)
]

Expand All @@ -49,16 +49,18 @@ async function run(): Promise<void> {
return
}

const changelogs = core.getInput('changelogs') === 'true'

if (typeof pullRequestNumber !== 'number') {
return
}
core.info(`Fetching changelogs...`)

const updatedDependenciesWithChangelogs = await fetchChangelogs(
config,
updatedDependencies
)
const commentBody = getPrCommentBody(updatedDependenciesWithChangelogs)
if (changelogs) {
core.info(`Fetching changelogs...`)
updatedDependencies = await fetchChangelogs(config, updatedDependencies)
}

const commentBody = getPrCommentBody(updatedDependencies)

const github = getOctokit(token)

Expand Down
5 changes: 1 addition & 4 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ export interface UpdatedDependency {
packageFile: PackageFile
dependency: PackageDependency<Record<string, unknown>>
update: LookupUpdate
}

export interface UpdatedDependencyWithChangelog extends UpdatedDependency {
changelog: ChangeLogResult | null
changelog?: ChangeLogResult
}

0 comments on commit 79000a1

Please sign in to comment.