gha-repo-manager
gha-repo-manager copied to clipboard
FEATURE: Settings - Integrations - Autolink references
Is your feature request related to a problem? Please describe. An additional setting which isn't currently supported in syncing that would be very useful to add
Describe the solution you'd like The ability to set alphanumeric/numeric, reference prefix, and target url
https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls
Describe alternatives you've considered There are no good alternatives
As far as I know, the current ability to do this has to be through the API, however, there might be a better option.
Here's a sample:
API_URL = "https://api.github.com"
def getAutolinks(repo, headers):
"""Fetch all autolinks for a repository."""
url = f"{API_URL}/repos/{repo}/autolinks"
response = requests.get(url, headers = headers)
response.raise_for_status()
return response.json()
def addAutolink(repo, key_prefix, url_template, headers, dry_run):
"""Add an autolink to a repository."""
url = f"{API_URL}/repos/{repo}/autolinks"
payload = {"key_prefix": key_prefix, "url_template": url_template}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 201:
print(f"Successfully added autolink to {repo}: Prefix={key_prefix}")
elif response.status_code == 422:
print(f"Autolink already exists in {repo}: Prefix={key_prefix}")
else:
print(f"Failed to add autolink to {repo}: Prefix={key_prefix}")
print(f"Error: {response.status_code} - {response.text}")
As long as pygithub supports this api, then I am fine with a PR to add this feature. If not, it would need to get support in pygithub first.
It looks like it is supported, https://github.com/search?q=repo%3APyGithub%2FPyGithub%20autolinks&type=code