go-github icon indicating copy to clipboard operation
go-github copied to clipboard

Repositories.Edit errors when migrating from 0.42 to 0.45

Open souleb opened this issue 3 years ago • 6 comments

Hi,

We are migrating from v0.42 to v0.45 and we get the following error when calling repositories.Edit:

<*github.ErrorResponse | 0xc000346410>{
                  Response: {
                      Status: "422 Unprocessable Entity",
                      StatusCode: 422,
                      Proto: "HTTP/2.0",
                      ProtoMajor: 2,
                      ProtoMinor: 0,
                      Header: {
                          "Date": [
                              "Tue, 21 Jun 2022 15:34:00 GMT",
                          ],
                          "X-Xss-Protection": ["0"],
                          "X-Github-Request-Id": [
                              "0400:098F:C3462:177AFA:62B1E4E7",
                          ],
                          "Server": ["GitHub.com"],
                          "Content-Type": [
                              "application/json; charset=utf-8",
                          ],
                          "X-Ratelimit-Reset": ["1655829232"],
                          "Strict-Transport-Security": [
                              "max-age=31536000; includeSubdomains; preload",
                          ],
                          "X-Frame-Options": ["deny"],
                          "X-Content-Type-Options": ["nosniff"],
                          "Content-Security-Policy": ["default-src 'none'"],
                          "X-Oauth-Scopes": [
                              "admin:org, delete_repo, repo",
                          ],
                          "X-Github-Media-Type": [
                              "github.v3; param=baptiste-preview.nebula-preview; format=json",
                          ],
                          "X-Ratelimit-Limit": ["5000"],
                          "X-Ratelimit-Remaining": ["4985"],
                          "X-Ratelimit-Used": ["15"],
                          "Access-Control-Allow-Origin": ["*"],
                          "Content-Length": ["160"],
                          "X-Accepted-Oauth-Scopes": [""],
                          "X-Ratelimit-Resource": ["core"],
                          "Access-Control-Expose-Headers": [
                              "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
                          ],
                          "Referrer-Policy": [
                              "origin-when-cross-origin, strict-origin-when-cross-origin",
                          ],
                          "Vary": [
                              "Accept-Encoding, Accept, X-Requested-With",
                          ],
                      },
                      Body: <io.nopCloser>{
                          Reader: <*bytes.Buffer | 0xc0003643f0>{
                              buf: "{\"message\":\"This organization does not allow private repository forking\",\"documentation_url\":\"https://docs.github.com/rest/reference/repos#update-a-repository\"}",
                              off: 0,
                              lastRead: 0,
                          },
                      },
                      TransferEncoding: nil,
                      Close: false,
                      Uncompressed: false,
                      Trailer: nil,
                      Request: {
                          Method: "PATCH",
                          URL: {
                              Scheme: "https",
                              Opaque: "",
                              User: nil,
                              Host: "api.github.com",
                              Path: "/repos/***-testing/test-repo-292",
                              RawPath: "",
                              ForceQuery: false,
                              RawQuery: "",
                              Fragment: "",
                              RawFragment: "",
                          },
                          Proto: "HTTP/1.1",
                          ProtoMajor: 1,
                          ProtoMinor: 1,

The message states This organisation does not allow private repository forking. When we enable forking for private repos in the org, everything work fine again. But we should not have to do this as we are simply trying to update the description when getting the above error.

As it is now, we cannot upgrade to 0.45 as it would break our users instrumentation.

souleb avatar Jun 22 '22 08:06 souleb

After a quick scan of the changes from v42.0.0 to v45.2.0, it is not obvious to me why there was a regression.

To help quickly debug this, please add https://github.com/gmlewis/go-httpdebug to your client, then run the command with v42.0.0, and run again with v45.2.0 and copy the resulting curl-equivalent command to this issue for both cases, and we can see what changed.

Thank you, and I apologize for the breakage.

gmlewis avatar Jun 22 '22 11:06 gmlewis

v42.0.0

 2022/06/22 14:04:58 curl -X PATCH \
   https://api.github.com/repos/***-testing/test-repo-750
   -H 'Accept: application/vnd.github.baptiste-preview+json, application/vnd.github.nebula-preview+json' \
   -H 'Content-Type: application/json' \
   -H 'User-Agent: go-github' \
   -d '{"id":506273200,"node_id":"***","owner":{"login":"***-testing","id":69147387,"node_id":"***","avatar_url":"https://avatars.githubusercontent.com/u/69147387?    v=4","html_url":"https://github.com/***-testing","gravatar_id":"","type":"Organization","site_admin":false,"url":"https://api.github.com/users/***-testing","events_url":"https://api.github.com/users/***- testing/events{/privacy}","following_url":"https://api.github.com/users/***-testing/following{/other_user}","followers_url":"https://api.github.com/users/***-testing/followers","gists_url":"https://api.  github.com/users/***-testing/gists{/gist_id}","organizations_url":"https://api.github.com/users/***-testing/orgs","received_events_url":"https://api.github.com/users/***-testing/received_events",         "repos_url":"https://api.github.com/users/***-testing/repos","starred_url":"https://api.github.com/users/***-testing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/***-testing/ subscriptions"},"name":"test-repo-750","full_name":"***-testing/test-repo-750","description":"New description","default_branch":"main","created_at":"2022-06-22T14:04:55Z","pushed_at":"2022-06-22T14:04:   55Z","updated_at":"2022-06-22T14:04:55Z","html_url":"https://github.com/***-testing/test-repo-750","clone_url":"https://github.com/***-testing/test-repo-750.git","git_url":"git://github.com/***-testing/  test-repo-750.git","ssh_url":"[email protected]:***-testing/test-repo-750.git","svn_url":"https://github.com/***-testing/test-repo-750","fork":false,"forks_count":0,"network_count":0,"open_issues_count":0,  "open_issues":0,"stargazers_count":0,"subscribers_count":1,"watchers_count":0,"watchers":0,"size":0,"organization":{"login":"***-testing","id":69147387,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5MTQ3Mzg3",       "avatar_url":"https://avatars.githubusercontent.com/u/69147387?v=4","html_url":"https://github.com/***-testing","type":"Organization","url":"https://api.github.com/users/***-testing","events_url":        "https://api.github.com/users/***-testing/events{/privacy}","repos_url":"https://api.github.com/users/***-testing/repos"},"permissions":{"admin":true,"maintain":true,"pull":true,"push":true,"triage":     true},"allow_rebase_merge":true,"allow_squash_merge":true,"allow_merge_commit":true,"allow_auto_merge":false,"delete_branch_on_merge":false,"archived":false,"disabled":false,"license":{"key":"apache-2.   0","name":"Apache License 2.0","url":"https://api.github.com/licenses/apache-2.0","spdx_id":"Apache-2.0"},"private":true,"has_issues":true,"has_wiki":true,"has_pages":false,"has_projects":true,           "has_downloads":true,"is_template":false,"url":"https://api.github.com/repos/***-testing/test-repo-750","archive_url":"https://api.github.com/repos/***-testing/test-repo-750/{archive_format}{/ref}",      "assignees_url":"https://api.github.com/repos/***-testing/test-repo-750/assignees{/user}","blobs_url":"https://api.github.com/repos/***-testing/test-repo-750/git/blobs{/sha}","branches_url":"https://api. github.com/repos/***-testing/test-repo-750/branches{/branch}","collaborators_url":"https://api.github.com/repos/***-testing/test-repo-750/collaborators{/collaborator}","comments_url":"https://api.github. com/repos/***-testing/test-repo-750/comments{/number}","commits_url":"https://api.github.com/repos/***-testing/test-repo-750/commits{/sha}","compare_url":"https://api.github.com/repos/***-testing/test-   repo-750/compare/{base}...{head}","contents_url":"https://api.github.com/repos/***-testing/test-repo-750/contents/{+path}","contributors_url":"https://api.github.com/repos/***-testing/test-repo-750/      contributors","deployments_url":"https://api.github.com/repos/***-testing/test-repo-750/deployments","downloads_url":"https://api.github.com/repos/***-testing/test-repo-750/downloads","events_url":       "https://api.github.com/repos/***-testing/test-repo-750/events","forks_url":"https://api.github.com/repos/***-testing/test-repo-750/forks","git_commits_url":"https://api.github.com/repos/***-testing/     test-repo-750/git/commits{/sha}","git_refs_url":"https://api.github.com/repos/***-testing/test-repo-750/git/refs{/sha}","git_tags_url":"https://api.github.com/repos/***-testing/test-repo-750/git/tags{/   sha}","hooks_url":"https://api.github.com/repos/***-testing/test-repo-750/hooks","issue_comment_url":"https://api.github.com/repos/***-testing/test-repo-750/issues/comments{/number}","issue_events_url":  "https://api.github.com/repos/***-testing/test-repo-750/issues/events{/number}","issues_url":"https://api.github.com/repos/***-testing/test-repo-750/issues{/number}","keys_url":"https://api.github.com/   repos/***-testing/test-repo-750/keys{/key_id}","labels_url":"https://api.github.com/repos/***-testing/test-repo-750/labels{/name}","languages_url":"https://api.github.com/repos/***-testing/test-repo-750/ languages","merges_url":"https://api.github.com/repos/***-testing/test-repo-750/merges","milestones_url":"https://api.github.com/repos/***-testing/test-repo-750/milestones{/number}","notifications_url":  "https://api.github.com/repos/***-testing/test-repo-750/notifications{?since,all,participating}","pulls_url":"https://api.github.com/repos/***-testing/test-repo-750/pulls{/number}","releases_url":        "https://api.github.com/repos/***-testing/test-repo-750/releases{/id}","stargazers_url":"https://api.github.com/repos/***-testing/test-repo-750/stargazers","statuses_url":"https://api.github.com/         repos/***-testing/test-repo-750/statuses/{sha}","subscribers_url":"https://api.github.com/repos/***-testing/test-repo-750/subscribers","subscription_url":"https://api.github.com/repos/***-testing/test-   repo-750/subscription","tags_url":"https://api.github.com/repos/***-testing/test-repo-750/tags","trees_url":"https://api.github.com/repos/***-testing/test-repo-750/git/trees{/sha}","teams_url":"https://  api.github.com/repos/***-testing/test-repo-750/teams","visibility":"private"}
 '

v45.2.0

2022/06/22 13:40:16 curl -X PATCH \
 [ https://api.github.com/repos/***-testing/test-repo-2](https://api.github.com/repos/***-testing/test-repo-213)13 
  -H 'Accept: application/vnd.github.baptiste-preview+json, application/vnd.github.nebula-preview+json' \
  -H 'Content-Type: application/json' \
  -H 'User-Agent: go-github' \
  -d '{"id":506263912,"node_id":"***","owner":{"login":"***-testing","id":69147387,"node_id":"***","avatar_url":"https://avatars.githubusercontent.com/u/69147387?v=4","html_url":"https://github.com/***-testing","gravatar_id":"","type":"Organization","site_admin":false,"url":"https://api.github.com/users/***-testing","events_url":"[https://api.github.com/users/***-testing/events{/privacy}](https://api.github.com/users/***-testing/events%7B/privacy%7D)","following_url":"[https://api.github.com/users/***-testing/following{/other_user}](https://api.github.com/users/***-testing/following%7B/other_user%7D)","followers_url":"https://api.github.com/users/***-testing/followers","gists_url":"[https://api.github.com/users/***-testing/gists{/gist_id}](https://api.github.com/users/***-testing/gists%7B/gist_id%7D)","organizations_url":"https://api.github.com/users/***-testing/orgs","received_events_url":"https://api.github.com/users/***-testing/received_events","repos_url":"https://api.github.com/users/***-testing/repos","starred_url":"[https://api.github.com/users/***-testing/starred{/owner}{/repo}](https://api.github.com/users/***-testing/starred%7B/owner%7D%7B/repo%7D)","subscriptions_url":"https://api.github.com/users/***-testing/subscriptions"},"name":"test-repo-213","full_name":"***-testing/test-repo-213","description":"New description","default_branch":"main","created_at":"2022-06-22T13:40:13Z","pushed_at":"2022-06-22T13:40:13Z","updated_at":"2022-06-22T13:40:13Z","html_url":"https://github.com/***-testing/test-repo-213","clone_url":"https://github.com/***-testing/test-repo-213.git","git_url":"git://github.com/***-testing/test-repo-213.git","ssh_url":"[email protected]:***-testing/test-repo-213.git","svn_url":"https://github.com/***-testing/test-repo-213","fork":false,"forks_count":0,"network_count":0,"open_issues_count":0,"open_issues":0,"stargazers_count":0,"subscribers_count":1,"watchers_count":0,"watchers":0,"size":0,"organization":{"login":"***-testing","id":69147387,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5MTQ3Mzg3","avatar_url":"https://avatars.githubusercontent.com/u/69147387?v=4","html_url":"https://github.com/***-testing","type":"Organization","url":"https://api.github.com/users/***-testing","events_url":"[https://api.github.com/users/***-testing/events{/privacy}](https://api.github.com/users/***-testing/events%7B/privacy%7D)","repos_url":"https://api.github.com/users/***-testing/repos"},"permissions":{"admin":true,"maintain":true,"pull":true,"push":true,"triage":true},"allow_rebase_merge":true,"allow_update_branch":false,"allow_squash_merge":true,"allow_merge_commit":true,"allow_auto_merge":false,"allow_forking":false,"delete_branch_on_merge":false,"use_squash_pr_title_as_default":false,"archived":false,"disabled":false,"private":true,"has_issues":true,"has_wiki":true,"has_pages":false,"has_projects":true,"has_downloads":true,"is_template":false,"url":"https://api.github.com/repos/***-testing/test-repo-213","archive_url":"[https://api.github.com/repos/***-testing/test-repo-213/{archive_format}{/ref}](https://api.github.com/repos/***-testing/test-repo-213/%7Barchive_format%7D%7B/ref%7D)","assignees_url":"[https://api.github.com/repos/***-testing/test-repo-213/assignees{/user}](https://api.github.com/repos/***-testing/test-repo-213/assignees%7B/user%7D)","blobs_url":"[https://api.github.com/repos/***-testing/test-repo-213/git/blobs{/sha}](https://api.github.com/repos/***-testing/test-repo-213/git/blobs%7B/sha%7D)","branches_url":"[https://api.github.com/repos/***-testing/test-repo-213/branches{/branch}](https://api.github.com/repos/***-testing/test-repo-213/branches%7B/branch%7D)","collaborators_url":"[https://api.github.com/repos/***-testing/test-repo-213/collaborators{/collaborator}](https://api.github.com/repos/***-testing/test-repo-213/collaborators%7B/collaborator%7D)","comments_url":"[https://api.github.com/repos/***-testing/test-repo-213/comments{/number}](https://api.github.com/repos/***-testing/test-repo-213/comments%7B/number%7D)","commits_url":"[https://api.github.com/repos/***-testing/test-repo-213/commits{/sha}](https://api.github.com/repos/***-testing/test-repo-213/commits%7B/sha%7D)","compare_url":"[https://api.github.com/repos/***-testing/test-repo-213/compare/{base}...{head}](https://api.github.com/repos/***-testing/test-repo-213/compare/%7Bbase%7D...%7Bhead%7D)","contents_url":"[https://api.github.com/repos/***-testing/test-repo-213/contents/{+path}](https://api.github.com/repos/***-testing/test-repo-213/contents/%7B+path%7D)","contributors_url":"https://api.github.com/repos/***-testing/test-repo-213/contributors","deployments_url":"https://api.github.com/repos/***-testing/test-repo-213/deployments","downloads_url":"https://api.github.com/repos/***-testing/test-repo-213/downloads","events_url":"https://api.github.com/repos/***-testing/test-repo-213/events","forks_url":"https://api.github.com/repos/***-testing/test-repo-213/forks","git_commits_url":"[https://api.github.com/repos/***-testing/test-repo-213/git/commits{/sha}](https://api.github.com/repos/***-testing/test-repo-213/git/commits%7B/sha%7D)","git_refs_url":"[https://api.github.com/repos/***-testing/test-repo-213/git/refs{/sha}](https://api.github.com/repos/***-testing/test-repo-213/git/refs%7B/sha%7D)","git_tags_url":"[https://api.github.com/repos/***-testing/test-repo-213/git/tags{/sha}](https://api.github.com/repos/***-testing/test-repo-213/git/tags%7B/sha%7D)","hooks_url":"https://api.github.com/repos/***-testing/test-repo-213/hooks","issue_comment_url":"[https://api.github.com/repos/***-testing/test-repo-213/issues/comments{/number}](https://api.github.com/repos/***-testing/test-repo-213/issues/comments%7B/number%7D)","issue_events_url":"[https://api.github.com/repos/***-testing/test-repo-213/issues/events{/number}](https://api.github.com/repos/***-testing/test-repo-213/issues/events%7B/number%7D)","issues_url":"[https://api.github.com/repos/***-testing/test-repo-213/issues{/number}](https://api.github.com/repos/***-testing/test-repo-213/issues%7B/number%7D)","keys_url":"[https://api.github.com/repos/***-testing/test-repo-213/keys{/key_id}](https://api.github.com/repos/***-testing/test-repo-213/keys%7B/key_id%7D)","labels_url":"[https://api.github.com/repos/***-testing/test-repo-213/labels{/name}](https://api.github.com/repos/***-testing/test-repo-213/labels%7B/name%7D)","languages_url":"https://api.github.com/repos/***-testing/test-repo-213/languages","merges_url":"https://api.github.com/repos/***-testing/test-repo-213/merges","milestones_url":"[https://api.github.com/repos/***-testing/test-repo-213/milestones{/number}](https://api.github.com/repos/***-testing/test-repo-213/milestones%7B/number%7D)","notifications_url":"[https://api.github.com/repos/***-testing/test-repo-213/notifications{?since](https://api.github.com/repos/***-testing/test-repo-213/notifications%7B?since),all,participating}","pulls_url":"[https://api.github.com/repos/***-testing/test-repo-213/pulls{/number}](https://api.github.com/repos/***-testing/test-repo-213/pulls%7B/number%7D)","releases_url":"[https://api.github.com/repos/***-testing/test-repo-213/releases{/id}](https://api.github.com/repos/***-testing/test-repo-213/releases%7B/id%7D)","stargazers_url":"https://api.github.com/repos/***-testing/test-repo-213/stargazers","statuses_url":"[https://api.github.com/repos/***-testing/test-repo-213/statuses/{sha}](https://api.github.com/repos/***-testing/test-repo-213/statuses/%7Bsha%7D)","subscribers_url":"https://api.github.com/repos/***-testing/test-repo-213/subscribers","subscription_url":"https://api.github.com/repos/***-testing/test-repo-213/subscription","tags_url":"https://api.github.com/repos/***-testing/test-repo-213/tags","trees_url":"[https://api.github.com/repos/***-testing/test-repo-213/git/trees{/sha}](https://api.github.com/repos/***-testing/test-repo-213/git/trees%7B/sha%7D)","teams_url":"https://api.github.com/repos/***-testing/test-repo-213/teams","visibility":"private"}
'

the list of permissions has quite expanded.

souleb avatar Jun 22 '22 14:06 souleb

Thank you! It looks like somehow "allow_forking": false, snuck in to the second one:

ksnip_20220622-103244

Now, the question is... how did this happen?!? Investigating...

gmlewis avatar Jun 22 '22 14:06 gmlewis

Ah, yes! I believe I have seen this before.

When you call Repositories.Edit, you need to only put the values into the request that you actually want to change.

So a common mistake is to first do a Repositories.Get and then use that entire structure to send to Repositories.Edit.

In other words, your request to Repositories.Edit must be absolutely minimal with just the fields you want to change.

Let me find you the most recent case where we saw this...

gmlewis avatar Jun 22 '22 14:06 gmlewis

Please see:

  • #2292
  • #2309

You will need to change your code to not send the full repo info... but make a brand new *github.Repository struct with only the fields you want to change.

I hope that helps.

gmlewis avatar Jun 22 '22 14:06 gmlewis

ok I will try that.

souleb avatar Jun 22 '22 15:06 souleb

Thanks again. Closing this now.

souleb avatar Sep 08 '22 12:09 souleb