.examples
.github
alerting
client
config
controller
core
docs
jsonpath
metrics
pattern
security
storage
test
util
vendor
github.com
TwiN
beorn7
cespare
coreos
davecgh
go-ping
golang
google
go-github
v48
github
actions.go
actions_artifacts.go
actions_runner_groups.go
actions_runners.go
actions_secrets.go
actions_workflow_jobs.go
actions_workflow_runs.go
actions_workflows.go
activity.go
activity_events.go
activity_notifications.go
activity_star.go
activity_watching.go
admin.go
admin_orgs.go
admin_stats.go
admin_users.go
apps.go
apps_hooks.go
apps_hooks_deliveries.go
apps_installation.go
apps_manifest.go
apps_marketplace.go
authorizations.go
billing.go
checks.go
code-scanning.go
dependabot.go
dependabot_alerts.go
dependabot_secrets.go
doc.go
enterprise.go
enterprise_actions_runners.go
enterprise_audit_log.go
event.go
event_types.go
gists.go
gists_comments.go
git.go
git_blobs.go
git_commits.go
git_refs.go
git_tags.go
git_trees.go
github-accessors.go
github.go
gitignore.go
interactions.go
interactions_orgs.go
interactions_repos.go
issue_import.go
issues.go
issues_assignees.go
issues_comments.go
issues_events.go
issues_labels.go
issues_milestones.go
issues_timeline.go
licenses.go
messages.go
migrations.go
migrations_source_import.go
migrations_user.go
misc.go
orgs.go
orgs_actions_allowed.go
orgs_actions_permissions.go
orgs_audit_log.go
orgs_custom_roles.go
orgs_hooks.go
orgs_hooks_deliveries.go
orgs_members.go
orgs_outside_collaborators.go
orgs_packages.go
orgs_projects.go
orgs_security_managers.go
orgs_users_blocking.go
packages.go
projects.go
pulls.go
pulls_comments.go
pulls_reviewers.go
pulls_reviews.go
pulls_threads.go
reactions.go
repos.go
repos_actions_access.go
repos_actions_allowed.go
repos_actions_permissions.go
repos_autolinks.go
repos_codeowners.go
repos_collaborators.go
repos_comments.go
repos_commits.go
repos_community_health.go
repos_contents.go
repos_deployments.go
repos_environments.go
repos_forks.go
repos_hooks.go
repos_hooks_deliveries.go
repos_invitations.go
repos_keys.go
repos_lfs.go
repos_merging.go
repos_pages.go
repos_prereceive_hooks.go
repos_projects.go
repos_releases.go
repos_stats.go
repos_statuses.go
repos_tags.go
repos_traffic.go
scim.go
search.go
secret_scanning.go
strings.go
teams.go
teams_discussion_comments.go
teams_discussions.go
teams_members.go
timestamp.go
users.go
users_administration.go
users_blocking.go
users_emails.go
users_followers.go
users_gpg_keys.go
users_keys.go
users_packages.go
users_projects.go
users_ssh_signing_keys.go
with_appengine.go
without_appengine.go
AUTHORS
LICENSE
go-querystring
uuid
gorilla
ishidawataru
kballard
lib
mattn
matttproud
miekg
prometheus
remyoudompheng
wcharczuk
golang.org
google.golang.org
gopkg.in
lukechampine.com
modernc.org
modules.txt
watchdog
web
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE
Makefile
README.md
config.yaml
go.mod
go.sum
main.go
81 lines
2.8 KiB
Go
81 lines
2.8 KiB
Go
// Copyright 2018 The go-github AUTHORS. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package github
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// GetRestrictionsForRepo fetches the interaction restrictions for a repository.
|
|
//
|
|
// GitHub API docs: https://docs.github.com/en/rest/interactions/repos#get-interaction-restrictions-for-a-repository
|
|
func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, repo string) (*InteractionRestriction, *Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
// TODO: remove custom Accept header when this API fully launches.
|
|
req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
|
|
|
|
repositoryInteractions := new(InteractionRestriction)
|
|
|
|
resp, err := s.client.Do(ctx, req, repositoryInteractions)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return repositoryInteractions, resp, nil
|
|
}
|
|
|
|
// UpdateRestrictionsForRepo adds or updates the interaction restrictions for a repository.
|
|
//
|
|
// limit specifies the group of GitHub users who can comment, open issues, or create pull requests
|
|
// for the given repository.
|
|
// Possible values are: "existing_users", "contributors_only", "collaborators_only".
|
|
//
|
|
// GitHub API docs: https://docs.github.com/en/rest/interactions/repos#set-interaction-restrictions-for-a-repository
|
|
func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
|
|
|
|
interaction := &InteractionRestriction{Limit: String(limit)}
|
|
|
|
req, err := s.client.NewRequest("PUT", u, interaction)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
// TODO: remove custom Accept header when this API fully launches.
|
|
req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
|
|
|
|
repositoryInteractions := new(InteractionRestriction)
|
|
|
|
resp, err := s.client.Do(ctx, req, repositoryInteractions)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return repositoryInteractions, resp, nil
|
|
}
|
|
|
|
// RemoveRestrictionsFromRepo removes the interaction restrictions for a repository.
|
|
//
|
|
// GitHub API docs: https://docs.github.com/en/rest/interactions/repos#remove-interaction-restrictions-for-a-repository
|
|
func (s *InteractionsService) RemoveRestrictionsFromRepo(ctx context.Context, owner, repo string) (*Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
|
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// TODO: remove custom Accept header when this API fully launches.
|
|
req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
|
|
|
|
return s.client.Do(ctx, req, nil)
|
|
}
|