Made author optional in changelog message. Fixes #1. Added error handling for github tag API request to handle use case when no tags exist yet. This addresses issue #2.

This commit is contained in:
Corey Butler 2019-09-10 12:26:37 -05:00
parent 63a2889369
commit e011fb10da

View File

@ -32,16 +32,21 @@ async function run() {
return
}
// Check existing for existing tag
// Check for existing tag
const git = new github.GitHub(process.env.INPUT_GITHUB_TOKEN)
const owner = process.env.GITHUB_ACTOR
const repo = process.env.GITHUB_REPOSITORY.split('/').pop()
let tags = await git.repos.listTags({
owner,
repo,
per_page: 100
})
let tags
try {
tags = await git.repos.listTags({
owner,
repo,
per_page: 100
})
} catch (e) {
tags = {}
}
// Check for existance of tag and abort (short circuit) if it already exists.
for (let tag of tags.data) {
@ -71,7 +76,7 @@ async function run() {
head: 'master'
})
tagMsg = changelog.data.commits.map(commit => `**1) ${commit.commit.message}** (${commit.author.login})\n(SHA: ${commit.sha})\n`).join('\n')
tagMsg = changelog.data.commits.map(commit => `**1) ${commit.commit.message}**${commit.hasOwnProperty('author') ? (commit.author.hasOwnProperty('login') ? ' (' + commit.author.login + ')' : '') : ''}\n(SHA: ${commit.sha})\n`).join('\n')
} catch (e) {
core.setFailed(e.message)
return