Repository: repobee/repobee

Issue:
Config wizard fails if the configuration directory does not exist
Derp, if e.g. `~/.config/repobee` doesn't exist, it must be created.

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=h1) Report
> Merging [#300](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=desc) into [master](https://codecov.io/gh/repobee/repobee/commit/48ea2acf09163bff99e2105e865d7c0cc2fcf8c9?src=pr&el=desc) will **decrease** coverage by `0.11%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/repobee/repobee/pull/300/graphs/tree.svg?width=650&token=5vOKgkphZe&height=150&src=pr)](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #300      +/-   ##
=========================================
- Coverage   90.31%   90.2%   -0.12%     
=========================================
  Files          21      21              
  Lines        1539    1541       +2     
  Branches      275     275              
=========================================
  Hits         1390    1390              
- Misses        124     127       +3     
+ Partials       25      24       -1
```


| [Impacted Files](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/\_repobee/ext/configwizard.py](https://codecov.io/gh/repobee/repobee/pull/300/diff?src=pr&el=tree#diff-c3JjL19yZXBvYmVlL2V4dC9jb25maWd3aXphcmQucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [src/\_repobee/cli.py](https://codecov.io/gh/repobee/repobee/pull/300/diff?src=pr&el=tree#diff-c3JjL19yZXBvYmVlL2NsaS5weQ==) | `98.09% <0%> (-0.64%)` | :arrow_down: |
| [src/\_repobee/ext/gitlab.py](https://codecov.io/gh/repobee/repobee/pull/300/diff?src=pr&el=tree#diff-c3JjL19yZXBvYmVlL2V4dC9naXRsYWIucHk=) | `64.63% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=footer). Last update [48ea2ac...6c6488e](https://codecov.io/gh/repobee/repobee/pull/300?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/_repobee/ext/configwizard.py b/src/_repobee/ext/configwizard.py
index a8cc05b..c1a7176 100644
--- a/src/_repobee/ext/configwizard.py
+++ b/src/_repobee/ext/configwizard.py
@@ -9,6 +9,7 @@ a short configuration wizard that lets the user set RepoBee's defaults.
 import argparse
 import configparser
 import sys
+import os
 
 import daiquiri
 import repobee_plug as plug
@@ -38,6 +39,9 @@ def callback(args: argparse.Namespace, api: apimeta.API) -> None:
             return
         parser.read(str(constants.DEFAULT_CONFIG_FILE))
 
+    os.makedirs(
+        str(constants.DEFAULT_CONFIG_FILE.parent), mode=0o700, exist_ok=True
+    )
     if constants.DEFAULTS_SECTION_HDR not in parser:
         parser.add_section(constants.DEFAULTS_SECTION_HDR)
 


Test patch:
diff --git a/tests/unit_tests/plugin_tests/test_configwizard.py b/tests/unit_tests/plugin_tests/test_configwizard.py
index 5bf970b..c748f9a 100644
--- a/tests/unit_tests/plugin_tests/test_configwizard.py
+++ b/tests/unit_tests/plugin_tests/test_configwizard.py
@@ -1,5 +1,6 @@
 import string
 import sys
+import os
 import collections
 import builtins  # noqa: F401
 import configparser
@@ -163,3 +164,16 @@ def test_retains_values_that_are_not_specified(config_mock, defaults_options):
         assert parser[_repobee.constants.DEFAULTS_SECTION_HDR][option] == value
     for option, value in plugin_options.items():
         assert parser[plugin_section][option] == value
+
+
+def test_creates_directory(config_mock, tmpdir, defaults_options):
+    with patch(
+        "builtins.input", side_effect=["yes"] + list(defaults_options.values())
+    ), patch("os.makedirs", autospec=True) as makedirs_mock, patch(
+        "pathlib.Path.exists", autospec=True, return_value=False
+    ):
+        configwizard.callback(None, None)
+
+    makedirs_mock.assert_called_once_with(
+        os.path.dirname(str(config_mock)), mode=0o700, exist_ok=True
+    )