Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Sep 13, 2022
1 parent 71c362e commit 57e8cbc
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 386 deletions.
19 changes: 17 additions & 2 deletions bin/release-please.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ const [branch] = process.argv.slice(2)
const setOutput = (key, val) => {
if (val && (!Array.isArray(val) || val.length)) {
if (dryRun) {
console.log(key, JSON.stringify(val, null, 2))
if (key === 'pr') {
console.log('PR:', val.title.toString())
console.log('='.repeat(40))
console.log(val.body.toString())
console.log('='.repeat(40))
for (const update of val.updates.filter(u => u.updater.changelogEntry)) {
console.log('CHANGELOG:', update.path)
console.log('-'.repeat(40))
console.log(update.updater.changelogEntry)
console.log('-'.repeat(40))
}
}
} else {
core.setOutput(key, JSON.stringify(val))
}
Expand All @@ -27,5 +38,9 @@ main({
setOutput('release', release)
return null
}).catch(err => {
core.setFailed(`failed: ${err}`)
if (dryRun) {
console.error(err)
} else {
core.setFailed(`failed: ${err}`)
}
})
25 changes: 9 additions & 16 deletions lib/release-please/changelog.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const makeGh = require('./github.js')
const saveFixture = require('./save-fixture.js')
const { link, code, specRe, list } = require('./util')
const { link, code, specRe, list, dateFmt } = require('./util')

module.exports = class ChangelogNotes {
constructor (options) {
this.gh = makeGh(options.github)
}

buildEntry (commit, authors) {
buildEntry (commit, authors = []) {
const breaking = commit.notes
.filter(n => n.title === 'BREAKING CHANGE')
.map(n => n.text)

const entry = []

// A link to the commit
entry.push(link(code(commit.sha.slice(0, 7)), this.gh.commit(commit.sha)))
if (commit.sha) {
// A link to the commit
entry.push(link(code(commit.sha.slice(0, 7)), this.gh.commit(commit.sha)))
}

// A link to the pull request if the commit has one
const prNumber = commit.pullRequest && commit.pullRequest.number
Expand All @@ -40,14 +41,6 @@ module.exports = class ChangelogNotes {
}

async buildNotes (rawCommits, { version, previousTag, currentTag, changelogSections }) {
await saveFixture(`changelog-${currentTag}`, {
commits: rawCommits,
version,
previousTag,
currentTag,
changelogSections,
})

const changelog = changelogSections.reduce((acc, c) => {
if (!c.hidden) {
acc[c.type] = {
Expand All @@ -58,7 +51,7 @@ module.exports = class ChangelogNotes {
return acc
}, {
breaking: {
title: 'BREAKING CHANGES',
title: '⚠️ BREAKING CHANGES',
entries: [],
},
})
Expand All @@ -83,8 +76,8 @@ module.exports = class ChangelogNotes {
.filter((s) => s.entries.length)
.map(({ title, entries }) => [`### ${title}`, entries.map(list).join('\n')].join('\n\n'))

const changelogTitle = this.gh.title(version, currentTag, previousTag)
const title = `## ${link(version, this.gh.compare(previousTag, currentTag))} (${dateFmt()})`

return [changelogTitle, ...sections].join('\n\n').trim()
return [title, ...sections].join('\n\n').trim()
}
}
86 changes: 39 additions & 47 deletions lib/release-please/github.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
const { link, dateFmt } = require('./util')

module.exports = (gh) => {
return {
...gh,
authors: ghAuthors(gh),
...format(gh),
}
}
const { owner, repo } = gh.repository

const format = (gh) => {
const base = `https://github.com/${gh.repository.owner}/${gh.repository.repo}`
const url = (...p) => `${base}/${p.join('/')}`
const compare = (prev, current) => url('compare', prev, '...', current)
return {
pull: (number) => url('pull', number),
compare: compare,
commit: (sha) => url('commit', sha),
release: (tag) => url('releases', 'tag', tag),
title: (version, currentTag, previousTag) =>
`## ${link(version, previousTag && compare(previousTag, currentTag))} (${dateFmt()})`,
tag: (component, version) => [component, `v${version.toString()}`].filter(Boolean).join('-'),
}
}
const authors = async (commits) => {
const response = {}

const ghAuthors = (gh) => async (commits) => {
const response = {}
const shas = commits.map(c => c.sha).filter(Boolean)

if (!commits.length) {
return response
}
if (!shas.length) {
return response
}

const { repository } = await gh.graphql(
`fragment CommitAuthors on GitObject {
... on Commit {
authors (first:10) {
nodes {
user { login }
name
const { repository } = await gh.graphql(
`fragment CommitAuthors on GitObject {
... on Commit {
authors (first:10) {
nodes {
user { login }
name
}
}
}
}
}
query {
repository (owner:"${gh.repository.owner}", name:"${gh.repository.repo}") {
${commits.map(({ sha: s }) => {
return `_${s}: object (expression: "${s}") { ...CommitAuthors }`
})}
query {
repository (owner:"${owner}", name:"${repo}") {
${shas.map((s) => {
return `_${s}: object (expression: "${s}") { ...CommitAuthors }`
})}
}
}`
)

for (const [key, commit] of Object.entries(repository)) {
if (commit) {
response[key.slice(1)] = commit.authors.nodes
.map((a) => a.user && a.user.login ? `@${a.user.login}` : a.name)
.filter(Boolean)
}
}`
)
}

for (const [sha, commit] of Object.entries(repository)) {
response[sha.slice(1)] = commit.authors.nodes
.map((a) => a.user && a.user.login ? `@${a.user.login}` : a.name)
.filter(Boolean)
return response
}

return response
const url = (...p) => `https://github.com/${owner}/${repo}/${p.join('/')}`

return {
authors,
pull: (number) => url('pull', number),
commit: (sha) => url('commit', sha),
compare: (a, b) => a ? url('compare', `${a.toString()}...${b.toString()}`) : null,
}
}
2 changes: 2 additions & 0 deletions lib/release-please/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const RP = require('release-please')
const { CheckpointLogger } = require('release-please/build/src/util/logger.js')
const { ManifestPlugin } = require('release-please/build/src/plugin.js')
const ChangelogNotes = require('./changelog.js')
const Version = require('./version.js')
const NodeWs = require('./node-workspace.js')
Expand All @@ -8,6 +9,7 @@ RP.setLogger(new CheckpointLogger(true, true))
RP.registerChangelogNotes('default', (o) => new ChangelogNotes(o))
RP.registerVersioningStrategy('default', (o) => new Version(o))
RP.registerPlugin('node-workspace', (o) => new NodeWs(o.github, o.targetBranch, o.repositoryConfig))
RP.registerPlugin('workspace-deps', () => new ManifestPlugin())

const main = async ({ repo: fullRepo, token, dryRun, branch }) => {
if (!token) {
Expand Down

0 comments on commit 57e8cbc

Please sign in to comment.