Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError: 'api_version' for self-hosted SCM #71

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

rkorzeniec
Copy link
Contributor

This is a proposal for a fix in case this plugin is used for GitLab self-hosted or GitHub enterprise repositories.

Currently this in case GitLab self-hosted or GitHub enterprise repo is being used with the newest version of this plugin, it would return the following error:

INFO    -  git-committers plugin ENABLED
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 265, in build
    config = config.plugins.on_config(config)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/plugins.py", line 587, in on_config
    return self.run_event('config', config)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_git_committers_plugin_2/plugin.py", line 67, in on_config
    if not self.config['api_version']:
  File "/usr/local/lib/python3.9/collections/__init__.py", line 1058, in __getitem__
    raise KeyError(key)
KeyError: 'api_version'

This change proposes to change the dict key access to a safer version.

This is a proposal for a fix in case this plugin is used for GitLab self-hosted or GitHub enterprise repositories.

Currently this in case GitLab self-hosted or GitHub enterprise repo is being used with the newest version of this plugin, it would return the following error:
```python
INFO    -  git-committers plugin ENABLED
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 265, in build
    config = config.plugins.on_config(config)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/plugins.py", line 587, in on_config
    return self.run_event('config', config)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_git_committers_plugin_2/plugin.py", line 67, in on_config
    if not self.config['api_version']:
  File "/usr/local/lib/python3.9/collections/__init__.py", line 1058, in __getitem__
    raise KeyError(key)
KeyError: 'api_version'
```

This change proposes to change the dict key access to a safer version.
@rkorzeniec
Copy link
Contributor Author

Normally I would do it the following way

if self.config['gitlab_hostname'] and self.config['gitlab_hostname'] != '':
            api_version = self.config.get('api_version', 'v4')
            self.gitlaburl = "https://" + self.config['gitlab_hostname'] + "/api/" + api_version

however I wanted to be consistent with the similar github conditional

@ojacques
Copy link
Owner

ojacques commented Oct 3, 2024

Thanks! Merging this version, but feel free to continue improving, so that the implementation is better.

@ojacques ojacques merged commit 39a2b29 into ojacques:master Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants