From a3bf91404fcf168eb81f194fdbfa79482e915cda Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 09:30:55 -0500 Subject: [PATCH 1/7] Add some logging --- dist/index.js | 2 ++ index.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index 95129b7..83f69a1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -559,6 +559,7 @@ async function run() { if (usePr) { let branch = core.getInput('branch_name') || `changelog-${tag}`; + console.log(brach); try { await octokit.git.createRef({ owner, @@ -568,6 +569,7 @@ async function run() { }); options.branch = branch; } catch (e) { + console.log(e); core.error(`Failed creating changelog PR: ${e}`); return; } diff --git a/index.js b/index.js index 2cae308..fdeb1d7 100644 --- a/index.js +++ b/index.js @@ -65,6 +65,7 @@ async function run() { if (usePr) { let branch = core.getInput('branch_name') || `changelog-${tag}`; + console.log(brach); try { await octokit.git.createRef({ owner, @@ -74,6 +75,7 @@ async function run() { }); options.branch = branch; } catch (e) { + console.log(e); core.error(`Failed creating changelog PR: ${e}`); return; } From 9e6eddc749a88d8eda5b45123eac920032652f5c Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 09:33:25 -0500 Subject: [PATCH 2/7] Fix typo --- dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 83f69a1..8feafbb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -559,7 +559,7 @@ async function run() { if (usePr) { let branch = core.getInput('branch_name') || `changelog-${tag}`; - console.log(brach); + console.log(branch); try { await octokit.git.createRef({ owner, diff --git a/index.js b/index.js index fdeb1d7..c18c285 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,7 @@ async function run() { if (usePr) { let branch = core.getInput('branch_name') || `changelog-${tag}`; - console.log(brach); + console.log(branch); try { await octokit.git.createRef({ owner, From 81d4ec0298ce6a974aa9c66df567fccd2cbc9f35 Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 09:48:33 -0500 Subject: [PATCH 3/7] More attemps at randomly fixing things --- dist/index.js | 27 +++++++++++++++++++++------ index.js | 27 +++++++++++++++++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8feafbb..cfb2490 100644 --- a/dist/index.js +++ b/dist/index.js @@ -537,7 +537,7 @@ async function run() { changelogExists = false; } - let { url, tag, name, body } = getReleaseData(eventPath); + let { url, tag, name, body, releaseBranch } = getReleaseData(eventPath); let newContents = `### [${name}](${url}) ${NEWLINE} **${tag}** ${NEWLINE} ${body}` + currentContents; @@ -548,7 +548,7 @@ async function run() { owner, repo, path, - branch: defaultBranch, + branch: releaseBranch, message: `Updated ${path} via Next Release action.`, content }; @@ -557,8 +557,9 @@ async function run() { options.sha = sha; } + let branch = core.getInput('branch_name') || `changelog-${tag}`; + if (usePr) { - let branch = core.getInput('branch_name') || `changelog-${tag}`; console.log(branch); try { await octokit.git.createRef({ @@ -582,16 +583,30 @@ async function run() { } if (usePr) { - await octokit.repo.get(); + await octokit.pulls.create({ + owner, + repo, + head: branch, + base: releaseBranch, + title: `Update ${path}`, + maintainer_can_modify: true, + body: 'Automatically generated by Next Release Changelog Action' + }); } } function getReleaseData(eventPath) { const event = JSON.parse(fs.readFileSync(eventPath, 'utf8')); - let { html_url: url, tag_name: tag, name, body } = event.release; + let { + html_url: url, + tag_name: tag, + name, + body, + target_commitish: releaseBranch + } = event.release; - return { url, tag, name, body }; + return { url, tag, name, body, releaseBranch }; } run(); diff --git a/index.js b/index.js index c18c285..f35f8d3 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ async function run() { changelogExists = false; } - let { url, tag, name, body } = getReleaseData(eventPath); + let { url, tag, name, body, releaseBranch } = getReleaseData(eventPath); let newContents = `### [${name}](${url}) ${NEWLINE} **${tag}** ${NEWLINE} ${body}` + currentContents; @@ -54,7 +54,7 @@ async function run() { owner, repo, path, - branch: defaultBranch, + branch: releaseBranch, message: `Updated ${path} via Next Release action.`, content }; @@ -63,8 +63,9 @@ async function run() { options.sha = sha; } + let branch = core.getInput('branch_name') || `changelog-${tag}`; + if (usePr) { - let branch = core.getInput('branch_name') || `changelog-${tag}`; console.log(branch); try { await octokit.git.createRef({ @@ -88,16 +89,30 @@ async function run() { } if (usePr) { - await octokit.repo.get(); + await octokit.pulls.create({ + owner, + repo, + head: branch, + base: releaseBranch, + title: `Update ${path}`, + maintainer_can_modify: true, + body: 'Automatically generated by Next Release Changelog Action' + }); } } function getReleaseData(eventPath) { const event = JSON.parse(fs.readFileSync(eventPath, 'utf8')); - let { html_url: url, tag_name: tag, name, body } = event.release; + let { + html_url: url, + tag_name: tag, + name, + body, + target_commitish: releaseBranch + } = event.release; - return { url, tag, name, body }; + return { url, tag, name, body, releaseBranch }; } run(); From 60585e71640eff2cc47c1a27a984ea494ea49bfd Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 10:00:14 -0500 Subject: [PATCH 4/7] try creating branch from latest ref --- dist/index.js | 16 +++++++++++++++- index.js | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index cfb2490..0a945de 100644 --- a/dist/index.js +++ b/dist/index.js @@ -561,11 +561,25 @@ async function run() { if (usePr) { console.log(branch); + let refSha; + try { + let { data } = await octokit.git.getRef({ + owner, + repo, + ref: `heads/${releaseBranch}` + }); + + refSha = data.object.sha; + } catch (e) { + core.error(`Error creating changelog PR ${e}`); + return; + } + try { await octokit.git.createRef({ owner, repo, - sha, + sha: refSha, ref: `refs/heads/${branch}` }); options.branch = branch; diff --git a/index.js b/index.js index f35f8d3..3a2f286 100644 --- a/index.js +++ b/index.js @@ -67,11 +67,25 @@ async function run() { if (usePr) { console.log(branch); + let refSha; + try { + let { data } = await octokit.git.getRef({ + owner, + repo, + ref: `heads/${releaseBranch}` + }); + + refSha = data.object.sha; + } catch (e) { + core.error(`Error creating changelog PR ${e}`); + return; + } + try { await octokit.git.createRef({ owner, repo, - sha, + sha: refSha, ref: `refs/heads/${branch}` }); options.branch = branch; From 5b7e82353cda0c4938a15b63b5ea2ad865fc483b Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 10:12:48 -0500 Subject: [PATCH 5/7] Finally get things working --- dist/index.js | 2 -- index.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0a945de..c9f73d2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -560,7 +560,6 @@ async function run() { let branch = core.getInput('branch_name') || `changelog-${tag}`; if (usePr) { - console.log(branch); let refSha; try { let { data } = await octokit.git.getRef({ @@ -584,7 +583,6 @@ async function run() { }); options.branch = branch; } catch (e) { - console.log(e); core.error(`Failed creating changelog PR: ${e}`); return; } diff --git a/index.js b/index.js index 3a2f286..160513f 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,6 @@ async function run() { let branch = core.getInput('branch_name') || `changelog-${tag}`; if (usePr) { - console.log(branch); let refSha; try { let { data } = await octokit.git.getRef({ @@ -90,7 +89,6 @@ async function run() { }); options.branch = branch; } catch (e) { - console.log(e); core.error(`Failed creating changelog PR: ${e}`); return; } From 7ca79355a6f49329a50098fccc76a4334d65cf2a Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 10:16:21 -0500 Subject: [PATCH 6/7] Updated names to make more sense --- action.yml | 2 +- dist/index.js | 16 +++++++++------- index.js | 16 +++++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/action.yml b/action.yml index e39e786..7a04c45 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,7 @@ inputs: description: 'The branch name to use for a pull request for your changelog (If `use_pullrequest` is true)' default_branch: required: false - description: 'The branch name to commit / make pull request against for changelog' + description: 'The branch name to commit / make pull request against for changelog if different than the tagged branch' runs: using: 'node12' diff --git a/dist/index.js b/dist/index.js index c9f73d2..2993487 100644 --- a/dist/index.js +++ b/dist/index.js @@ -539,6 +539,8 @@ async function run() { let { url, tag, name, body, releaseBranch } = getReleaseData(eventPath); + let branch = defaultBranch || releaseBranch; + let newContents = `### [${name}](${url}) ${NEWLINE} **${tag}** ${NEWLINE} ${body}` + currentContents; let buff = new Buffer.from(newContents); @@ -548,7 +550,7 @@ async function run() { owner, repo, path, - branch: releaseBranch, + branch, message: `Updated ${path} via Next Release action.`, content }; @@ -557,7 +559,7 @@ async function run() { options.sha = sha; } - let branch = core.getInput('branch_name') || `changelog-${tag}`; + let prBranch = core.getInput('branch_name') || `changelog-${tag}`; if (usePr) { let refSha; @@ -565,7 +567,7 @@ async function run() { let { data } = await octokit.git.getRef({ owner, repo, - ref: `heads/${releaseBranch}` + ref: `heads/${branch}` }); refSha = data.object.sha; @@ -579,9 +581,9 @@ async function run() { owner, repo, sha: refSha, - ref: `refs/heads/${branch}` + ref: `refs/heads/${prBranch}` }); - options.branch = branch; + options.branch = prBranch; } catch (e) { core.error(`Failed creating changelog PR: ${e}`); return; @@ -598,8 +600,8 @@ async function run() { await octokit.pulls.create({ owner, repo, - head: branch, - base: releaseBranch, + head: prBranch, + base: branch, title: `Update ${path}`, maintainer_can_modify: true, body: 'Automatically generated by Next Release Changelog Action' diff --git a/index.js b/index.js index 160513f..c3d1b21 100644 --- a/index.js +++ b/index.js @@ -45,6 +45,8 @@ async function run() { let { url, tag, name, body, releaseBranch } = getReleaseData(eventPath); + let branch = defaultBranch || releaseBranch; + let newContents = `### [${name}](${url}) ${NEWLINE} **${tag}** ${NEWLINE} ${body}` + currentContents; let buff = new Buffer.from(newContents); @@ -54,7 +56,7 @@ async function run() { owner, repo, path, - branch: releaseBranch, + branch, message: `Updated ${path} via Next Release action.`, content }; @@ -63,7 +65,7 @@ async function run() { options.sha = sha; } - let branch = core.getInput('branch_name') || `changelog-${tag}`; + let prBranch = core.getInput('branch_name') || `changelog-${tag}`; if (usePr) { let refSha; @@ -71,7 +73,7 @@ async function run() { let { data } = await octokit.git.getRef({ owner, repo, - ref: `heads/${releaseBranch}` + ref: `heads/${branch}` }); refSha = data.object.sha; @@ -85,9 +87,9 @@ async function run() { owner, repo, sha: refSha, - ref: `refs/heads/${branch}` + ref: `refs/heads/${prBranch}` }); - options.branch = branch; + options.branch = prBranch; } catch (e) { core.error(`Failed creating changelog PR: ${e}`); return; @@ -104,8 +106,8 @@ async function run() { await octokit.pulls.create({ owner, repo, - head: branch, - base: releaseBranch, + head: prBranch, + base: branch, title: `Update ${path}`, maintainer_can_modify: true, body: 'Automatically generated by Next Release Changelog Action' From 3fdc73fb60c91388cc5536c72d90e993dad13bf0 Mon Sep 17 00:00:00 2001 From: Donald Wasserman Date: Mon, 9 Dec 2019 10:17:42 -0500 Subject: [PATCH 7/7] Update some docs --- workflow.example.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/workflow.example.yml b/workflow.example.yml index 95779b6..1f75c57 100644 --- a/workflow.example.yml +++ b/workflow.example.yml @@ -12,3 +12,4 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} # Required changelog: 'CHANGELOG.md' # optional, default: CHANGELOG.md + use_pullrequest: false # default false, use true to create changelog in a PR