|
| 1 | +import sys |
| 2 | +sys.path.append('../') |
| 3 | +from lib.dialoget import dialoget |
| 4 | + |
| 5 | +@dialoget('Update a {repo_name} on {org_name}, Set a {description}, Set a {domain}', '../../') |
| 6 | +# Connect to the github API @GITHUB_API_URL with @api_token' |
| 7 | +# Update a @repo_name on @org_name |
| 8 | +# with a @description |
| 9 | +# on the @domain |
| 10 | +def update_repo_on_github2(api_token, org_name, repo_name, description, domain, GITHUB_API_URL='https://api.github.com'): |
| 11 | + """ |
| 12 | + Update the description of a specific GitHub repository. |
| 13 | +
|
| 14 | + This function uses the GitHub API to update the repository's description field. |
| 15 | + It requires an API token with appropriate permissions to modify repository settings. |
| 16 | +
|
| 17 | + Parameters: |
| 18 | + - api_token (str): The personal access token for GitHub API authentication. |
| 19 | + - org_name (str): The name of the organization under which the repository exists. |
| 20 | + Use the username for repositories owned by an individual user. |
| 21 | + - repo_name (str): The name of the repository to be updated. |
| 22 | + - description (str): The new description text for the repository. |
| 23 | + - domain (str): The custom domain to use for API requests. This is useful if you |
| 24 | + are using GitHub Enterprise with a different domain than github.com. |
| 25 | + - GITHUB_API_URL (str, optional): The base URL for the GitHub API. Defaults to |
| 26 | + 'https://api.github.com', which is the public API URL. |
| 27 | +
|
| 28 | + Returns: |
| 29 | + None - This function does not return a value but raises an exception if the update fails. |
| 30 | +
|
| 31 | + Raises: |
| 32 | + - HTTPError: An error from the requests module 'requests.exceptions.HTTPError' if the |
| 33 | + HTTP request returned an unsuccessful status code. |
| 34 | + - Exception: A general exception if the update was unsuccessful, with an error message |
| 35 | + indicating the failure reason. |
| 36 | +
|
| 37 | + Usage: |
| 38 | + ```python |
| 39 | + update_repo_on_github2('<your_api_token>', 'my-org', 'my-repo', 'New description', 'https://github.my-domain.com') |
| 40 | + ``` |
| 41 | + """ |
| 42 | + |
| 43 | + # Code to perform the API request to update the repository description would go here. |
| 44 | + # The 'requests' library would typically be used to make the HTTP request. |
| 45 | + # Example: |
| 46 | + # headers = {'Authorization': f'token {api_token}'} |
| 47 | + # data = {'description': description} |
| 48 | + # response = requests.patch(f'{GITHUB_API_URL}/repos/{org_name}/{repo_name}', |
| 49 | + # json=data, headers=headers) |
| 50 | + # response.raise_for_status() # Raise an HTTPError if the request returned an |
| 51 | + # # unsuccessful status code. |
| 52 | + |
| 53 | + # Endpoint to create a repo within an organization |
| 54 | + url = f'{GITHUB_API_URL}/repos/{org_name}/{repo_name}/pages' |
| 55 | + |
| 56 | + try: |
| 57 | + url = f'{GITHUB_API_URL}/repos/{org_name}/{repo_name}/pages' |
| 58 | + # print(url) |
| 59 | + except: |
| 60 | + print("Something went wrong") |
| 61 | + exit(1) |
| 62 | + # print(api_token, org_name, repo_name, description, domain) |
| 63 | + return 200 |
| 64 | + |
| 65 | +# result = update_repo_on_github(api_token, org_name, repo_name, description, domain) |
| 66 | +# (result.status == 200) |
| 67 | + |
| 68 | + |
| 69 | +# f'Connect to {Github,github_url,GITHUB_API_URL} by {"API token",api_token,GITHUB_API_TOKEN}' |
0 commit comments