Skip to content

Conversation

michelangelomo
Copy link
Contributor

Description

I've encountered an issue trying to update BranchRestriction on a personal repository. Github doesn't allow teams and users fields in the request payload.

How to reproduce

p := github.ProtectionRequest{
	Restrictions: &github.BranchRestrictionsRequest{
		Apps: []string{"myapp"},
	},
}
client.Repositories.UpdateBranchProtection(ctx, org, repo, branch, p)

will return

No subschema in "anyOf" matched.
For 'properties/users', nil is not an array.
For 'properties/teams', nil is not an array.
Not all subschemas of "allOf" matched.
For 'anyOf/1', {"users"=>nil, "teams"=>nil, "apps"=>["myapp"]} is not a null.

but if I set Teams and Users fields as []string{} Github returns 422 Validation Failed [{Resource: Field: Code: Message:Only organization repositories can have users and team restrictions}] as described above.

Fix

Allow Teams and Users fields to be empty by using omitempty.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@codecov
Copy link

codecov bot commented May 20, 2020

Codecov Report

Merging #1530 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1530   +/-   ##
=======================================
  Coverage   68.03%   68.03%           
=======================================
  Files          94       94           
  Lines        8528     8528           
=======================================
  Hits         5802     5802           
  Misses       1844     1844           
  Partials      882      882           
Impacted Files Coverage Δ
github/repos.go 70.04% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4392860...7a55b9b. Read the comment docs.

@michelangelomo
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels May 20, 2020
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @michelangelomo !
LGTM.

Awaiting second LGTM before merging.

@gmlewis gmlewis requested review from gauntface and wesleimp May 20, 2020 23:32
Copy link
Collaborator

@wesleimp wesleimp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👌

@gmlewis
Copy link
Collaborator

gmlewis commented May 21, 2020

Thank you, @wesleimp !
Merging.

@gmlewis gmlewis changed the title BranchRestriction fields can be empty Enable BranchRestriction fields to be empty May 21, 2020
@gmlewis gmlewis merged commit f093974 into google:master May 21, 2020
@michelangelomo michelangelomo deleted the restriction-fields-can-be-empty branch May 23, 2020 14:35
anGie44 added a commit to anGie44/go-github that referenced this pull request Jul 9, 2020
gmlewis pushed a commit that referenced this pull request Jul 16, 2020
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants