nim-lang / nimble

Package manager for the Nim programming language.
https://nim-lang.github.io/nimble/index.html
Other
1.25k stars 190 forks source link

`nimble publish` works through all the steps except for the final PR creation #652

Open kaushalmodi opened 5 years ago

kaushalmodi commented 5 years ago

Hello,

Today I was trying to publish a new package (now PR'ed manually: https://github.com/nim-lang/packages/pull/1076).

I tried the nimble publish command and I got:

> nimble publish
      Info: Using GitHub API Token in file: /home/kmodi/.nimble/github_api_token
   Success: Verified as kaushalmodi
    Copying packages fork into: /tmp/nimble-packages-fork
   Updating the fork
    Prompt: Whitespace separated list of tags?
    Answer: dpi-c systemverilog foreign-function interface
    Pushing to remote of fork.
       Info Creating PR
../../../lib/pure/httpclient.nim(997) responseContent
Error: unhandled exception: 422 Unprocessable Entity [HttpRequestError]

So it successfully created the fork, a branch with the correct changes in that fork, but just failed at the PR creation.


Version info

nimble --version

nimble v0.9.0 compiled at 2019-05-06 21:46:20
git hash: f17eaef7957da23aab6e375400b37227394a632a

nim --version

Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-05-06
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 2475d92c36e26e44372175c2cf4c21fbab084619
active boot switches: -d:release
genotrance commented 5 years ago

Do you see this every time or sporadically? I just tried from Linux with latest devel and it worked just fine. I couldn't find anything useful around 422 for PR creation.

Related: https://github.com/nim-lang/nimble/issues/594

kaushalmodi commented 5 years ago

Yes, I've seen this every time. Every time I do nimble publish (I think I have done 3 times), it goes all the way to submitting the PR, and then I get this error. Then I go to github.com, take the nimble publish created branch and submit the PR manually.

genotrance commented 5 years ago

I've seen protocol error before but never this. Can you check if you have the right permissions on the oauth token you are using?

kaushalmodi commented 5 years ago

I have deleted and recreated the token with the nimble suggested public_repo scope and even the full repo scope, and still I get the same error.

Seems like the httpclient.nim code has changed, so the line number in the error has changed:

    Pushing to remote of fork.
       Info Creating PR
../../../lib/pure/httpclient.nim(1012) responseContent
Error: unhandled exception: 422 Unprocessable Entity [HttpRequestError]
kaushalmodi commented 5 years ago

I attempted a little bit of debug, but I didn't get anything useful:

I added debug statements to the createPullRequest proc:

# Added import strformat at the top
proc createPullRequest(a: Auth, packageName, branch: string): string =
  display("Info", "Creating PR", priority = HighPriority)
  let
    url = ReposUrl & "nim-lang/packages/pulls"
    bodyStr = """{"title": "Add package $1", "head": "$2:$3", "base": "master"}""" % [packageName, a.user, branch]
  echo &"dbg: {url}"
  echo &"dbg: {bodyStr}"
  var body = a.http.postContent(url, body=bodyStr)
  echo &"dbg: {body}"
  var pr = parseJson(body)
  return pr{"html_url"}.getStr()

This was the output:

> /home/kmodi/sandbox/nim/nimble/nimble publish
      Info: Using GitHub API Token in file: /home/kmodi/.nimble/github_api_token
   Success: Verified as kaushalmodi
    Copying packages fork into: /tmp/nimble-packages-fork
   Updating the fork
    Prompt: Whitespace separated list of tags?
    Answer: asdf
    Pushing to remote of fork.
       Info Creating PR
dbg: https://api.github.com/repos/nim-lang/packages/pulls
dbg: {"title": "Add package svdpi", "head": "kaushalmodi:add-svdpi0509", "base": "master"}
nimble.nim(1145)         nimble
nimble.nim(1110)         doAction
publish.nim(229)         publish
publish.nim(104)         createPullRequest
httpclient.nim(1077)     postContent
httpclient.nim(1012)     responseContent
Error: unhandled exception: 422 Unprocessable Entity [HttpRequestError]
kaushalmodi commented 5 years ago

OK, I figured out the problem.

Earlier my "packages" repo fork was at https://github.com/kaushalmodi/packages. At some point I moved it to my "forks Organization". So the new URL was https://github.com/kaushalmodi-forks/packages.

GitHub auto-redirected https://github.com/kaushalmodi-forks/packages to https://github.com/kaushalmodi/packages.

That's when this issue was happening.

Now I once again moved that fork from my "kaushalmodi-forks" Organization to my "kaushalmodi" username, and this issue got resolved.

(Now https://github.com/kaushalmodi-forks/packages redirects to https://github.com/kaushalmodi/packages.)

So closing this issue.


I was successfully able to create this test PR: https://github.com/nim-lang/packages/pull/1089

dom96 commented 5 years ago

This is still a bug, any way we could catch this and print a nicer error?