From 06f536aef69e98aef1e92bbe2de552b1e8a8005a Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 14:48:08 -0700 Subject: [PATCH 01/13] Update index.js This pull request enhances the issue-cloner action by adding the ability to specify additional labels and assignees for the cloned issue via the `addLabel` and `assignTo` inputs, respectively. Both inputs accept comma-separated values, allowing for multiple labels and assignees. The code has been updated to handle these inputs, ensuring they are properly applied to the cloned issue in the target repository. Additionally, the URL of the cloned issue is now set as an output of the action, providing a reference to the new issue directly from the action's output, which can be accessed with ${{ steps..outputs.issue_url }} in your workflow file. --- index.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 177d540..3f40f94 100644 --- a/index.js +++ b/index.js @@ -6,18 +6,23 @@ async function start(){ const label = core.getInput('label'); const targetRepo = core.getInput('targetRepo', {required: true}); const ghToken = core.getInput('token', {required: true}); + const labelArr = core.getInput('addLabel').split(',').map(label => label.trim()); + const assignToArr = core.getInput('assignTo').split(',').map(assignee => assignee.trim()); + const octokit = new github.getOctokit(ghToken); const originalIssue = await getOriginalIssue(octokit); if (!hasLabel(label, originalIssue)){ - console.log(`Label ${label} not present. Will not copy issue`) + console.log(`Label ${label} not present. Will not copy issue`); return; } - const clonedIssue = await cloneIssue(octokit, targetRepo, originalIssue) - await addComment(octokit, originalIssue, clonedIssue) + const clonedIssue = await cloneIssue(octokit, targetRepo, originalIssue, labelArr, assignToArr); + + await addComment(octokit, originalIssue, clonedIssue); + core.setOutput('issue_url', clonedIssue.data.html_url); console.log(`Issue cloned successfully`); } catch (error) { core.setFailed(error.message); @@ -41,7 +46,7 @@ async function getOriginalIssue(octokit) { return issue; } -async function cloneIssue(octokit, targetRepo, original){ +async function cloneIssue(octokit, targetRepo, original, labelArr, assignToArr) { const splitted = targetRepo.split('/'); const owner = splitted[0]; const repoName = splitted[1]; @@ -61,6 +66,25 @@ async function cloneIssue(octokit, targetRepo, original){ body: body, title: title }); + + if (labelArr.length > 0) { + await octokit.rest.issues.addLabels({ + owner: owner, + repo: repoName, + issue_number: result.data.number, + labels: labelArr + }); + } + + if (assignToArr.length > 0) { + await octokit.rest.issues.addAssignees({ + owner: owner, + repo: repoName, + issue_number: result.data.number, + assignees: assignToArr + }); + } + return result; } @@ -82,4 +106,4 @@ function hasLabel(label, issue){ } } return false; -} \ No newline at end of file +} From 1f0bb7c76d33ef97d7d9d5d70ef6ec1f23530558 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 14:50:44 -0700 Subject: [PATCH 02/13] Update README.md update README.md --- README.md | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cd1efdf..b70097c 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,36 @@ -# Clone issue to another repository +# Issue Cloner -Clone an issue to a predefined repository when labeled with a specific label +This action clones an issue from the current repository to another repository when a specified label is present on the issue. ## Inputs -### `token` - -**Required** Github token with repo:all permissions. +### `label` +The label that triggers the action. Default `"bug"`. ### `targetRepo` +**Required** The repository to clone the issue to, in the format `owner/repo`. -**Required** The repository in which to clone the issue. +### `token` +**Required** A GitHub token. -### `label` +### `addLabel` +A comma-separated list of labels to add to the cloned issue. Example: `"label1, label2"` + +### `assignTo` +A comma-separated list of assignees to assign to the cloned issue. Example: `"username1, username2"` + +## Outputs -**Optional** The label on which to react. Default `clone`. +### `issue_url` +The URL of the cloned issue in the target repository. -## Example usage +## Example Usage -```yml +```yaml uses: dpanayotov/issue-cloner@v0.2 with: - label: "clone" - targetRepo: myorg/myrepo - token: ${{ secrets.CLONE_ISSUE_TOKEN }} -``` \ No newline at end of file + label: 'bug' + targetRepo: 'owner/repo' + token: ${{ secrets.GITHUB_TOKEN }} + addLabel: 'new label, another label' + assignTo: 'username1, username2' From df1f59b5e6a1aebd53497d0ac77aae06e4d13adb Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 15:06:56 -0700 Subject: [PATCH 03/13] Update index.js --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3f40f94..6c4fe39 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ async function start(){ const label = core.getInput('label'); const targetRepo = core.getInput('targetRepo', {required: true}); const ghToken = core.getInput('token', {required: true}); + const prefixTitle = core.getInput('prefixTitle'); const labelArr = core.getInput('addLabel').split(',').map(label => label.trim()); const assignToArr = core.getInput('assignTo').split(',').map(assignee => assignee.trim()); @@ -59,7 +60,7 @@ async function cloneIssue(octokit, targetRepo, original, labelArr, assignToArr) body = `Issue cloned from ${original.data.html_url}\n\n${body}`; - const title = original.data.title; + const title = prefixTitle + original.data.title; const result = await octokit.rest.issues.create({ owner: owner, repo: repoName, From 0fb069360d32f1d071e016e42bb87ec8c4c7942d Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 15:10:08 -0700 Subject: [PATCH 04/13] Update index.js refactored parameters --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 6c4fe39..6a05cf2 100644 --- a/index.js +++ b/index.js @@ -6,10 +6,10 @@ async function start(){ const label = core.getInput('label'); const targetRepo = core.getInput('targetRepo', {required: true}); const ghToken = core.getInput('token', {required: true}); - const prefixTitle = core.getInput('prefixTitle'); - const labelArr = core.getInput('addLabel').split(',').map(label => label.trim()); - const assignToArr = core.getInput('assignTo').split(',').map(assignee => assignee.trim()); + const addPrefix = core.getInput('addPrefix'); + const addLabels = core.getInput('addLabels').split(',').map(label => label.trim()); + const addAssignees = core.getInput('addAssignees').split(',').map(assignee => assignee.trim()); const octokit = new github.getOctokit(ghToken); const originalIssue = await getOriginalIssue(octokit); @@ -19,7 +19,7 @@ async function start(){ return; } - const clonedIssue = await cloneIssue(octokit, targetRepo, originalIssue, labelArr, assignToArr); + const clonedIssue = await cloneIssue(octokit, targetRepo, originalIssue, addLabels, addAssignees, addPrefix); await addComment(octokit, originalIssue, clonedIssue); @@ -47,7 +47,7 @@ async function getOriginalIssue(octokit) { return issue; } -async function cloneIssue(octokit, targetRepo, original, labelArr, assignToArr) { +async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees, addPrefix) { const splitted = targetRepo.split('/'); const owner = splitted[0]; const repoName = splitted[1]; @@ -60,7 +60,7 @@ async function cloneIssue(octokit, targetRepo, original, labelArr, assignToArr) body = `Issue cloned from ${original.data.html_url}\n\n${body}`; - const title = prefixTitle + original.data.title; + const title = addPrefix + original.data.title; const result = await octokit.rest.issues.create({ owner: owner, repo: repoName, From e301154229214df363b4b79717274f4416878390 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 15:13:21 -0700 Subject: [PATCH 05/13] Update README.md --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b70097c..2494d67 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This action clones an issue from the current repository to another repository wh ## Inputs ### `label` -The label that triggers the action. Default `"bug"`. +The label that triggers the action. Default `"clone"`. ### `targetRepo` **Required** The repository to clone the issue to, in the format `owner/repo`. @@ -13,11 +13,15 @@ The label that triggers the action. Default `"bug"`. ### `token` **Required** A GitHub token. -### `addLabel` -A comma-separated list of labels to add to the cloned issue. Example: `"label1, label2"` +### `addPrefix` +A prefix to append to the title of the cloned issue. Default is an empty string. + +### `addLabels` +A comma-separated list of labels to add to the cloned issue. Default is an empty string. + +### `addAssignees` +A comma-separated list of assignees to add to the cloned issue. Default is an empty string. -### `assignTo` -A comma-separated list of assignees to assign to the cloned issue. Example: `"username1, username2"` ## Outputs @@ -27,10 +31,11 @@ The URL of the cloned issue in the target repository. ## Example Usage ```yaml -uses: dpanayotov/issue-cloner@v0.2 +uses: dpanayotov/issue-cloner@v0.3 with: - label: 'bug' + label: 'clone' targetRepo: 'owner/repo' token: ${{ secrets.GITHUB_TOKEN }} - addLabel: 'new label, another label' - assignTo: 'username1, username2' + addPrefix: 'Bug - ' + addLabels: 'bug, needs-triage' + addAssignees: 'alice,bob' From 77537644a4f1d679e26001a71251ae5e1caf0954 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 15:19:08 -0700 Subject: [PATCH 06/13] Update index.js --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6a05cf2..b10296f 100644 --- a/index.js +++ b/index.js @@ -60,7 +60,7 @@ async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees body = `Issue cloned from ${original.data.html_url}\n\n${body}`; - const title = addPrefix + original.data.title; + const title = !!addPrefix ? `${addPrefix} ${original.data.title}` : original.data.title; const result = await octokit.rest.issues.create({ owner: owner, repo: repoName, @@ -68,7 +68,7 @@ async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees title: title }); - if (labelArr.length > 0) { + if (addLabels.length > 0) { await octokit.rest.issues.addLabels({ owner: owner, repo: repoName, @@ -77,7 +77,7 @@ async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees }); } - if (assignToArr.length > 0) { + if (addAssignees.length > 0) { await octokit.rest.issues.addAssignees({ owner: owner, repo: repoName, From 2a8450b26696f27d803f666a96b68259fb579a26 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 15:23:10 -0700 Subject: [PATCH 07/13] Update index.js --- index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index b10296f..39da6f2 100644 --- a/index.js +++ b/index.js @@ -7,9 +7,9 @@ async function start(){ const targetRepo = core.getInput('targetRepo', {required: true}); const ghToken = core.getInput('token', {required: true}); - const addPrefix = core.getInput('addPrefix'); - const addLabels = core.getInput('addLabels').split(',').map(label => label.trim()); - const addAssignees = core.getInput('addAssignees').split(',').map(assignee => assignee.trim()); + const prefix = core.getInput('prefix'); + const labels = core.getInput('labels').split(',').map(label => label.trim()); + const assignees = core.getInput('assignees').split(',').map(assignee => assignee.trim()); const octokit = new github.getOctokit(ghToken); const originalIssue = await getOriginalIssue(octokit); @@ -19,7 +19,7 @@ async function start(){ return; } - const clonedIssue = await cloneIssue(octokit, targetRepo, originalIssue, addLabels, addAssignees, addPrefix); + const clonedIssue = await cloneIssue(octokit, targetRepo, originalIssue, prefix, labels, assignees); await addComment(octokit, originalIssue, clonedIssue); @@ -47,7 +47,7 @@ async function getOriginalIssue(octokit) { return issue; } -async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees, addPrefix) { +async function cloneIssue(octokit, targetRepo, original, prefix, labels, assignees) { const splitted = targetRepo.split('/'); const owner = splitted[0]; const repoName = splitted[1]; @@ -60,7 +60,7 @@ async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees body = `Issue cloned from ${original.data.html_url}\n\n${body}`; - const title = !!addPrefix ? `${addPrefix} ${original.data.title}` : original.data.title; + const title = !!prefix ? `${prefix} ${original.data.title}` : original.data.title; const result = await octokit.rest.issues.create({ owner: owner, repo: repoName, @@ -68,21 +68,21 @@ async function cloneIssue(octokit, targetRepo, original, addLabels, addAssignees title: title }); - if (addLabels.length > 0) { + if (labels.length > 0) { await octokit.rest.issues.addLabels({ owner: owner, repo: repoName, issue_number: result.data.number, - labels: labelArr + labels: labels }); } - if (addAssignees.length > 0) { + if (assignees.length > 0) { await octokit.rest.issues.addAssignees({ owner: owner, repo: repoName, issue_number: result.data.number, - assignees: assignToArr + assignees: assignees }); } From a46f67f94da5caa75205eee44c16752a85703bd7 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 15:25:08 -0700 Subject: [PATCH 08/13] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2494d67..825fb5b 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ The label that triggers the action. Default `"clone"`. ### `token` **Required** A GitHub token. -### `addPrefix` +### `prefix` A prefix to append to the title of the cloned issue. Default is an empty string. -### `addLabels` +### `labels` A comma-separated list of labels to add to the cloned issue. Default is an empty string. -### `addAssignees` +### `asignees` A comma-separated list of assignees to add to the cloned issue. Default is an empty string. @@ -36,6 +36,7 @@ with: label: 'clone' targetRepo: 'owner/repo' token: ${{ secrets.GITHUB_TOKEN }} - addPrefix: 'Bug - ' - addLabels: 'bug, needs-triage' - addAssignees: 'alice,bob' + prefix: 'CLONE:' + labels: 'bug, needs-triage' + asignees: 'alice,bob' +``` From 5f92fc4284cc840cf119fcf4e4c56b30993287dd Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 18:17:43 -0700 Subject: [PATCH 09/13] Update README.md Match existing format --- README.md | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 825fb5b..f5c5dce 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,29 @@ -# Issue Cloner +# Clone issue to another repository This action clones an issue from the current repository to another repository when a specified label is present on the issue. ## Inputs -### `label` -The label that triggers the action. Default `"clone"`. +### `token` + +**Required** Github token with repo:all permissions. ### `targetRepo` + **Required** The repository to clone the issue to, in the format `owner/repo`. -### `token` -**Required** A GitHub token. +### `label` + +**Optional** The label on which to react. Default `clone`. ### `prefix` -A prefix to append to the title of the cloned issue. Default is an empty string. +**Optional** A prefix to append to the title of the cloned issue. Default is an empty string. ### `labels` -A comma-separated list of labels to add to the cloned issue. Default is an empty string. +**Optional** A comma-separated list of labels to add to the cloned issue. Default is an empty string. ### `asignees` -A comma-separated list of assignees to add to the cloned issue. Default is an empty string. - +**Optional** A comma-separated list of assignees to add to the cloned issue. Default is an empty string. ## Outputs @@ -30,13 +32,13 @@ The URL of the cloned issue in the target repository. ## Example Usage -```yaml -uses: dpanayotov/issue-cloner@v0.3 +```yml +uses: dpanayotov/issue-cloner@v0.2 with: - label: 'clone' - targetRepo: 'owner/repo' - token: ${{ secrets.GITHUB_TOKEN }} - prefix: 'CLONE:' + label: "clone" + targetRepo: myorg/myrepo + token: ${{ secrets.CLONE_ISSUE_TOKEN }} + prefix: 'CLONED:' labels: 'bug, needs-triage' asignees: 'alice,bob' ``` From c8063b4511f4de377a48124945f7a73785ef492f Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 18:19:03 -0700 Subject: [PATCH 10/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f5c5dce..edccfd8 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ This action clones an issue from the current repository to another repository wh ## Outputs ### `issue_url` -The URL of the cloned issue in the target repository. +The URL of the cloned issue in the target repository, which can be accessed with ${{ steps..outputs.issue_url }} in your workflow file. ## Example Usage From 14b529db70b1554504f4ba97855e5c800e6c5305 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 18:22:16 -0700 Subject: [PATCH 11/13] Update index.js --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 39da6f2..7dcb793 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const github = require('@actions/github');; async function start(){ try { - const label = core.getInput('label'); + const label = core.getInput('label') || 'clone'; const targetRepo = core.getInput('targetRepo', {required: true}); const ghToken = core.getInput('token', {required: true}); @@ -24,6 +24,7 @@ async function start(){ await addComment(octokit, originalIssue, clonedIssue); core.setOutput('issue_url', clonedIssue.data.html_url); + console.log(`Issue cloned successfully`); } catch (error) { core.setFailed(error.message); From 370209c1dbc3859ee25dba0d7e0f5dd00073d326 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 18:23:13 -0700 Subject: [PATCH 12/13] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7dcb793..6559869 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const github = require('@actions/github');; async function start(){ try { - const label = core.getInput('label') || 'clone'; + const label = core.getInput('label'); const targetRepo = core.getInput('targetRepo', {required: true}); const ghToken = core.getInput('token', {required: true}); From 5176170dd7e3648c850e7ae618849854efb71ced Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Fri, 6 Oct 2023 18:28:09 -0700 Subject: [PATCH 13/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edccfd8..e5dc626 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The URL of the cloned issue in the target repository, which can be accessed with ## Example Usage ```yml -uses: dpanayotov/issue-cloner@v0.2 +uses: dpanayotov/issue-cloner@v0.3 with: label: "clone" targetRepo: myorg/myrepo