diff --git a/.github/workflows/create_pull_request.yml b/.github/workflows/create_pull_request.yml deleted file mode 100644 index d9d1eb5..0000000 --- a/.github/workflows/create_pull_request.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Pull Request Action -on: - push: - branches: - - feature/* - - test/* - - test - -jobs: - create-pull-request: - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v2 - - name: pull-request - uses: repo-sync/pull-request@v2 - with: - destination_branch: "develop" - github_token: ${{ secrets.GITHUB_TOKEN }} - pr_label: "feature, automated pr" - pr_title: "[Example] Simple demo" \ No newline at end of file diff --git a/.github/workflows/develop_actions.yml b/.github/workflows/develop_actions.yml new file mode 100644 index 0000000..caf4e8e --- /dev/null +++ b/.github/workflows/develop_actions.yml @@ -0,0 +1,16 @@ +name: on merging to develop + +on: + push: + branches: [ develop ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ./develop_actions.js + with: + GITHUB_TOKEN: ${{secrets.TOKEN}} + \ No newline at end of file diff --git a/.github/workflows/merge_pull_request.yml b/.github/workflows/merge_pull_request.yml deleted file mode 100644 index 9eef387..0000000 --- a/.github/workflows/merge_pull_request.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: test - -on: - pull_request: - branches: [master, develop, staging] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Check Out Repo - uses: actions/checkout@v2 - - # - name: 🔀 Merge Pull Request - # uses: BaharaJr/merge-pr@0.0.1 - # with: - # GITHUB_TOKEN: ${{ secrets.TOKEN }} \ No newline at end of file diff --git a/.github/workflows/npm-gulp.yml b/.github/workflows/npm-gulp.yml deleted file mode 100644 index 3f12365..0000000 --- a/.github/workflows/npm-gulp.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: NodeJS with Gulp - -on: - push: - branches: [ develop ] - paths: ["gulpfile.js"] - pull_request: - branches: [ develop ] - paths: ["gulpfile.js"] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - node-version: [12.x, 14.x, 16.x] - - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: Build - run: npm install - - - name: gulp - run: npm install -g gulp axios @octokit/core - - - name: notify - # run: gulp createnotification --b ${{ secrets.SLACK_WEBHOOK_URL }} - run: gulp getpulls --b ${{ secrets.TOKEN }} - diff --git a/gulpfile.js b/gulpfile.js index aad22fe..ed14678 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -87,10 +87,10 @@ gulp.task("getpulls", async () => { }); console.log("pulls", pulls?.data); - const pull = await octokit.request("GET /repos/bmsteven/demo/pulls/16", { + const pull = await octokit.request("GET /repos/bmsteven/demo/pulls/18", { owner: "bmsteven", repo: "demo", - pull_number: "16", + pull_number: "18", }); console.log("pull", pull?.data); // update pull request @@ -109,27 +109,27 @@ gulp.task("getpulls", async () => { { owner: "bmsteven", repo: "demo", - pull_number: "16", + pull_number: "18", } ); console.log("commits", commits?.data); // check if pull request was merged - // const checkPulls = await octokit.request( - // "GET /repos/bmsteven/demo/pulls/16/merge", - // { - // owner: "bmsteven", - // repo: "demo", - // pull_number: "16", - // } - // ); - // console.log("checkPulls", checkPulls?.data); + const checkPulls = await octokit.request( + "GET /repos/bmsteven/demo/pulls/18/merge", + { + owner: "bmsteven", + repo: "demo", + pull_number: "18", + } + ); + console.log("checkPulls", checkPulls?.data); // merge pull request const mergepr = await octokit.request( "PUT /repos/bmsteven/demo/pulls/16/merge", { owner: "bmsteven", repo: "demo", - pull_number: "16", + pull_number: "18", } ); console.log("mergepr", mergepr?.data); @@ -163,3 +163,82 @@ gulp.task("getpulls", async () => { // run: echo "This step will be skipped on Monday and Wednesday" // - name: Every time // run: echo "This step will always run" + +// create pr action +// name: Pull Request Action +// on: +// push: +// branches: +// - feature/* +// - test/* +// - test + +// jobs: +// create-pull-request: +// runs-on: ubuntu-latest +// steps: +// - name: Check out repository code +// uses: actions/checkout@v2 +// - name: pull-request +// uses: repo-sync/pull-request@v2 +// with: +// destination_branch: "develop" +// github_token: ${{ secrets.GITHUB_TOKEN }} +// pr_label: "feature, automated pr" +// pr_title: "[Example] Simple demo" + +// name: test + +// on: +// pull_request: +// branches: [master, develop, staging] + +// jobs: +// build: +// runs-on: ubuntu-latest + +// steps: +// - name: Check Out Repo +// uses: actions/checkout@v2 + +// # - name: 🔀 Merge Pull Request +// # uses: BaharaJr/merge-pr@0.0.1 +// # with: +// # GITHUB_TOKEN: ${{ secrets.TOKEN }} + +// name: NodeJS with Gulp + +// on: +// push: +// branches: [ develop ] +// paths: ["gulpfile.js"] +// pull_request: +// branches: [ develop ] +// paths: ["gulpfile.js"] + +// jobs: +// build: +// runs-on: ubuntu-latest + +// strategy: +// fail-fast: false +// matrix: +// node-version: [12.x, 14.x, 16.x] + +// steps: +// - uses: actions/checkout@v3 + +// - name: Use Node.js ${{ matrix.node-version }} +// uses: actions/setup-node@v3 +// with: +// node-version: ${{ matrix.node-version }} + +// - name: Build +// run: npm install + +// - name: gulp +// run: npm install -g gulp axios @octokit/core + +// - name: notify +// # run: gulp createnotification --b ${{ secrets.SLACK_WEBHOOK_URL }} +// run: gulp getpulls --b ${{ secrets.TOKEN }} diff --git a/package-lock.json b/package-lock.json index e3033c5..d38c1b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,40 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@actions/core": "^1.6.0", + "@actions/github": "^5.0.1", "@octokit/core": "^3.6.0", "axios": "^0.26.1", "gulp": "^4.0.2" } }, + "node_modules/@actions/core": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz", + "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==", + "dependencies": { + "@actions/http-client": "^1.0.11" + } + }, + "node_modules/@actions/github": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.0.1.tgz", + "integrity": "sha512-JZGyPM9ektb8NVTTI/2gfJ9DL7Rk98tQ7OVyTlgTuaQroariRBsOnzjy0I2EarX4xUZpK88YyO503fhmjFdyAg==", + "dependencies": { + "@actions/http-client": "^1.0.11", + "@octokit/core": "^3.6.0", + "@octokit/plugin-paginate-rest": "^2.17.0", + "@octokit/plugin-rest-endpoint-methods": "^5.13.0" + } + }, + "node_modules/@actions/http-client": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", + "integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", + "dependencies": { + "tunnel": "0.0.6" + } + }, "node_modules/@octokit/auth-token": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", @@ -61,6 +90,29 @@ "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-11.2.0.tgz", "integrity": "sha512-PBsVO+15KSlGmiI8QAzaqvsNlZlrDlyAJYcrXBCvVUxCp7VnXjkwPoFHgjEJXx3WF9BAwkA6nfCUA7i9sODzKA==" }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz", + "integrity": "sha512-tzMbrbnam2Mt4AhuyCHvpRkS0oZ5MvwwcQPYGtMv4tUa5kkzG58SVB0fcsLulOZQeRnOgdkZWkRUiyBlh0Bkyw==", + "dependencies": { + "@octokit/types": "^6.34.0" + }, + "peerDependencies": { + "@octokit/core": ">=2" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.13.0.tgz", + "integrity": "sha512-uJjMTkN1KaOIgNtUPMtIXDOjx6dGYysdIFhgA52x4xSadQCz3b/zJexvITDVpANnfKPW/+E0xkOvLntqMYpviA==", + "dependencies": { + "@octokit/types": "^6.34.0", + "deprecation": "^2.3.1" + }, + "peerDependencies": { + "@octokit/core": ">=3" + } + }, "node_modules/@octokit/request": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", @@ -3437,6 +3489,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, "node_modules/type": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", @@ -3789,6 +3849,33 @@ } }, "dependencies": { + "@actions/core": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz", + "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==", + "requires": { + "@actions/http-client": "^1.0.11" + } + }, + "@actions/github": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.0.1.tgz", + "integrity": "sha512-JZGyPM9ektb8NVTTI/2gfJ9DL7Rk98tQ7OVyTlgTuaQroariRBsOnzjy0I2EarX4xUZpK88YyO503fhmjFdyAg==", + "requires": { + "@actions/http-client": "^1.0.11", + "@octokit/core": "^3.6.0", + "@octokit/plugin-paginate-rest": "^2.17.0", + "@octokit/plugin-rest-endpoint-methods": "^5.13.0" + } + }, + "@actions/http-client": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", + "integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", + "requires": { + "tunnel": "0.0.6" + } + }, "@octokit/auth-token": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", @@ -3836,6 +3923,23 @@ "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-11.2.0.tgz", "integrity": "sha512-PBsVO+15KSlGmiI8QAzaqvsNlZlrDlyAJYcrXBCvVUxCp7VnXjkwPoFHgjEJXx3WF9BAwkA6nfCUA7i9sODzKA==" }, + "@octokit/plugin-paginate-rest": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz", + "integrity": "sha512-tzMbrbnam2Mt4AhuyCHvpRkS0oZ5MvwwcQPYGtMv4tUa5kkzG58SVB0fcsLulOZQeRnOgdkZWkRUiyBlh0Bkyw==", + "requires": { + "@octokit/types": "^6.34.0" + } + }, + "@octokit/plugin-rest-endpoint-methods": { + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.13.0.tgz", + "integrity": "sha512-uJjMTkN1KaOIgNtUPMtIXDOjx6dGYysdIFhgA52x4xSadQCz3b/zJexvITDVpANnfKPW/+E0xkOvLntqMYpviA==", + "requires": { + "@octokit/types": "^6.34.0", + "deprecation": "^2.3.1" + } + }, "@octokit/request": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", @@ -6500,6 +6604,11 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" + }, "type": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", diff --git a/package.json b/package.json index 75a2f55..c2e77e2 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ }, "homepage": "https://github.com/bmsteven/demo#readme", "dependencies": { + "@actions/core": "^1.6.0", + "@actions/github": "^5.0.1", "@octokit/core": "^3.6.0", "axios": "^0.26.1", "gulp": "^4.0.2" diff --git a/src/develop_actions.js b/src/develop_actions.js new file mode 100644 index 0000000..c188676 --- /dev/null +++ b/src/develop_actions.js @@ -0,0 +1,18 @@ +const axios = require("axios"); +const github = require("@actions/github"); +const core = require("@actions/core"); + +const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN"); +const octokit = github.getOctokit(GITHUB_TOKEN); +const { context = {} } = github; + +const run = async () => { + console.log(context.payload); + console.log(GITHUB_TOKEN); + console.log("actions"); +}; + +run(); + +// $GITHUB_REF would look like (refs/pull/33/merge), $GITHUB_HEAD_REF would just store the source branch name while $GITHUB_BASE_REF would represent RP destination branch. Maybe you can update your answer to fallback to $GITHUB_HEAD_REF +// ${GITHUB_REF##*/}