boennemann / github-change-remote-file

♻️
16 stars 5 forks source link

422: Validation Failed #11

Closed zeke closed 8 years ago

zeke commented 8 years ago

I have the following code, derived from the README example:

require('dotenv').load()

const githubChangeRemoteFile = require('github-change-remote-file')

githubChangeRemoteFile({
  user: 'zeke',
  repo: 'standard-markdown',
  filename: 'package.json',
  transform: function (pkg) {
    pkg = JSON.parse(pkg)
    pkg.dependencies.standard = '100'
    return JSON.stringify(pkg, null, 2)
  },
  token: process.env.GITHUB_TOKEN,
  pr: {
    title: 'Testing automated PRs',
    body: 'This is a test. cc @zeke'
  }
}, function (err, res) {
  console.log(JSON.stringify(err, null, 2))
  console.log(JSON.stringify(res, null, 2))
})

When I run it, I'm getting a 422 back from GitHub.

❯ node index.js       
{
  "code": 422,
  "message": "{\"message\":\"Validation Failed\",\"errors\":[{\"resource\":\"PullRequest\",\"field\":\"head\",\"code\":\"invalid\"}],\"documentation_url\":\"https://developer.github.com/v3/pulls/#create-a-pull-request\"}"
}
undefined

I have verified that the GITHUB_TOKEN is being set, and it lots of privileges.

Am I missing something, @boennemann?

zeke commented 8 years ago

Also, when I console.log(pkg) in the transform function, I can see the changes have been made to the package object.

zeke commented 8 years ago

Bump. Any ideas, @christophwitzko or @boennemann?

christophwitzko commented 8 years ago

Hi @zeke, we have released a new major version of github-change-remote-file yesterday. I have adapted and tested your example:

const GitHubApi = require('github')
const githubChangeRemoteFile = require('github-change-remote-file')

const token = process.env.GITHUB_TOKEN

const github = new GitHubApi()
github.authenticate({type: 'oauth', token})

const repo = {
  user: 'zeke',
  repo: 'standard-markdown'
}
const newBranch = 'update-standard'

githubChangeRemoteFile(Object.assign({
  github,
  filename: 'package.json',
  newBranch,
  transform: pkg => {
    pkg = JSON.parse(pkg)
    pkg.dependencies.standard = '100'
    return JSON.stringify(pkg, null, 2) + '\n'
  }
}, repo))
.then(commit => {
  return github.pullRequests.create(Object.assign({
    title: 'Testing automated PRs',
    body: 'This is a test. cc @zeke',
    head: newBranch,
    base: 'master'
  }, repo))
})
.then(console.log)
.catch(console.log)

If you have any further questions feel free to ask.

Best, Christoph

zeke commented 8 years ago

Thanks!