{"id":13898121,"url":"https://github.com/gr2m/octokit-plugin-create-pull-request","last_synced_at":"2025-04-08T01:39:53.623Z","repository":{"id":38176201,"uuid":"161698526","full_name":"gr2m/octokit-plugin-create-pull-request","owner":"gr2m","description":"Octokit plugin to create a pull request with multiple file changes","archived":false,"fork":false,"pushed_at":"2024-09-30T20:27:30.000Z","size":1708,"stargazers_count":104,"open_issues_count":13,"forks_count":28,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-29T23:49:52.154Z","etag":null,"topics":["javascript","octokit","plugin"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gr2m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"gr2m"}},"created_at":"2018-12-13T21:47:33.000Z","updated_at":"2024-09-30T20:27:32.000Z","dependencies_parsed_at":"2023-02-12T13:46:04.981Z","dependency_job_id":"c42f0fbe-4396-4d9b-ac75-363d4f5a4b00","html_url":"https://github.com/gr2m/octokit-plugin-create-pull-request","commit_stats":{"total_commits":157,"total_committers":20,"mean_commits":7.85,"dds":0.5732484076433121,"last_synced_commit":"170a12422edc53e6b01367c2b19070e23752d35e"},"previous_names":["gr2m/octokit-create-pull-request"],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-plugin-create-pull-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-plugin-create-pull-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-plugin-create-pull-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-plugin-create-pull-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gr2m","download_url":"https://codeload.github.com/gr2m/octokit-plugin-create-pull-request/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247750582,"owners_count":20989789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","octokit","plugin"],"created_at":"2024-08-06T18:04:05.693Z","updated_at":"2025-04-08T01:39:53.606Z","avatar_url":"https://github.com/gr2m.png","language":"TypeScript","funding_links":["https://github.com/sponsors/gr2m"],"categories":["TypeScript"],"sub_categories":[],"readme":"# octokit-plugin-create-pull-request\n\n\u003e Octokit plugin to create a pull request with multiple file changes\n\n[![@latest](https://img.shields.io/npm/v/octokit-plugin-create-pull-request.svg)](https://www.npmjs.com/package/octokit-plugin-create-pull-request)\n[![Build Status](https://github.com/gr2m/octokit-plugin-create-pull-request/workflows/Test/badge.svg)](https://github.com/gr2m/octokit-plugin-create-pull-request/actions?query=workflow%3ATest+branch%3Amain)\n\nFeatures\n\n- Retrieves the repository’s default branch unless `base` branch is set\n- Makes multiple file changes using a single commit\n- Creates a fork if the authenticated user does not have write access to the repository\n- Can update existing pull request\n\n## Usage\n\n\u003ctable\u003e\n\u003ctbody valign=top align=left\u003e\n\u003ctr\u003e\u003cth\u003e\nBrowsers\n\u003c/th\u003e\u003ctd width=100%\u003e\n\nLoad `octokit-plugin-create-pull-request` and [`@octokit/core`](https://github.com/octokit/core.js) (or core-compatible module) directly from [esm.sh](https://esm.sh)\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { Octokit } from \"https://esm.sh/@octokit/core\";\n  import { createPullRequest } from \"https://esm.sh/octokit-plugin-create-pull-request\";\n\u003c/script\u003e\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth\u003e\nNode\n\u003c/th\u003e\u003ctd\u003e\n\nInstall with `npm install @octokit/core octokit-plugin-create-pull-request`. Optionally replace `@octokit/core` with a core-compatible module\n\n```js\nimport { Octokit } from \"@octokit/core\";\nimport {\n  createPullRequest,\n  DELETE_FILE,\n} from \"octokit-plugin-create-pull-request\";\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003e [!IMPORTANT]\n\u003e As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `\"moduleResolution\": \"node16\", \"module\": \"node16\"`.\n\u003e\n\u003e See the TypeScript docs on [package.json \"exports\"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).\u003cbr\u003e\n\u003e See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)\n\n```js\nconst MyOctokit = Octokit.plugin(createPullRequest);\n\nconst TOKEN = \"secret123\"; // create token at https://github.com/settings/tokens/new?scopes=repo\nconst octokit = new MyOctokit({\n  auth: TOKEN,\n});\n\n// Returns a normal Octokit PR response\n// See https://octokit.github.io/rest.js/#octokit-routes-pulls-create\noctokit\n  .createPullRequest({\n    owner: \"user-or-org-login\",\n    repo: \"repo-name\",\n    title: \"pull request title\",\n    body: \"pull request description\",\n    head: \"pull-request-branch-name\",\n    base: \"main\" /* optional: defaults to default branch */,\n    update: false /* optional: set to `true` to enable updating existing pull requests */,\n    forceFork: false /* optional: force creating fork even when user has write rights */,\n    labels: [\n      \"bug\",\n    ] /* optional: applies the given labels when user has permissions. When updating an existing pull request, already present labels will not be deleted. */\n    changes: [\n      {\n        /* optional: if `files` is not passed, an empty commit is created instead */\n        files: {\n          \"path/to/file1.txt\": \"Content for file1\",\n          \"path/to/file2.png\": {\n            content: \"_base64_encoded_content_\",\n            encoding: \"base64\",\n          },\n          // deletes file if it exists,\n          \"path/to/file3.txt\": DELETE_FILE,\n          // updates file based on current content\n          \"path/to/file4.txt\": ({ exists, encoding, content }) =\u003e {\n            // do not create the file if it does not exist\n            if (!exists) return null;\n\n            return Buffer.from(content, encoding)\n              .toString(\"utf-8\")\n              .toUpperCase();\n          },\n          \"path/to/file5.sh\": {\n            content: \"echo Hello World\",\n            encoding: \"utf-8\",\n            // one of the modes supported by the git tree object\n            // https://developer.github.com/v3/git/trees/#tree-object\n            mode: \"100755\",\n          },\n          \"path/to/file6.txt\": ({ exists, encoding, content }) =\u003e {\n            // do nothing if it does not exist\n            if (!exists) return null;\n\n            const fileContent = Buffer.from(content, encoding).toString(\n              \"utf-8\"\n            );\n\n            if (fileContent.includes(\"octomania\")) {\n              // delete file\n              return DELETE_FILE;\n            }\n\n            // keep file\n            return null;\n          },\n        },\n        commit:\n          \"creating file1.txt, file2.png, deleting file3.txt, updating file4.txt (if it exists), file5.sh\",\n        /* optional: if not passed, will be the authenticated user and the current date */\n        author: {\n          name: \"Author LastName\",\n          email: \"Author.LastName@acme.com\",\n          date: new Date().toISOString(), // must be ISO date string\n        },\n        /* optional: if not passed, will use the information set in author */\n        committer: {\n          name: \"Committer LastName\",\n          email: \"Committer.LastName@acme.com\",\n          date: new Date().toISOString(), // must be ISO date string\n        },\n        /* optional: if not passed, commit won't be signed*/\n        signature: async function (commitPayload) {\n          // import { createSignature } from 'github-api-signature'\n          //\n          // return createSignature(\n          //   commitPayload,\n          //   privateKey,\n          //   passphrase\n          // );\n        },\n      },\n    ],\n  })\n  .then((pr) =\u003e console.log(pr.data.number));\n```\n\nBy default, a pull request is created, even if no files have been changed. To prevent an empty pull request, set `options.createWhenEmpty` to `false`. If no pull request has been created, `octokit.createPullRequest()` resolves with `null`.\n\nBy default, commits are always created, even if no files have been updated. To prevent empty commits, set `options.changes[].emptyCommit` to `false`. To set a custom commit message for empty commits, set `emptyCommit` to a string.\n\nFor using this plugin with another plugin, you can import the `composeCreatePullRequest` function, which accepts an `octokit` instance as first argument, and the same options as `octokit.createPullRequest` as second argument.\n\n```js\nimport { Octokit } from \"@octokit/core\";\nimport { composeCreatePullRequest } from \"octokit-plugin-create-pull-request\";\n\nexport function myPlugin(octokit) {\n  return {\n    async myFunction(options) {\n      // custom code here\n\n      const response = await composeCreatePullRequest(octokit, options);\n\n      // more custom code here\n\n      return response;\n    },\n  };\n}\n```\n\n## LICENSE\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgr2m%2Foctokit-plugin-create-pull-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgr2m%2Foctokit-plugin-create-pull-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgr2m%2Foctokit-plugin-create-pull-request/lists"}