4242
4343from __future__ import annotations
4444
45+ import urllib .parse
4546from datetime import datetime
4647from typing import TYPE_CHECKING , Any
4748
@@ -172,14 +173,13 @@ def create_secret(self, secret_name: str, unencrypted_value: str) -> Secret:
172173 "key_id" : public_key .key_id ,
173174 "encrypted_value" : payload ,
174175 }
175- self ._requester .requestJsonAndCheck ("PUT" , f"{ self .url } /secrets/{ secret_name } " , input = put_parameters )
176+ quoted_secret_name = urllib .parse .quote (secret_name , safe = "" )
177+ url = f"{ self .url } /secrets/{ quoted_secret_name } "
178+ self ._requester .requestJsonAndCheck ("PUT" , url , input = put_parameters )
176179 return github .Secret .Secret (
177- requester = self ._requester ,
178- headers = {},
179- attributes = {
180- "name" : secret_name ,
181- "url" : f"{ self .url } /secrets/{ secret_name } " ,
182- },
180+ self ._requester ,
181+ url = url ,
182+ attributes = {"name" : secret_name },
183183 completed = False ,
184184 )
185185
@@ -204,12 +204,8 @@ def get_secret(self, secret_name: str) -> Secret:
204204 :calls: `GET /repos/{owner}/{repo}/environments/{environment_name}/secrets/{secret_name} <https://docs.github.com/en/rest/secrets#get-an-organization-secret>`_
205205 """
206206 assert isinstance (secret_name , str ), secret_name
207- return github .Secret .Secret (
208- requester = self ._requester ,
209- headers = {},
210- attributes = {"url" : f"{ self .url } /secrets/{ secret_name } " },
211- completed = False ,
212- )
207+ secret_name = urllib .parse .quote (secret_name , safe = "" )
208+ return github .Secret .Secret (self ._requester , url = f"{ self .url } /secrets/{ secret_name } " )
213209
214210 def create_variable (self , variable_name : str , value : str ) -> Variable :
215211 """
@@ -222,13 +218,15 @@ def create_variable(self, variable_name: str, value: str) -> Variable:
222218 "value" : value ,
223219 }
224220 self ._requester .requestJsonAndCheck ("POST" , f"{ self .url } /variables" , input = post_parameters )
221+
222+ quoted_variable_name = urllib .parse .quote (variable_name , safe = "" )
223+ url = f"{ self .url } /variables/{ quoted_variable_name } "
225224 return github .Variable .Variable (
226225 self ._requester ,
227- headers = {} ,
226+ url = url ,
228227 attributes = {
229228 "name" : variable_name ,
230229 "value" : value ,
231- "url" : f"{ self .url } /variables/{ variable_name } " ,
232230 },
233231 completed = False ,
234232 )
@@ -253,12 +251,9 @@ def get_variable(self, variable_name: str) -> Variable:
253251 :rtype: Variable
254252 """
255253 assert isinstance (variable_name , str ), variable_name
256- return github .Variable .Variable (
257- requester = self ._requester ,
258- headers = {},
259- attributes = {"url" : f"{ self .url } /variables/{ variable_name } " },
260- completed = False ,
261- )
254+ variable_name = urllib .parse .quote (variable_name , safe = "" )
255+ url = f"{ self .url } /variables/{ variable_name } "
256+ return github .Variable .Variable (self ._requester , url = url )
262257
263258 def delete_secret (self , secret_name : str ) -> bool :
264259 """
@@ -296,6 +291,10 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
296291 self ._id = self ._makeIntAttribute (attributes ["id" ])
297292 if "name" in attributes : # pragma no branch
298293 self ._name = self ._makeStringAttribute (attributes ["name" ])
294+ elif "url" in attributes and attributes ["url" ]:
295+ quoted_name = attributes ["url" ].split ("/" )[- 1 ]
296+ name = urllib .parse .unquote (quoted_name )
297+ self ._name = self ._makeStringAttribute (name )
299298 if "node_id" in attributes : # pragma no branch
300299 self ._node_id = self ._makeStringAttribute (attributes ["node_id" ])
301300 if "protection_rules" in attributes : # pragma no branch
0 commit comments