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..f6e8c1e --- /dev/null +++ b/.github/workflows/develop_actions.yml @@ -0,0 +1,20 @@ +name: on merging to develop + +on: + push: + branches: [ develop ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: npm install + + - name: install packages + run: npm install -g gulp axios @octokit/core @actions/github @actions/core + - uses: ./ + with: + GITHUB_TOKEN: ${{secrets.TOKEN}} 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/action.yml b/action.yml new file mode 100644 index 0000000..6d290fe --- /dev/null +++ b/action.yml @@ -0,0 +1,15 @@ +name: 'Automatically create pr to staging' +description: 'Run develop actions' +author: 'Benedict Steven' + +inputs: + GITHUB_TOKEN: + description: 'GitHub Token' + required: true +runs: + using: 'node16' + main: './src/develop_actions.js' + +branding: + icon: 'package' + color: 'gray-dark' \ No newline at end of file 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/res.js b/res.js new file mode 100644 index 0000000..81268c3 --- /dev/null +++ b/res.js @@ -0,0 +1,194 @@ +exports.response = { + after: "94a28b830c5af1d1a5e0a1ccd55ac9f9df8244da", + base_ref: null, + before: "cc8b67c069125765f31ee6908392e0439f0d04eb", + commits: [ + { + author: [Object], + committer: [Object], + distinct: false, + id: "49f9be33fb8cbf34c5a891db989e3de07c27b7a1", + message: "test commit", + timestamp: "2022-04-22T20:00:25+03:00", + tree_id: "969c2c9cb3ca68847fcf744a21df3672c153127d", + url: "https://github.com/bmsteven/demo/commit/49f9be33fb8cbf34c5a891db989e3de07c27b7a1", + }, + { + author: [Object], + committer: [Object], + distinct: true, + id: "94a28b830c5af1d1a5e0a1ccd55ac9f9df8244da", + message: + "Merge pull request #22 from bmsteven/test_branch\n\ntest commit", + timestamp: "2022-04-22T20:01:07+03:00", + tree_id: "969c2c9cb3ca68847fcf744a21df3672c153127d", + url: "https://github.com/bmsteven/demo/commit/94a28b830c5af1d1a5e0a1ccd55ac9f9df8244da", + }, + ], + compare: + "https://github.com/bmsteven/demo/compare/cc8b67c06912...94a28b830c5a", + created: false, + deleted: false, + forced: false, + head_commit: { + author: { + email: "48621248+bmsteven@users.noreply.github.com", + name: "Benedict Steven", + username: "bmsteven", + }, + committer: { + email: "noreply@github.com", + name: "GitHub", + username: "web-flow", + }, + distinct: true, + id: "94a28b830c5af1d1a5e0a1ccd55ac9f9df8244da", + message: "Merge pull request #22 from bmsteven/test_branch\n\ntest commit", + timestamp: "2022-04-22T20:01:07+03:00", + tree_id: "969c2c9cb3ca68847fcf744a21df3672c153127d", + url: "https://github.com/bmsteven/demo/commit/94a28b830c5af1d1a5e0a1ccd55ac9f9df8244da", + }, + pusher: { + email: "48621248+bmsteven@users.noreply.github.com", + name: "bmsteven", + }, + ref: "refs/heads/develop", + repository: { + allow_forking: true, + archive_url: + "https://api.github.com/repos/bmsteven/demo/{archive_format}{/ref}", + archived: false, + assignees_url: + "https://api.github.com/repos/bmsteven/demo/assignees{/user}", + blobs_url: "https://api.github.com/repos/bmsteven/demo/git/blobs{/sha}", + branches_url: + "https://api.github.com/repos/bmsteven/demo/branches{/branch}", + clone_url: "https://github.com/bmsteven/demo.git", + collaborators_url: + "https://api.github.com/repos/bmsteven/demo/collaborators{/collaborator}", + comments_url: + "https://api.github.com/repos/bmsteven/demo/comments{/number}", + commits_url: "https://api.github.com/repos/bmsteven/demo/commits{/sha}", + compare_url: + "https://api.github.com/repos/bmsteven/demo/compare/{base}...{head}", + contents_url: "https://api.github.com/repos/bmsteven/demo/contents/{+path}", + contributors_url: "https://api.github.com/repos/bmsteven/demo/contributors", + created_at: 1553584187, + default_branch: "master", + deployments_url: "https://api.github.com/repos/bmsteven/demo/deployments", + description: "demo repository", + disabled: false, + downloads_url: "https://api.github.com/repos/bmsteven/demo/downloads", + events_url: "https://api.github.com/repos/bmsteven/demo/events", + fork: false, + forks: 0, + forks_count: 0, + forks_url: "https://api.github.com/repos/bmsteven/demo/forks", + full_name: "bmsteven/demo", + git_commits_url: + "https://api.github.com/repos/bmsteven/demo/git/commits{/sha}", + git_refs_url: "https://api.github.com/repos/bmsteven/demo/git/refs{/sha}", + git_tags_url: "https://api.github.com/repos/bmsteven/demo/git/tags{/sha}", + git_url: "git://github.com/bmsteven/demo.git", + has_downloads: true, + has_issues: true, + has_pages: false, + has_projects: true, + has_wiki: true, + homepage: null, + hooks_url: "https://api.github.com/repos/bmsteven/demo/hooks", + html_url: "https://github.com/bmsteven/demo", + id: 177733530, + is_template: false, + issue_comment_url: + "https://api.github.com/repos/bmsteven/demo/issues/comments{/number}", + issue_events_url: + "https://api.github.com/repos/bmsteven/demo/issues/events{/number}", + issues_url: "https://api.github.com/repos/bmsteven/demo/issues{/number}", + keys_url: "https://api.github.com/repos/bmsteven/demo/keys{/key_id}", + labels_url: "https://api.github.com/repos/bmsteven/demo/labels{/name}", + language: "JavaScript", + languages_url: "https://api.github.com/repos/bmsteven/demo/languages", + license: null, + master_branch: "master", + merges_url: "https://api.github.com/repos/bmsteven/demo/merges", + milestones_url: + "https://api.github.com/repos/bmsteven/demo/milestones{/number}", + mirror_url: null, + name: "demo", + node_id: "MDEwOlJlcG9zaXRvcnkxNzc3MzM1MzA=", + notifications_url: + "https://api.github.com/repos/bmsteven/demo/notifications{?since,all,participating}", + open_issues: 0, + open_issues_count: 0, + owner: { + avatar_url: "https://avatars.githubusercontent.com/u/48621248?v=4", + email: "48621248+bmsteven@users.noreply.github.com", + events_url: "https://api.github.com/users/bmsteven/events{/privacy}", + followers_url: "https://api.github.com/users/bmsteven/followers", + following_url: + "https://api.github.com/users/bmsteven/following{/other_user}", + gists_url: "https://api.github.com/users/bmsteven/gists{/gist_id}", + gravatar_id: "", + html_url: "https://github.com/bmsteven", + id: 48621248, + login: "bmsteven", + name: "bmsteven", + node_id: "MDQ6VXNlcjQ4NjIxMjQ4", + organizations_url: "https://api.github.com/users/bmsteven/orgs", + received_events_url: + "https://api.github.com/users/bmsteven/received_events", + repos_url: "https://api.github.com/users/bmsteven/repos", + site_admin: false, + starred_url: + "https://api.github.com/users/bmsteven/starred{/owner}{/repo}", + subscriptions_url: "https://api.github.com/users/bmsteven/subscriptions", + type: "User", + url: "https://api.github.com/users/bmsteven", + }, + private: false, + pulls_url: "https://api.github.com/repos/bmsteven/demo/pulls{/number}", + pushed_at: 1650646867, + releases_url: "https://api.github.com/repos/bmsteven/demo/releases{/id}", + size: 169, + ssh_url: "git@github.com:bmsteven/demo.git", + stargazers: 0, + stargazers_count: 0, + stargazers_url: "https://api.github.com/repos/bmsteven/demo/stargazers", + statuses_url: "https://api.github.com/repos/bmsteven/demo/statuses/{sha}", + subscribers_url: "https://api.github.com/repos/bmsteven/demo/subscribers", + subscription_url: "https://api.github.com/repos/bmsteven/demo/subscription", + svn_url: "https://github.com/bmsteven/demo", + tags_url: "https://api.github.com/repos/bmsteven/demo/tags", + teams_url: "https://api.github.com/repos/bmsteven/demo/teams", + topics: [], + trees_url: "https://api.github.com/repos/bmsteven/demo/git/trees{/sha}", + updated_at: "2022-04-20T22:35:19Z", + url: "https://github.com/bmsteven/demo", + visibility: "public", + watchers: 0, + watchers_count: 0, + }, + sender: { + avatar_url: "https://avatars.githubusercontent.com/u/48621248?v=4", + events_url: "https://api.github.com/users/bmsteven/events{/privacy}", + followers_url: "https://api.github.com/users/bmsteven/followers", + following_url: + "https://api.github.com/users/bmsteven/following{/other_user}", + gists_url: "https://api.github.com/users/bmsteven/gists{/gist_id}", + gravatar_id: "", + html_url: "https://github.com/bmsteven", + id: 48621248, + login: "bmsteven", + node_id: "MDQ6VXNlcjQ4NjIxMjQ4", + organizations_url: "https://api.github.com/users/bmsteven/orgs", + received_events_url: + "https://api.github.com/users/bmsteven/received_events", + repos_url: "https://api.github.com/users/bmsteven/repos", + site_admin: false, + starred_url: "https://api.github.com/users/bmsteven/starred{/owner}{/repo}", + subscriptions_url: "https://api.github.com/users/bmsteven/subscriptions", + type: "User", + url: "https://api.github.com/users/bmsteven", + }, +}; diff --git a/src/develop_actions.js b/src/develop_actions.js new file mode 100644 index 0000000..f75b47a --- /dev/null +++ b/src/develop_actions.js @@ -0,0 +1,60 @@ +const axios = require("axios"); +const github = require("@actions/github"); +const core = require("@actions/core"); +// const response = require("../res"); + +const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN"); +const octokit = github.getOctokit(GITHUB_TOKEN); +const { context = {} } = github; + +const run = async () => { + try { + const branch_name = context.payload?.head_commit?.message + ?.split("from")[1] + .split("\n")[0] + ?.split("/") + .slice(1) + .join("/"); + + console.log("branch name", branch_name); + console.log("full name", context.payload?.full_name); + console.log("owner", context.payload?.owner?.login); + console.log("repo", context.payload?.repository?.name); + + console.log("commits", context.payload?.commits); + let commits = ""; + + context.payload?.commits?.forEach((e, i) => { + if ( + !e.message.includes("Merge") && + !e.message.includes("Merged") && + !e.message.includes("skip") && + !e.message.includes("Skip") + ) + commits = + commits + i !== 0 ? "> " + e.message : "\n\n" + "> " + e.message; + }); + + console.log("formatted commits", commits); + + const createpr = await octokit.request( + `POST /repos/${context.payload?.full_name}/pulls`, + { + owner: context.payload?.owner?.login, + repo: context.payload?.repository?.name, + title: branch_name, + body: commits, + head: branch_name, + base: "staging", + } + ); + console.log("createPr", createpr?.data); + } catch (error) { + console.log("error", error?.message); + } +}; + +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##*/}