diff --git a/action.yml b/action.yml index efdb148..e54f3d6 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: description: 'The name of the base reference' default: '' required: false + reverse: + description: 'Git log is chronological order by default. Set to true to reverse chronological order. ' + default: 'false' + required: false outputs: changelog: description: 'Markdown formatted changelog' diff --git a/changelog.sh b/changelog.sh index 70408f2..1f8f3c2 100755 --- a/changelog.sh +++ b/changelog.sh @@ -4,6 +4,11 @@ set -eou pipefail head_ref=$1 base_ref=$2 repo_url=$3 +extra_flags="" + +if [ "$4" == "true" ]; then + extra_flags='--reverse' +fi # By default a GitHub action checkout is shallow. Get all the tags, branches, # and history. Redirect output to standard error which we can collect in the @@ -20,9 +25,12 @@ then base_ref=$(git rev-list --max-parents=0 HEAD) fi +# Bash quoting will get you. Do not quote the extra_flags. If its null +# we want it to disappear. If you quote it, it will go to git as an "" +# and thats not a valid arg. log=$(git log "${base_ref}...${head_ref}" \ --pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \ - --reverse) + ${extra_flags}) if [ -z "$log" ]; then diff --git a/dist/changelog.sh b/dist/changelog.sh index 70408f2..82150bd 100755 --- a/dist/changelog.sh +++ b/dist/changelog.sh @@ -5,6 +5,11 @@ head_ref=$1 base_ref=$2 repo_url=$3 +reverse = "" +if [ $strval1 != "true" ]; then + reverse = "--reverse" +fi + # By default a GitHub action checkout is shallow. Get all the tags, branches, # and history. Redirect output to standard error which we can collect in the # action. @@ -22,7 +27,7 @@ fi log=$(git log "${base_ref}...${head_ref}" \ --pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \ - --reverse) + ${reverse}) if [ -z "$log" ]; then diff --git a/dist/index.js b/dist/index.js index f46da04..96905a1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7677,6 +7677,7 @@ async function run() { var headRef = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('head-ref') var baseRef = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('base-ref') const myToken = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('myToken') + const reverse = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('reverse') const octokit = new _actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit(myToken) const { owner, repo } = _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.repo const regexp = /^[.A-Za-z0-9_-]*$/ @@ -7708,7 +7709,7 @@ async function run() { regexp.test(headRef) && regexp.test(baseRef) ) { - getChangelog(headRef, baseRef, owner + '/' + repo) + getChangelog(headRef, baseRef, owner + '/' + repo, reverse) } else { (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)( 'Branch names must contain only numbers, strings, underscores, periods, and dashes.' @@ -7719,7 +7720,7 @@ async function run() { } } -async function getChangelog(headRef, baseRef, repoName) { +async function getChangelog(headRef, baseRef, repoName, reverse) { try { let output = '' let err = '' @@ -7736,7 +7737,11 @@ async function getChangelog(headRef, baseRef, repoName) { } options.cwd = './' - await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)(__nccwpck_require__.ab + "changelog.sh", [headRef, baseRef, repoName], options) + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)( + __nccwpck_require__.ab + "changelog.sh", + [headRef, baseRef, repoName, reverse], + options + ) if (output) { console.log( diff --git a/index.js b/index.js index 071c091..b17fefc 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ async function run() { var headRef = getInput('head-ref') var baseRef = getInput('base-ref') const myToken = getInput('myToken') + const reverse = getInput('reverse') const octokit = new getOctokit(myToken) const { owner, repo } = context.repo const regexp = /^[.A-Za-z0-9_-]*$/ @@ -40,7 +41,7 @@ async function run() { regexp.test(headRef) && regexp.test(baseRef) ) { - getChangelog(headRef, baseRef, owner + '/' + repo) + getChangelog(headRef, baseRef, owner + '/' + repo, reverse) } else { setFailed( 'Branch names must contain only numbers, strings, underscores, periods, and dashes.' @@ -51,7 +52,7 @@ async function run() { } } -async function getChangelog(headRef, baseRef, repoName) { +async function getChangelog(headRef, baseRef, repoName, reverse) { try { let output = '' let err = '' @@ -68,7 +69,11 @@ async function getChangelog(headRef, baseRef, repoName) { } options.cwd = './' - await _exec(`${src}/changelog.sh`, [headRef, baseRef, repoName], options) + await _exec( + `${src}/changelog.sh`, + [headRef, baseRef, repoName, reverse], + options + ) if (output) { console.log(