From 2044ba3fc5eb449b35bcd65f7958fff0326f0460 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:30:35 -0700 Subject: [PATCH 1/9] style: prettier --- index.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 059b68d4..8794ac4d 100644 --- a/index.js +++ b/index.js @@ -43,17 +43,17 @@ async function main() { branch: core.getInput("branch").replace(/^refs\/heads\//, ""), path: core.getInput("path"), commitMessage: core.getInput("commit-message"), - author: core.getInput("author") + author: core.getInput("author"), }; core.debug(`Inputs: ${inspect(inputs)}`); const { - data: { default_branch } + data: { default_branch }, } = await request(`GET /repos/${process.env.GITHUB_REPOSITORY}`, { headers: { - authorization: `token ${process.env.GITHUB_TOKEN}` - } + authorization: `token ${process.env.GITHUB_TOKEN}`, + }, }); const DEFAULT_BRANCH = default_branch; core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`); @@ -86,7 +86,7 @@ async function main() { await setGitUser({ name, - email + email, }); } @@ -128,7 +128,7 @@ async function main() { if (remoteBranchExists) { const q = `head:${inputs.branch} type:pr is:open repo:${process.env.GITHUB_REPOSITORY}`; const { data } = await request("GET /search/issues", { - q + q, }); if (data.total_count > 0) { @@ -141,15 +141,15 @@ async function main() { core.debug(`Creating pull request`); const { - data: { html_url } + data: { html_url }, } = await request(`POST /repos/${process.env.GITHUB_REPOSITORY}/pulls`, { headers: { - authorization: `token ${process.env.GITHUB_TOKEN}` + authorization: `token ${process.env.GITHUB_TOKEN}`, }, title: inputs.title, body: inputs.body, head: inputs.branch, - base: DEFAULT_BRANCH + base: DEFAULT_BRANCH, }); core.info(`Pull request created: ${html_url}`); @@ -173,7 +173,7 @@ async function getLocalChanges(path) { return { hasUncommitedChanges, - hasChanges: hasUncommitedChanges + hasChanges: hasUncommitedChanges, }; } @@ -184,7 +184,7 @@ async function getGitUser() { return { name, - email + email, }; } catch (error) { return; From f9f06f6891f9c34f8833ed10e65eb493a7e00e25 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:42:27 -0700 Subject: [PATCH 2/9] feat: `labels` option --- .github/workflows/test.yml | 1 + README.md | 1 + action.yml | 2 ++ index.js | 23 ++++++++++++++++++++--- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d44d5bb7..27720b00 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,6 +42,7 @@ jobs: branch: test-create-new-pull-request commit-message: "Just testing [skip ci]" author: "J. Doe " + labels: test1, test2 - run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git :test-create-new-pull-request" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 6ffb5783..16748329 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ with: path: "lib/" commit-message: "My commit message for uncommitted changes in lib/ folder" author: "Lorem J. Ipsum " + labels: label1, label2 ``` To create multiple commits for different paths, use the action multiple times diff --git a/action.yml b/action.yml index 51585451..ff4055b4 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,8 @@ inputs: default: Update from 'Create or Update Request' action path: description: Commit selected files only by providing a path. It is used in `git add ""` + labels: + description: Comma separated list of labels to apply to the pull request runs: using: "node12" main: "dist/index.js" diff --git a/index.js b/index.js index 8794ac4d..4e1e89b5 100644 --- a/index.js +++ b/index.js @@ -44,16 +44,18 @@ async function main() { path: core.getInput("path"), commitMessage: core.getInput("commit-message"), author: core.getInput("author"), + labels: core.getInput("labels"), }; core.debug(`Inputs: ${inspect(inputs)}`); const { data: { default_branch }, - } = await request(`GET /repos/${process.env.GITHUB_REPOSITORY}`, { + } = await request(`GET /repos/{repository}`, { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`, }, + repository: process.env.GITHUB_REPOSITORY, }); const DEFAULT_BRANCH = default_branch; core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`); @@ -141,11 +143,12 @@ async function main() { core.debug(`Creating pull request`); const { - data: { html_url }, - } = await request(`POST /repos/${process.env.GITHUB_REPOSITORY}/pulls`, { + data: { html_url, number }, + } = await request(`POST /repos/{repository}/pulls`, { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`, }, + repository: process.env.GITHUB_REPOSITORY, title: inputs.title, body: inputs.body, head: inputs.branch, @@ -153,6 +156,20 @@ async function main() { }); core.info(`Pull request created: ${html_url}`); + + if (inputs.labels) { + core.debug(`Adding labels: ${inputs.labels}`); + await request(`/repos/{repository}/issues/{issue_number}/labels`, { + headers: { + authorization: `token ${process.env.GITHUB_TOKEN}`, + }, + repository: process.env.GITHUB_REPOSITORY, + issue_number: number, + labels: inputs.labels.trim().split(/\s*,\s*/), + }); + core.info(`Labels added: ${inputs.labels}`); + } + await runShellCommand(`git stash pop || true`); } catch (error) { core.debug(inspect(error)); From 7337d16e3f1997d1dd9382ecf12e5c6f43648615 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:45:22 -0700 Subject: [PATCH 3/9] fixup! feat: `labels` option --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 4e1e89b5..5a448509 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,8 @@ async function main() { return; } + const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/"); + try { const inputs = { title: core.getInput("title"), @@ -51,11 +53,12 @@ async function main() { const { data: { default_branch }, - } = await request(`GET /repos/{repository}`, { + } = await request(`GET /repos/{owner}/{repo}`, { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`, }, - repository: process.env.GITHUB_REPOSITORY, + owner, + repo, }); const DEFAULT_BRANCH = default_branch; core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`); @@ -144,11 +147,12 @@ async function main() { core.debug(`Creating pull request`); const { data: { html_url, number }, - } = await request(`POST /repos/{repository}/pulls`, { + } = await request(`POST /repos/{owner}/{repo}/pulls`, { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`, }, - repository: process.env.GITHUB_REPOSITORY, + owner, + repo, title: inputs.title, body: inputs.body, head: inputs.branch, @@ -159,11 +163,12 @@ async function main() { if (inputs.labels) { core.debug(`Adding labels: ${inputs.labels}`); - await request(`/repos/{repository}/issues/{issue_number}/labels`, { + await request(`/repos/{owner}/{repo}/issues/{issue_number}/labels`, { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`, }, - repository: process.env.GITHUB_REPOSITORY, + owner, + repo, issue_number: number, labels: inputs.labels.trim().split(/\s*,\s*/), }); From 6d62995dc0f3bc9c3dd55b35928bea5a63c38d2a Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:48:53 -0700 Subject: [PATCH 4/9] fixup! feat: `labels` option --- index.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 5a448509..81697823 100644 --- a/index.js +++ b/index.js @@ -163,16 +163,21 @@ async function main() { if (inputs.labels) { core.debug(`Adding labels: ${inputs.labels}`); - await request(`/repos/{owner}/{repo}/issues/{issue_number}/labels`, { - headers: { - authorization: `token ${process.env.GITHUB_TOKEN}`, - }, - owner, - repo, - issue_number: number, - labels: inputs.labels.trim().split(/\s*,\s*/), - }); - core.info(`Labels added: ${inputs.labels}`); + const labels = inputs.labels.trim().split(/\s*,\s*/); + const { data } = await request( + `/repos/{owner}/{repo}/issues/{issue_number}/labels`, + { + headers: { + authorization: `token ${process.env.GITHUB_TOKEN}`, + }, + owner, + repo, + issue_number: number, + labels, + } + ); + core.info(`Labels added: ${labels.join(", ")}`); + core.debug(data); } await runShellCommand(`git stash pop || true`); From 17b7e30e64295f17711e33f7d222a32511dab256 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:52:09 -0700 Subject: [PATCH 5/9] fixup! feat: `labels` option --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 81697823..eb344f15 100644 --- a/index.js +++ b/index.js @@ -177,12 +177,12 @@ async function main() { } ); core.info(`Labels added: ${labels.join(", ")}`); - core.debug(data); + core.debug(inspect(data)); } await runShellCommand(`git stash pop || true`); } catch (error) { - core.debug(inspect(error)); + core.info(inspect(error)); core.setFailed(error.message); } } From 25dcf5bdebc04b2b5716b14b635c28d1eeea6587 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:55:42 -0700 Subject: [PATCH 6/9] fixup! feat: `labels` option --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index eb344f15..25c7b7ea 100644 --- a/index.js +++ b/index.js @@ -159,7 +159,7 @@ async function main() { base: DEFAULT_BRANCH, }); - core.info(`Pull request created: ${html_url}`); + core.info(`Pull request created: ${html_url} (#${number})`); if (inputs.labels) { core.debug(`Adding labels: ${inputs.labels}`); From 94dfdda7bff813b5fbe690471e6eed459176740e Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:57:08 -0700 Subject: [PATCH 7/9] fixup! feat: `labels` option --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index 25c7b7ea..29b9517d 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,20 @@ async function main() { if (inputs.labels) { core.debug(`Adding labels: ${inputs.labels}`); const labels = inputs.labels.trim().split(/\s*,\s*/); + const options = request.endpoint( + "/repos/{owner}/{repo}/issues/{issue_number}/labels", + { + headers: { + authorization: `token ${process.env.GITHUB_TOKEN}`, + }, + owner, + repo, + issue_number: number, + labels, + } + ); + core.debug(inspect(options)); + const { data } = await request( `/repos/{owner}/{repo}/issues/{issue_number}/labels`, { From 1ad32ad55e6314ab31b6365cc9663731c8fe291e Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 10:59:42 -0700 Subject: [PATCH 8/9] fixup! feat: `labels` option --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27720b00..e7eb3770 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,7 @@ jobs: commit-message: "Just testing [skip ci]" author: "J. Doe " labels: test1, test2 + - run: sleep 3 # wait 3s before deleting the pull request to give GitHub time to fully replicate - run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git :test-create-new-pull-request" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4eafcf29b49b07d3dfcb808755868305b716f3e3 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 18 Sep 2020 11:01:48 -0700 Subject: [PATCH 9/9] fixup! feat: `labels` option --- .github/workflows/test.yml | 1 - index.js | 16 +--------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7eb3770..27720b00 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,6 @@ jobs: commit-message: "Just testing [skip ci]" author: "J. Doe " labels: test1, test2 - - run: sleep 3 # wait 3s before deleting the pull request to give GitHub time to fully replicate - run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git :test-create-new-pull-request" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/index.js b/index.js index 29b9517d..ef472670 100644 --- a/index.js +++ b/index.js @@ -164,22 +164,8 @@ async function main() { if (inputs.labels) { core.debug(`Adding labels: ${inputs.labels}`); const labels = inputs.labels.trim().split(/\s*,\s*/); - const options = request.endpoint( - "/repos/{owner}/{repo}/issues/{issue_number}/labels", - { - headers: { - authorization: `token ${process.env.GITHUB_TOKEN}`, - }, - owner, - repo, - issue_number: number, - labels, - } - ); - core.debug(inspect(options)); - const { data } = await request( - `/repos/{owner}/{repo}/issues/{issue_number}/labels`, + `POST /repos/{owner}/{repo}/issues/{issue_number}/labels`, { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`,