Skip to content

Commit 301bb57

Browse files
authored
feat: enable and disable automated security features
feat: enable and disable automated security features
2 parents 7ff23fa + 843ea20 commit 301bb57

File tree

6 files changed

+757
-0
lines changed

6 files changed

+757
-0
lines changed

lib/octokit/client/repositories.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,49 @@ def enable_vulnerability_alerts(repo, options = {})
774774
def disable_vulnerability_alerts(repo, options = {})
775775
boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", options)
776776
end
777+
778+
# Check to see if automated security fixes are enabled for a repository
779+
#
780+
# The authenticated user must have admin access to the repository.
781+
#
782+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
783+
# @return [Boolean] True if automated security fixes are enabled, false otherwise.
784+
# @see https://docs.github.com/en/rest/reference/repos#check-if-automated-security-fixes-are-enabled-for-a-repository
785+
#
786+
# @example
787+
# @client.automated_security_fixes_enabled?("octokit/octokit.rb")
788+
def automated_security_fixes_enabled?(repo, options = {})
789+
response = get "#{Repository.path repo}/automated-security-fixes", options
790+
return response[:enabled] if @last_response.status == 200
791+
792+
false
793+
end
794+
795+
# Enable automated security fixes for a repository
796+
#
797+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
798+
# @param options [Hash]
799+
#
800+
# @return [Boolean] True if vulnerability alerts enabled, false otherwise.
801+
# @see https://docs.github.com/en/rest/reference/repos#automated-security-fixes
802+
# @example Enable automated security fixes for a repository
803+
# @client.enable_automated_security_fixes("octokit/octokit.rb")
804+
def enable_automated_security_fixes(repo, options = {})
805+
boolean_from_response(:put, "#{Repository.path repo}/automated-security-fixes", options)
806+
end
807+
808+
# Disable automated security fixes for a repository
809+
#
810+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
811+
# @param options [Hash]
812+
#
813+
# @return [Boolean] True if vulnerability alerts disabled, false otherwise.
814+
# @see https://docs.github.com/en/rest/reference/repos#automated-security-fixes
815+
# @example Disable automated security fixes for a repository
816+
# @client.disable_automated_security_fixes("octokit/octokit.rb")
817+
def disable_automated_security_fixes(repo, options = {})
818+
boolean_from_response(:delete, "#{Repository.path repo}/automated-security-fixes", options)
819+
end
777820
end
778821
end
779822
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"request": {
5+
"method": "delete",
6+
"uri": "https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/automated-security-fixes",
7+
"body": {
8+
"encoding": "UTF-8",
9+
"base64_string": "e30=\n"
10+
},
11+
"headers": {
12+
"Accept": [
13+
"application/vnd.github.v3+json"
14+
],
15+
"User-Agent": [
16+
"Octokit Ruby Gem 9.1.0"
17+
],
18+
"Content-Type": [
19+
"application/json"
20+
],
21+
"Authorization": [
22+
"token <<ACCESS_TOKEN>>"
23+
],
24+
"Accept-Encoding": [
25+
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
26+
]
27+
}
28+
},
29+
"response": {
30+
"status": {
31+
"code": 204,
32+
"message": "No Content"
33+
},
34+
"headers": {
35+
"Date": [
36+
"Thu, 18 Jul 2024 13:41:54 GMT"
37+
],
38+
"X-Oauth-Scopes": [
39+
"admin:public_key, codespace, gist, read:org, repo"
40+
],
41+
"X-Accepted-Oauth-Scopes": [
42+
"repo"
43+
],
44+
"X-Oauth-Client-Id": [
45+
"178c6fc778ccc68e1d6a"
46+
],
47+
"X-Github-Media-Type": [
48+
"github.v3; format=json"
49+
],
50+
"X-Github-Api-Version-Selected": [
51+
"2022-11-28"
52+
],
53+
"X-Ratelimit-Limit": [
54+
"5000"
55+
],
56+
"X-Ratelimit-Remaining": [
57+
"4894"
58+
],
59+
"X-Ratelimit-Reset": [
60+
"1721311964"
61+
],
62+
"X-Ratelimit-Used": [
63+
"106"
64+
],
65+
"X-Ratelimit-Resource": [
66+
"core"
67+
],
68+
"Access-Control-Expose-Headers": [
69+
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset"
70+
],
71+
"Access-Control-Allow-Origin": [
72+
"*"
73+
],
74+
"Strict-Transport-Security": [
75+
"max-age=31536000; includeSubdomains; preload"
76+
],
77+
"X-Frame-Options": [
78+
"deny"
79+
],
80+
"X-Content-Type-Options": [
81+
"nosniff"
82+
],
83+
"X-Xss-Protection": [
84+
"0"
85+
],
86+
"Referrer-Policy": [
87+
"origin-when-cross-origin, strict-origin-when-cross-origin"
88+
],
89+
"Content-Security-Policy": [
90+
"default-src 'none'"
91+
],
92+
"Vary": [
93+
"Accept-Encoding, Accept, X-Requested-With"
94+
],
95+
"X-Github-Request-Id": [
96+
"DA10:39DB3F:20F911E:3DE6752:66991BA1"
97+
],
98+
"Server": [
99+
"github.com"
100+
]
101+
},
102+
"body": {
103+
"encoding": "UTF-8",
104+
"base64_string": ""
105+
}
106+
},
107+
"recorded_at": "Thu, 18 Jul 2024 13:41:54 GMT"
108+
},
109+
{
110+
"request": {
111+
"method": "get",
112+
"uri": "https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/automated-security-fixes",
113+
"body": {
114+
"encoding": "US-ASCII",
115+
"base64_string": ""
116+
},
117+
"headers": {
118+
"Accept": [
119+
"application/vnd.github.v3+json"
120+
],
121+
"User-Agent": [
122+
"Octokit Ruby Gem 9.1.0"
123+
],
124+
"Content-Type": [
125+
"application/json"
126+
],
127+
"Authorization": [
128+
"token <<ACCESS_TOKEN>>"
129+
],
130+
"Accept-Encoding": [
131+
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
132+
]
133+
}
134+
},
135+
"response": {
136+
"status": {
137+
"code": 200,
138+
"message": "OK"
139+
},
140+
"headers": {
141+
"Date": [
142+
"Thu, 18 Jul 2024 13:41:54 GMT"
143+
],
144+
"Content-Type": [
145+
"application/json; charset=utf-8"
146+
],
147+
"Cache-Control": [
148+
"private, max-age=60, s-maxage=60"
149+
],
150+
"Vary": [
151+
"Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With"
152+
],
153+
"Etag": [
154+
"W/\"7a86f4321c1d0f17a11c8d0a1c1105f6bda69697bfd035b8d50a6cda1e17c5a6\""
155+
],
156+
"X-Oauth-Scopes": [
157+
"admin:public_key, codespace, gist, read:org, repo"
158+
],
159+
"X-Accepted-Oauth-Scopes": [
160+
"repo"
161+
],
162+
"X-Oauth-Client-Id": [
163+
"178c6fc778ccc68e1d6a"
164+
],
165+
"X-Github-Media-Type": [
166+
"github.v3; format=json"
167+
],
168+
"X-Github-Api-Version-Selected": [
169+
"2022-11-28"
170+
],
171+
"X-Ratelimit-Limit": [
172+
"5000"
173+
],
174+
"X-Ratelimit-Remaining": [
175+
"4891"
176+
],
177+
"X-Ratelimit-Reset": [
178+
"1721311964"
179+
],
180+
"X-Ratelimit-Used": [
181+
"109"
182+
],
183+
"X-Ratelimit-Resource": [
184+
"core"
185+
],
186+
"Access-Control-Expose-Headers": [
187+
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset"
188+
],
189+
"Access-Control-Allow-Origin": [
190+
"*"
191+
],
192+
"Strict-Transport-Security": [
193+
"max-age=31536000; includeSubdomains; preload"
194+
],
195+
"X-Frame-Options": [
196+
"deny"
197+
],
198+
"X-Content-Type-Options": [
199+
"nosniff"
200+
],
201+
"X-Xss-Protection": [
202+
"0"
203+
],
204+
"Referrer-Policy": [
205+
"origin-when-cross-origin, strict-origin-when-cross-origin"
206+
],
207+
"Content-Security-Policy": [
208+
"default-src 'none'"
209+
],
210+
"Transfer-Encoding": [
211+
"chunked"
212+
],
213+
"X-Github-Request-Id": [
214+
"DA13:209DFA:411CDC6:78D2A89:66991BA2"
215+
],
216+
"Server": [
217+
"github.com"
218+
]
219+
},
220+
"body": {
221+
"encoding": "ASCII-8BIT",
222+
"base64_string": "eyJlbmFibGVkIjpmYWxzZSwicGF1c2VkIjpmYWxzZX0=\n"
223+
}
224+
},
225+
"recorded_at": "Thu, 18 Jul 2024 13:41:54 GMT"
226+
}
227+
],
228+
"recorded_with": "VCR 6.2.0"
229+
}

0 commit comments

Comments
 (0)