Skip to content

Commit 97b4e46

Browse files
DEVPS-49 fix the api endpoint for repo secret pass vars
1 parent 256be05 commit 97b4e46

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

.github/workflows/create_or_update_repository_secrets.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
env:
5353
organization: ${{ inputs.organization }}
5454
secret_name: ${{ inputs.secret_name }}
55+
REPOSITORY_NAME: ${{ inputs.repository_name }}
5556
ENCRYPTED_SECRET: ${{ env.ENCRYPTED_SECRET }}
5657
REPOSITORY_PUBLIC_KEY_ID: ${{ env.REPOSITORY_PUBLIC_KEY_ID }}
5758
GH_TOKEN: ${{ secrets.DEVWITHKRISHNA_PERSONAL_ACCESS_TOKEN }}

create_or_update_repo_secret.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def create_or_update_organization_secret_github(organization: str, secret_name:
2222
The token must have the following permission set: organization_secrets:write
2323
"""
2424
encrypted_secret = os.getenv('ENCRYPTED_SECRET')
25+
repo_name = os.getenv('REPOSITORY_NAME')
2526
if not encrypted_secret:
2627
print("ENCRYPTED_SECRET environment variable is not set or is empty.")
2728
print(f'encrypted sec is: {encrypted_secret}')
2829
ist_now_formatted = current_ist_time()
29-
github_org_secret_endpoint = f"https://api.github.com/orgs/{organization}/actions/secrets/{secret_name}"
30+
github_repo_secret_endpoint = f"https://api.github.com/repos/{organization}/{repo_name}/actions/secrets/{secret_name}"
3031

3132
headers = {
3233
"Accept": "application/vnd.github+json",
@@ -36,13 +37,13 @@ def create_or_update_organization_secret_github(organization: str, secret_name:
3637
data = {
3738
"encrypted_value": encrypted_secret,
3839
"visibility": "all",
39-
"key_id": os.getenv('PUBLIC_KEY_ID')
40+
"key_id": os.getenv('REPOSITORY_PUBLIC_KEY_ID')
4041
}
41-
response = requests.put(github_org_secret_endpoint, headers=headers, json=data)
42-
if response.status_code == '201':
43-
print(f"Secret {secret_name} created {organization} at {ist_now_formatted} ")
42+
response = requests.put(github_repo_secret_endpoint, headers=headers, json=data)
43+
if response.status_code == 201:
44+
print(f"Secret {secret_name} created {repo_name} at {ist_now_formatted} ")
4445
else:
45-
print(f"Secret {secret_name} updated on {organization} at {ist_now_formatted} ")
46+
print(f"Secret {secret_name} updated on {repo_name} at {ist_now_formatted} ")
4647

4748

4849
def main():

0 commit comments

Comments
 (0)