Skip to content

Commit

Permalink
fix: handle commits with no author info
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Mar 17, 2023
1 parent 94af0c3 commit d47b63a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
33 changes: 21 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28111,28 +28111,31 @@ function buildSubject ({ writeToFile, subject, author, authorUrl, owner, repo })
const prs = []
let output = subject
if (writeToFile) {
const authorLine = author ? ` by [@${author}](${authorUrl})` : ''
if (hasPR) {
const prMatch = subject.match(rePrEnding)
const msgOnly = subject.slice(0, prMatch[0].length * -1)
output = msgOnly.replace(rePrId, (m, prId) => {
prs.push(prId)
return `[#${prId}](https://github.com/${owner}/${repo}/pull/${prId})`
})
output += `*(PR [#${prMatch[1]}](https://github.com/${owner}/${repo}/pull/${prMatch[1]}) by [@${author}](${authorUrl}))*`
output += `*(PR [#${prMatch[1]}](https://github.com/${owner}/${repo}/pull/${prMatch[1]})${authorLine})*`
} else {
output = subject.replace(rePrId, (m, prId) => {
return `[#${prId}](https://github.com/${owner}/${repo}/pull/${prId})`
})
output += ` *(commit by [@${author}](${authorUrl}))*`
if (author) {
output += ` *(commit by [@${author}](${authorUrl}))*`
}
}
} else {
if (hasPR) {
output = subject.replace(rePrEnding, (m, prId) => {
prs.push(prId)
return `*(PR #${prId} by @${author})*`
return author ? `*(PR #${prId} by @${author})*` : `*(PR #${prId})*`
})
} else {
output = `${subject} *(commit by @${author})*`
output = author ? `${subject} *(commit by @${author})*` : subject
}
}
return {
Expand Down Expand Up @@ -28253,17 +28256,17 @@ async function main () {
type: cAst.type.toLowerCase(),
sha: commit.sha,
url: commit.html_url,
author: commit.author.login,
authorUrl: commit.author.html_url
author: _.get(commit, 'author.login'),
authorUrl: _.get(commit, 'author.html_url')
})
for (const note of cAst.notes) {
if (note.title === 'BREAKING CHANGE') {
breakingChanges.push({
sha: commit.sha,
url: commit.html_url,
subject: cAst.subject,
author: commit.author.login,
authorUrl: commit.author.html_url,
author: _.get(commit, 'author.login'),
authorUrl: _.get(commit, 'author.html_url'),
text: note.text
})
}
Expand All @@ -28276,8 +28279,8 @@ async function main () {
subject: commit.commit.message,
sha: commit.sha,
url: commit.html_url,
author: commit.author.login,
authorUrl: commit.author.html_url
author: _.get(commit, 'author.login'),
authorUrl: _.get(commit, 'author.html_url')
})
core.info(`[OK] Commit ${commit.sha} with invalid type, falling back to other - ${commit.commit.message}`)
} else {
Expand Down Expand Up @@ -28388,8 +28391,14 @@ async function main () {
})
const relIssues = _.get(issuesRaw, 'repository.pullRequest.closingIssuesReferences.nodes')
for (const relIssue of relIssues) {
changesFile.push(` - :arrow_lower_right: *${relIssuePrefix} issue [#${relIssue.number}](${relIssue.url}) opened by [@${relIssue.author.login}](${relIssue.author.url})*`)
changesVar.push(` - :arrow_lower_right: *${relIssuePrefix} issue #${relIssue.number} opened by @${relIssue.author.login}*`)
const authorLogin = _.get(relIssue, 'author.login')
if (authorLogin) {
changesFile.push(` - :arrow_lower_right: *${relIssuePrefix} issue [#${relIssue.number}](${relIssue.url}) opened by [@${authorLogin}](${relIssue.author.url})*`)
changesVar.push(` - :arrow_lower_right: *${relIssuePrefix} issue #${relIssue.number} opened by @${authorLogin}*`)
} else {
changesFile.push(` - :arrow_lower_right: *${relIssuePrefix} issue [#${relIssue.number}](${relIssue.url})*`)
changesVar.push(` - :arrow_lower_right: *${relIssuePrefix} issue #${relIssue.number}*`)
}
}
}
}
Expand Down
33 changes: 21 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,31 @@ function buildSubject ({ writeToFile, subject, author, authorUrl, owner, repo })
const prs = []
let output = subject
if (writeToFile) {
const authorLine = author ? ` by [@${author}](${authorUrl})` : ''
if (hasPR) {
const prMatch = subject.match(rePrEnding)
const msgOnly = subject.slice(0, prMatch[0].length * -1)
output = msgOnly.replace(rePrId, (m, prId) => {
prs.push(prId)
return `[#${prId}](https://github.com/${owner}/${repo}/pull/${prId})`
})
output += `*(PR [#${prMatch[1]}](https://github.com/${owner}/${repo}/pull/${prMatch[1]}) by [@${author}](${authorUrl}))*`
output += `*(PR [#${prMatch[1]}](https://github.com/${owner}/${repo}/pull/${prMatch[1]})${authorLine})*`
} else {
output = subject.replace(rePrId, (m, prId) => {
return `[#${prId}](https://github.com/${owner}/${repo}/pull/${prId})`
})
output += ` *(commit by [@${author}](${authorUrl}))*`
if (author) {
output += ` *(commit by [@${author}](${authorUrl}))*`
}
}
} else {
if (hasPR) {
output = subject.replace(rePrEnding, (m, prId) => {
prs.push(prId)
return `*(PR #${prId} by @${author})*`
return author ? `*(PR #${prId} by @${author})*` : `*(PR #${prId})*`
})
} else {
output = `${subject} *(commit by @${author})*`
output = author ? `${subject} *(commit by @${author})*` : subject
}
}
return {
Expand Down Expand Up @@ -168,17 +171,17 @@ async function main () {
type: cAst.type.toLowerCase(),
sha: commit.sha,
url: commit.html_url,
author: commit.author.login,
authorUrl: commit.author.html_url
author: _.get(commit, 'author.login'),
authorUrl: _.get(commit, 'author.html_url')
})
for (const note of cAst.notes) {
if (note.title === 'BREAKING CHANGE') {
breakingChanges.push({
sha: commit.sha,
url: commit.html_url,
subject: cAst.subject,
author: commit.author.login,
authorUrl: commit.author.html_url,
author: _.get(commit, 'author.login'),
authorUrl: _.get(commit, 'author.html_url'),
text: note.text
})
}
Expand All @@ -191,8 +194,8 @@ async function main () {
subject: commit.commit.message,
sha: commit.sha,
url: commit.html_url,
author: commit.author.login,
authorUrl: commit.author.html_url
author: _.get(commit, 'author.login'),
authorUrl: _.get(commit, 'author.html_url')
})
core.info(`[OK] Commit ${commit.sha} with invalid type, falling back to other - ${commit.commit.message}`)
} else {
Expand Down Expand Up @@ -303,8 +306,14 @@ async function main () {
})
const relIssues = _.get(issuesRaw, 'repository.pullRequest.closingIssuesReferences.nodes')
for (const relIssue of relIssues) {
changesFile.push(` - :arrow_lower_right: *${relIssuePrefix} issue [#${relIssue.number}](${relIssue.url}) opened by [@${relIssue.author.login}](${relIssue.author.url})*`)
changesVar.push(` - :arrow_lower_right: *${relIssuePrefix} issue #${relIssue.number} opened by @${relIssue.author.login}*`)
const authorLogin = _.get(relIssue, 'author.login')
if (authorLogin) {
changesFile.push(` - :arrow_lower_right: *${relIssuePrefix} issue [#${relIssue.number}](${relIssue.url}) opened by [@${authorLogin}](${relIssue.author.url})*`)
changesVar.push(` - :arrow_lower_right: *${relIssuePrefix} issue #${relIssue.number} opened by @${authorLogin}*`)
} else {
changesFile.push(` - :arrow_lower_right: *${relIssuePrefix} issue [#${relIssue.number}](${relIssue.url})*`)
changesVar.push(` - :arrow_lower_right: *${relIssuePrefix} issue #${relIssue.number}*`)
}
}
}
}
Expand Down

0 comments on commit d47b63a

Please sign in to comment.