Skip to content

Commit

Permalink
feat: enable and disable automated security features
Browse files Browse the repository at this point in the history
  • Loading branch information
jprosevear committed Jul 7, 2024
1 parent c1a9cb7 commit 75fc060
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/octokit/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,46 @@ def enable_vulnerability_alerts(repo, options = {})
def disable_vulnerability_alerts(repo, options = {})
boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", options)
end

# Check to see if automated security fixes are enabled for a repository
#
# The authenticated user must have admin access to the repository.
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Boolean] True if automated security fixes are enabled, false otherwise.
# @see https://docs.github.com/en/rest/reference/repos#check-if-automated-security-fixes-are-enabled-for-a-repository
#
# @example
# @client.automated_security_fixes_enabled?("octokit/octokit.rb")
def automated_security_fixes_enabled?(repo, options = {})
boolean_from_response(:get, "#{Repository.path repo}/automated-security-fixes", options)
end

# Enable automated security fixes for a repository
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param options [Hash]
#
# @return [Boolean] True if vulnerability alerts enabled, false otherwise.
# @see https://docs.github.com/en/rest/reference/repos#automated-security-fixes
# @example Enable automated security fixes for a repository
# @client.enable_automated_security_fixes("octokit/octokit.rb")
def enable_automated_security_fixes(repo, options = {})
boolean_from_response(:put, "#{Repository.path repo}/automated-security-fixes", options)
end

# Disable automated security fixes for a repository
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param options [Hash]
#
# @return [Boolean] True if vulnerability alerts disabled, false otherwise.
# @see https://docs.github.com/en/rest/reference/repos#automated-security-fixes
# @example Disable automated security fixes for a repository
# @client.disable_automated_security_fixes("octokit/octokit.rb")
def disable_automated_security_fixes(repo, options = {})
boolean_from_response(:delete, "#{Repository.path repo}/automated-security-fixes", options)
end
end
end
end
34 changes: 34 additions & 0 deletions spec/octokit/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,38 @@
expect(result).to be true
end
end # .disable_vulnerability_alerts

describe '.automated_security_fixes_enabled?', :vcr do
it 'returns true when automated security fixes are enabled' do
@client.enable_automated_security_fixes(@test_repo)

result = @client.automated_security_fixes_enabled?(@test_repo)
assert_requested :get, github_url("/repos/#{@test_repo}/automated-security-fixes")
expect(result).to be true
end

it 'returns false with automated security fixes disabled' do
@client.disable_automated_security_fixes(@test_repo)

result = @client.automated_security_fixes_enabled?(@test_repo)
assert_requested :get, github_url("/repos/#{@test_repo}/automated-security-fixes")
expect(result).to be false
end
end # .automated_security_fixes_enabled?

describe '.enable_automated_security_fixes', :vcr do
it 'enables automated security fixes for the repository' do
result = @client.enable_automated_security_fixes(@test_repo)
assert_requested :put, github_url("/repos/#{@test_repo}/automated-security-fixes")
expect(result).to be true
end
end # .enable_automated_security_fixes

describe '.disable_automated_security_fixes', :vcr do
it 'disablesautomated security fixes for the repository' do
result = @client.disable_automated_security_fixes(@test_repo)
assert_requested :delete, github_url("/repos/#{@test_repo}automated-security-fixes")
expect(result).to be true
end
end # .disable_automated_security_fixes
end

0 comments on commit 75fc060

Please sign in to comment.