|
import os |
|
import re |
|
import sys |
|
import requests |
|
import yaml |
|
|
|
ISSUE_TITLE = 'Consider using true/false for all booleans in docs' |
|
ISSUE_BODY = ''' |
|
Based on the [community decision](https://github.com/ansible-community/community-topics/discussions/120) to use `true/false` for boolean values in documentation and examples, we ask that you evaluate booleans in this collection and consider changing any that do not use `true/false` (lowercase). |
|
|
|
See [documentation block format](https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#documentation-block) for more info (specifically, option defaults). |
|
|
|
If you have already implemented this or decide not to, feel free to close this issue. |
|
|
|
--- |
|
|
|
P.S. This is auto-generated issue, please raise any concerns [here](https://github.com/ansible-community/community-team/issues/60) |
|
''' |
|
|
|
|
|
def print_log(msg: str, *args, **kwargs): |
|
sys.stdout.writelines(msg.format(*args, **kwargs) + "\n") |
|
sys.stdout.flush() |
|
|
|
|
|
def print_debug(msg: str, *args, **kwargs): |
|
sys.stderr.write(msg.format(*args, **kwargs) + "\n") |
|
sys.stdout.flush() |
|
|
|
|
|
def read_yaml_file(path: str): |
|
with open(path, 'r') as file: |
|
return yaml.safe_load(file) |
|
|
|
|
|
def write_yaml_file(path: str, data): |
|
with open(path, 'w') as file: |
|
return file.write(yaml.dump(data)) |
|
|
|
|
|
def parse_github_repo_url(repo_url: str): |
|
gh_url_matches = re.search(r'^https://github\.com/(.*?)/(.*?)$', repo_url) |
|
|
|
if not gh_url_matches: |
|
return None |
|
|
|
gh_repo_owner, gh_repo_name = gh_url_matches.groups() |
|
return dict(owner=gh_repo_owner, name=gh_repo_name) |
|
|
|
|
|
def create_gh_issue(gh_repo: dict, data: dict): |
|
assert os.getenv('GH_TOKEN') |
|
|
|
create_url = 'https://api.github.com/repos/{}/{}/issues'.format(gh_repo['owner'], gh_repo['name']) |
|
create_response = requests.post( |
|
url=create_url, |
|
headers={ |
|
'Accept': 'application/vnd.github+json', |
|
'Authorization': 'Bearer {}'.format(os.getenv('GH_TOKEN')), |
|
'X-GitHub-Api-Version': '2022-11-28', |
|
}, |
|
json=data |
|
) |
|
|
|
create_response.raise_for_status() |
|
|
|
return create_response.json() |
|
|
|
|
|
# From https://github.com/ansible-community/ansible-build-data/blob/main/7/collection-meta.yaml |
|
collections_meta = read_yaml_file('ansible-7-collection-meta.yml') |
|
|
|
# From https://github.com/ansible-community/community-team/issues/60#issuecomment-1252688300 |
|
notified_collections = read_yaml_file('notified-collections.yml') |
|
|
|
# Safety first! |
|
DRY_RUN = True |
|
if '--go-nuclear' in sys.argv: |
|
# Extra safety! |
|
confirm_lanuch = input("Launch issues at collections? [yes/no]: ").lower() == 'yes' |
|
DRY_RUN = not confirm_lanuch |
|
else: |
|
print_debug('--go-nuclear option not specified, issues will not be launched!') |
|
|
|
for fqcn, collection_meta in collections_meta['collections'].items(): |
|
|
|
# Check if issue is already created |
|
notified_meta = notified_collections.get(fqcn, dict()) or dict() |
|
if notified_meta and notified_meta.get('issue_url'): |
|
print_debug('[{}] Issue already created at {}, skipping...', fqcn, notified_meta['issue_url']) |
|
continue |
|
|
|
# Check if repository is hosted at GitHub |
|
repository_url = collections_meta['collections'][fqcn]['repository'] |
|
gh_repo = parse_github_repo_url(repository_url) |
|
if not gh_repo: |
|
print_debug('[{}] Couldn\'t detect github repository from {}, skipping...', fqcn, repository_url) |
|
continue |
|
|
|
if DRY_RUN: |
|
print_log('[{}] Would create an issue at https://github.com/{}/{}/issues', |
|
fqcn, gh_repo['owner'], gh_repo['name']) |
|
continue |
|
|
|
# Create the issue |
|
print_log('[{}] Creating issue at https://github.com/{}/{}/issues', fqcn, gh_repo['owner'], gh_repo['name']) |
|
create_result = create_gh_issue(gh_repo, { |
|
'title': ISSUE_TITLE, |
|
'body': ISSUE_BODY |
|
}) |
|
issue_url = create_result['html_url'] |
|
print_log('[{}] Created issue at {}', fqcn, issue_url) |
|
|
|
# Update notified list |
|
notified_meta['issue_url'] = issue_url |
|
notified_collections[fqcn] = notified_meta |
|
write_yaml_file('notified-collections.yml', notified_collections) |