-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for organization Immutable Releases API #3774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Not-Dhananjay-Mishra
wants to merge
6
commits into
google:master
Choose a base branch
from
Not-Dhananjay-Mishra:add-immutable-releases
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+504
−0
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4324bd5
feat: Add organization immutable releases settings API
Not-Dhananjay-Mishra 723c401
fix lint issue
Not-Dhananjay-Mishra 98aab3d
Refactor methods and update description
Not-Dhananjay-Mishra 13c0e17
fix lint issue
Not-Dhananjay-Mishra 9e52284
Wrap selected_repository_ids in JSON object
Not-Dhananjay-Mishra 2119402
fix test
Not-Dhananjay-Mishra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// Copyright 2025 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" | ||
) | ||
|
||
// ImmutableReleaseSettings represents the response from the immutable releases settings endpoint. | ||
type ImmutableReleaseSettings struct { | ||
// EnforcedRepositories specifies how immutable releases are enforced in the organization. Possible values include "all", "none", or "selected". | ||
EnforcedRepositories *string `json:"enforced_repositories,omitempty"` | ||
// SelectedRepositoriesURL provides the API URL for managing the repositories | ||
// selected for immutable releases enforcement when EnforcedRepositories is set to "selected". | ||
SelectedRepositoriesURL *string `json:"selected_repositories_url,omitempty"` | ||
} | ||
|
||
// ImmutableReleaseRepository for seting the immutable releases policy for repositories in an organization. | ||
type ImmutableReleaseRepository struct { | ||
// EnforcedRepositories specifies how immutable releases are enforced in the organization. Possible values include "all", "none", or "selected". | ||
EnforcedRepositories *string `json:"enforced_repositories,omitempty"` | ||
// An array of repository ids for which immutable releases enforcement should be applied. | ||
// You can only provide a list of repository ids when the enforced_repositories is set to "selected" | ||
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"` | ||
} | ||
|
||
// setImmutableReleasesRepositoriesOptions represents the request body for setting repositories. | ||
type setImmutableReleasesRepositoriesOptions struct { | ||
SelectedRepositoryIDs []int64 `json:"selected_repository_ids"` | ||
} | ||
|
||
// GetImmutableReleasesSettings gets immutable releases settings for an organization. | ||
// | ||
// This endpoint returns the immutable releases configuration that applies to repositories within the given organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/orgs#get-immutable-releases-settings-for-an-organization | ||
// | ||
//meta:operation GET /orgs/{org}/settings/immutable-releases | ||
func (s *OrganizationsService) GetImmutableReleasesSettings(ctx context.Context, org string) (*ImmutableReleaseSettings, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/settings/immutable-releases", org) | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var settings *ImmutableReleaseSettings | ||
resp, err := s.client.Do(ctx, req, &settings) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return settings, resp, nil | ||
} | ||
|
||
// SetImmutableReleasesPolicy sets immutable releases settings for an organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/orgs#set-immutable-releases-settings-for-an-organization | ||
// | ||
//meta:operation PUT /orgs/{org}/settings/immutable-releases | ||
func (s *OrganizationsService) SetImmutableReleasesPolicy(ctx context.Context, org string, opts ImmutableReleaseRepository) (*Response, error) { | ||
Not-Dhananjay-Mishra marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
u := fmt.Sprintf("orgs/%v/settings/immutable-releases", org) | ||
|
||
req, err := s.client.NewRequest("PUT", u, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := s.client.Do(ctx, req, nil) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// ListImmutableReleaseRepositories lists selected repositories for immutable releases enforcement. | ||
// | ||
// This endpoint gives a list of all the repositories that have been selected for immutable releases enforcement in an organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/orgs#list-selected-repositories-for-immutable-releases-enforcement | ||
// | ||
//meta:operation GET /orgs/{org}/settings/immutable-releases/repositories | ||
func (s *OrganizationsService) ListImmutableReleaseRepositories(ctx context.Context, org string, opts *ListOptions) (*ListRepositories, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/settings/immutable-releases/repositories", org) | ||
|
||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var repositories *ListRepositories | ||
resp, err := s.client.Do(ctx, req, &repositories) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return repositories, resp, nil | ||
} | ||
|
||
// SetImmutableReleaseRepositories sets selected repositories for immutable releases enforcement. | ||
// | ||
// Replaces all repositories selected for immutable releases enforcement in an organization. Requires the organization's immutable releases policy for enforced_repositories to be set to "selected". | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/orgs#set-selected-repositories-for-immutable-releases-enforcement | ||
// | ||
//meta:operation PUT /orgs/{org}/settings/immutable-releases/repositories | ||
func (s *OrganizationsService) SetImmutableReleaseRepositories(ctx context.Context, org string, repositoryIDs []int64) (*Response, error) { | ||
u := fmt.Sprintf("orgs/%v/settings/immutable-releases/repositories", org) | ||
|
||
body := &setImmutableReleasesRepositoriesOptions{ | ||
SelectedRepositoryIDs: repositoryIDs, | ||
} | ||
|
||
req, err := s.client.NewRequest("PUT", u, body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := s.client.Do(ctx, req, nil) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// EnableRepositoryForImmutableRelease enables a selected repository for immutable releases in an organization. | ||
// | ||
// Adds a repository to the organization's selected list for immutable releases enforcement (requires enforced_repositories set to "selected"). | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/orgs#enable-a-selected-repository-for-immutable-releases-in-an-organization | ||
// | ||
//meta:operation PUT /orgs/{org}/settings/immutable-releases/repositories/{repository_id} | ||
func (s *OrganizationsService) EnableRepositoryForImmutableRelease(ctx context.Context, org string, repoID int64) (*Response, error) { | ||
u := fmt.Sprintf("orgs/%v/settings/immutable-releases/repositories/%v", org, repoID) | ||
|
||
req, err := s.client.NewRequest("PUT", u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := s.client.Do(ctx, req, nil) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// DisableRepositoryForImmutableRelease disables a selected repository for immutable releases in an organization. | ||
// | ||
// Removes a repository from the organization's selected list for immutable releases enforcement (requires enforced_repositories set to "selected"). | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/orgs#disable-a-selected-repository-for-immutable-releases-in-an-organization | ||
// | ||
//meta:operation DELETE /orgs/{org}/settings/immutable-releases/repositories/{repository_id} | ||
func (s *OrganizationsService) DisableRepositoryForImmutableRelease(ctx context.Context, org string, repoID int64) (*Response, error) { | ||
u := fmt.Sprintf("orgs/%v/settings/immutable-releases/repositories/%v", org, repoID) | ||
|
||
req, err := s.client.NewRequest("DELETE", u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := s.client.Do(ctx, req, nil) | ||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
return resp, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.