Skip to content

Commit 096e4ce

Browse files
refactor!: Use a struct for Repository.Permissions instead of map[string]bool (#3936)
BREAKING CHANGE: `Repository.Permissions` is now a struct instead of `map[string]bool`.
1 parent 3a3eaaf commit 096e4ce

File tree

6 files changed

+177
-75
lines changed

6 files changed

+177
-75
lines changed

github/github-accessors.go

Lines changed: 44 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 56 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-stringify_test.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos.go

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,59 @@ type RepositoriesService service
2727

2828
// Repository represents a GitHub repository.
2929
type Repository struct {
30-
ID *int64 `json:"id,omitempty"`
31-
NodeID *string `json:"node_id,omitempty"`
32-
Owner *User `json:"owner,omitempty"`
33-
Name *string `json:"name,omitempty"`
34-
FullName *string `json:"full_name,omitempty"`
35-
Description *string `json:"description,omitempty"`
36-
Homepage *string `json:"homepage,omitempty"`
37-
CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"`
38-
DefaultBranch *string `json:"default_branch,omitempty"`
39-
MasterBranch *string `json:"master_branch,omitempty"`
40-
CreatedAt *Timestamp `json:"created_at,omitempty"`
41-
PushedAt *Timestamp `json:"pushed_at,omitempty"`
42-
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
43-
HTMLURL *string `json:"html_url,omitempty"`
44-
CloneURL *string `json:"clone_url,omitempty"`
45-
GitURL *string `json:"git_url,omitempty"`
46-
MirrorURL *string `json:"mirror_url,omitempty"`
47-
SSHURL *string `json:"ssh_url,omitempty"`
48-
SVNURL *string `json:"svn_url,omitempty"`
49-
Language *string `json:"language,omitempty"`
50-
Fork *bool `json:"fork,omitempty"`
51-
ForksCount *int `json:"forks_count,omitempty"`
52-
NetworkCount *int `json:"network_count,omitempty"`
53-
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
54-
OpenIssues *int `json:"open_issues,omitempty"` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated.
55-
StargazersCount *int `json:"stargazers_count,omitempty"`
56-
SubscribersCount *int `json:"subscribers_count,omitempty"`
57-
WatchersCount *int `json:"watchers_count,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated.
58-
Watchers *int `json:"watchers,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated.
59-
Size *int `json:"size,omitempty"`
60-
AutoInit *bool `json:"auto_init,omitempty"`
61-
Parent *Repository `json:"parent,omitempty"`
62-
Source *Repository `json:"source,omitempty"`
63-
TemplateRepository *Repository `json:"template_repository,omitempty"`
64-
Organization *Organization `json:"organization,omitempty"`
65-
Permissions map[string]bool `json:"permissions,omitempty"`
66-
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
67-
AllowUpdateBranch *bool `json:"allow_update_branch,omitempty"`
68-
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
69-
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
70-
AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"`
71-
AllowForking *bool `json:"allow_forking,omitempty"`
72-
WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"`
73-
DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"`
74-
UseSquashPRTitleAsDefault *bool `json:"use_squash_pr_title_as_default,omitempty"`
75-
SquashMergeCommitTitle *string `json:"squash_merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "COMMIT_OR_PR_TITLE"
76-
SquashMergeCommitMessage *string `json:"squash_merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "COMMIT_MESSAGES", "BLANK"
77-
MergeCommitTitle *string `json:"merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "MERGE_MESSAGE"
78-
MergeCommitMessage *string `json:"merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "PR_TITLE", "BLANK"
79-
Topics []string `json:"topics,omitempty"`
80-
CustomProperties map[string]any `json:"custom_properties,omitempty"`
81-
Archived *bool `json:"archived,omitempty"`
82-
Disabled *bool `json:"disabled,omitempty"`
30+
ID *int64 `json:"id,omitempty"`
31+
NodeID *string `json:"node_id,omitempty"`
32+
Owner *User `json:"owner,omitempty"`
33+
Name *string `json:"name,omitempty"`
34+
FullName *string `json:"full_name,omitempty"`
35+
Description *string `json:"description,omitempty"`
36+
Homepage *string `json:"homepage,omitempty"`
37+
CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"`
38+
DefaultBranch *string `json:"default_branch,omitempty"`
39+
MasterBranch *string `json:"master_branch,omitempty"`
40+
CreatedAt *Timestamp `json:"created_at,omitempty"`
41+
PushedAt *Timestamp `json:"pushed_at,omitempty"`
42+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
43+
HTMLURL *string `json:"html_url,omitempty"`
44+
CloneURL *string `json:"clone_url,omitempty"`
45+
GitURL *string `json:"git_url,omitempty"`
46+
MirrorURL *string `json:"mirror_url,omitempty"`
47+
SSHURL *string `json:"ssh_url,omitempty"`
48+
SVNURL *string `json:"svn_url,omitempty"`
49+
Language *string `json:"language,omitempty"`
50+
Fork *bool `json:"fork,omitempty"`
51+
ForksCount *int `json:"forks_count,omitempty"`
52+
NetworkCount *int `json:"network_count,omitempty"`
53+
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
54+
OpenIssues *int `json:"open_issues,omitempty"` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated.
55+
StargazersCount *int `json:"stargazers_count,omitempty"`
56+
SubscribersCount *int `json:"subscribers_count,omitempty"`
57+
WatchersCount *int `json:"watchers_count,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated.
58+
Watchers *int `json:"watchers,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated.
59+
Size *int `json:"size,omitempty"`
60+
AutoInit *bool `json:"auto_init,omitempty"`
61+
Parent *Repository `json:"parent,omitempty"`
62+
Source *Repository `json:"source,omitempty"`
63+
TemplateRepository *Repository `json:"template_repository,omitempty"`
64+
Organization *Organization `json:"organization,omitempty"`
65+
Permissions *RepositoryPermissions `json:"permissions,omitempty"`
66+
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
67+
AllowUpdateBranch *bool `json:"allow_update_branch,omitempty"`
68+
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
69+
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
70+
AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"`
71+
AllowForking *bool `json:"allow_forking,omitempty"`
72+
WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"`
73+
DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"`
74+
UseSquashPRTitleAsDefault *bool `json:"use_squash_pr_title_as_default,omitempty"`
75+
SquashMergeCommitTitle *string `json:"squash_merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "COMMIT_OR_PR_TITLE"
76+
SquashMergeCommitMessage *string `json:"squash_merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "COMMIT_MESSAGES", "BLANK"
77+
MergeCommitTitle *string `json:"merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "MERGE_MESSAGE"
78+
MergeCommitMessage *string `json:"merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "PR_TITLE", "BLANK"
79+
Topics []string `json:"topics,omitempty"`
80+
CustomProperties map[string]any `json:"custom_properties,omitempty"`
81+
Archived *bool `json:"archived,omitempty"`
82+
Disabled *bool `json:"disabled,omitempty"`
8383

8484
// Only provided when using RepositoriesService.Get while in preview
8585
License *License `json:"license,omitempty"`
@@ -202,6 +202,15 @@ type SecurityAndAnalysis struct {
202202
SecretScanningValidityChecks *SecretScanningValidityChecks `json:"secret_scanning_validity_checks,omitempty"`
203203
}
204204

205+
// RepositoryPermissions represents the permissions a user has for a repository.
206+
type RepositoryPermissions struct {
207+
Admin *bool `json:"admin,omitempty"`
208+
Maintain *bool `json:"maintain,omitempty"`
209+
Push *bool `json:"push,omitempty"`
210+
Triage *bool `json:"triage,omitempty"`
211+
Pull *bool `json:"pull,omitempty"`
212+
}
213+
205214
func (s SecurityAndAnalysis) String() string {
206215
return Stringify(s)
207216
}

github/repos_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4615,7 +4615,7 @@ func TestRepository_UnmarshalJSON(t *testing.T) {
46154615
},
46164616
"Partial project": {
46174617
data: []byte(`{"id":10270722,"name":"go-github","private":false,"owner":{"login":"google"},"created_at":"2013-05-24T16:42:58Z","license":{},"topics":["github"],"permissions":{"pull":true},"custom_properties":{},"organization":{"login":"google"}}`),
4618-
wantRepository: Repository{ID: Ptr(int64(10270722)), Name: Ptr("go-github"), Private: Ptr(false), Owner: &User{Login: Ptr("google")}, CreatedAt: &Timestamp{time.Date(2013, 5, 24, 16, 42, 58, 0, time.UTC)}, License: &License{}, Topics: []string{"github"}, Permissions: map[string]bool{"pull": true}, CustomProperties: map[string]any{}, Organization: &Organization{Login: Ptr("google")}},
4618+
wantRepository: Repository{ID: Ptr(int64(10270722)), Name: Ptr("go-github"), Private: Ptr(false), Owner: &User{Login: Ptr("google")}, CreatedAt: &Timestamp{time.Date(2013, 5, 24, 16, 42, 58, 0, time.UTC)}, License: &License{}, Topics: []string{"github"}, Permissions: &RepositoryPermissions{Pull: Ptr(true)}, CustomProperties: map[string]any{}, Organization: &Organization{Login: Ptr("google")}},
46194619
wantErr: false,
46204620
},
46214621
"With custom properties": {

0 commit comments

Comments
 (0)