-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new input parameter: gh_rest_api_base_url It defaults to https://api.github.com. If set, it should include the path `/api/v3` - if not, it will be added. Use $GITHUB_SERVER_URL otherwise throughout. Add logging to push-action - it will be streamed to stderr if `debug` is set (is `true`). Use function to escape regexp special chars. Implement function from stackoverflow answer: https://stackoverflow.com/a/16951928/12404091
- Loading branch information
Showing
8 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Validate inputs.""" | ||
from urllib.parse import urlsplit | ||
|
||
GITHUB_FREE_REST_API_BASE_URL = "https://api.github.com" | ||
"""Base URL for GitHub Free API.""" | ||
|
||
GITHUB_ENTERPRISE_API_PREFIX = "/api/v3" | ||
"""Prefix for GitHub Enterprise API URLs. | ||
See the note for more information here: | ||
https://docs.github.com/en/enterprise-server@3.10/rest/quickstart?apiVersion=2022-11-28&tool=curl#using-curl-commands-in-github-actions. | ||
""" | ||
|
||
|
||
def validate_rest_api_base_url(base_url: str) -> str: | ||
"""Validate and parse the `gh_rest_api_base_url` input.""" | ||
split_base_url = urlsplit(base_url) | ||
|
||
if not split_base_url.scheme or not split_base_url.netloc: | ||
raise ValueError( | ||
"Invalid URL provided for `gh_rest_api_base_url` input (missing scheme " | ||
"and/or netloc)." | ||
) | ||
|
||
compiled_url = split_base_url.scheme + "://" + split_base_url.netloc | ||
|
||
if compiled_url == GITHUB_FREE_REST_API_BASE_URL: | ||
return compiled_url | ||
|
||
url_path = split_base_url.path.rstrip("/") | ||
|
||
if url_path and not split_base_url.path.endswith(GITHUB_ENTERPRISE_API_PREFIX): | ||
raise ValueError( | ||
"Invalid URL provided for `gh_rest_api_base_url` input (path must end with " | ||
f"{GITHUB_ENTERPRISE_API_PREFIX!r})." | ||
) | ||
|
||
if not url_path: | ||
compiled_url += GITHUB_ENTERPRISE_API_PREFIX | ||
|
||
return compiled_url |