Skip to content

Commit

Permalink
fix: replace @octokit/rest with @octokit/core (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenkeeper[bot] authored Feb 20, 2020
1 parent bf2cc22 commit 38a9ec0
Show file tree
Hide file tree
Showing 11 changed files with 1,355 additions and 2,440 deletions.
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ Here is a script that records fixtures and logs them to stdout

```js
const TOKEN = process.env.TOKEN
const octokit = require('@octokit/rest')
.plugin(require('.'))()
const { Octokit } = require('@octokit/core')
const createPullRequest = require('.')
const MyOctokit = Octokit.plugin(createPullRequest)()
const octokit = new MyOctokit({
auth: TOKEN
})


const fixtures = []
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ Features
Update or create two files with a single commit

```js
const Octokit = require("@octokit/rest").plugin(
require("octokit-create-pull-request")
);
const { Octokit } = require("@octokit/core");
const createPullRequest = require("octokit-create-pull-request");

const MyOctokit = Octokit.plugin(createPullRequest);

const TOKEN = "secret123"; // token needs "repo" scope
const octokit = new Octokit({
auth: `token ${TOKEN}`
const octokit = new MyOctokit({
auth: TOKEN
});

// Returns a normal Octokit PR response
Expand Down
19 changes: 11 additions & 8 deletions lib/create-pull-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ async function createPullRequest(
octokit,
{ owner, repo, title, body, base, head, changes }
) {
let response = await octokit.repos.get({ owner, repo });
let response = await octokit.request("GET /repos/:owner/:repo", {
owner,
repo
});

if (!response.data.permissions) {
throw new Error("[octokit-create-pull-request] Missing authentication");
Expand All @@ -17,8 +20,8 @@ async function createPullRequest(
let fork = owner;

if (!response.data.permissions.push) {
const user = await octokit.users.getAuthenticated();
const forks = await octokit.repos.listForks({
const user = await octokit.request("GET /user");
const forks = await octokit.request("GET /repos/:owner/:repo/forks", {
owner,
repo
});
Expand All @@ -27,7 +30,7 @@ async function createPullRequest(
);

if (!hasFork) {
await octokit.repos.createFork({
await octokit.request("POST /repos/:owner/:repo/forks", {
owner,
repo
});
Expand All @@ -36,7 +39,7 @@ async function createPullRequest(
fork = user.data.login;
}

response = await octokit.repos.listCommits({
response = await octokit.request("GET /repos/:owner/:repo/commits", {
owner,
repo,
sha: base,
Expand Down Expand Up @@ -88,7 +91,7 @@ async function createPullRequest(

const newTreeSha = response.data.sha;

response = await octokit.git.createCommit({
response = await octokit.request("POST /repos/:owner/:repo/git/commits", {
owner: fork,
repo,
message: changes.commit,
Expand All @@ -97,14 +100,14 @@ async function createPullRequest(
});
latestCommitSha = response.data.sha;

await octokit.git.createRef({
await octokit.request("POST /repos/:owner/:repo/git/refs", {
owner: fork,
repo,
sha: latestCommitSha,
ref: `refs/heads/${head}`
});

return await octokit.pulls.create({
return await octokit.request("POST /repos/:owner/:repo/pulls", {
owner,
repo,
head: `${fork}:${head}`,
Expand Down
Loading

0 comments on commit 38a9ec0

Please sign in to comment.