Repository: stuartmccoll/gitlab-changelog-generator

Issue:
Add unit tests for token CLI parameter

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 985774e..dee7395 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # CHANGELOG
 
+## v1.0.3 - 2018/07/05
+
+- Added the ability to use GitLab personal auth token - [pull request](https://github.com/stuartmccoll/gitlab-changelog-generator/pull/20) submitted by [stotler](https://github.com/stuartmccoll/gitlab-changelog-generator/issues?q=is%3Apr+author%3Astotler).
+
 ## v1.0.2 - 2018/07/05
 
 - Updated documentation and configuration to document Python 3.7 compatability.
diff --git a/changelog_generator/calls.py b/changelog_generator/calls.py
index 22c7204..5b3884e 100644
--- a/changelog_generator/calls.py
+++ b/changelog_generator/calls.py
@@ -15,7 +15,14 @@ def get_last_commit_date(cli_args: dict) -> str:
     request_url = f"http://{cli_args['ip_address']}/api/v{cli_args['api_version']}/projects/" f"{cli_args['project_group']}%2F{cli_args['project']}/repository/commits/{cli_args['branch_one']}"
     logger.info(f"Requesting last commit date with URL: {request_url}")
     try:
-        response = requests.get(request_url, headers={"PRIVATE-TOKEN":cli_args['token']})
+        response = requests.get(
+            request_url,
+            headers={
+                "PRIVATE-TOKEN": cli_args["token"]
+                if "token" in cli_args
+                else None
+            },
+        )
         logger.info(response.status_code)
         response.raise_for_status()
     except requests.exceptions.HTTPError as ex:
@@ -54,7 +61,12 @@ def get_closed_issues_for_project(cli_args: dict) -> dict:
         f"Requesting tags for project {cli_args['project']} with URL: {request_url}"
     )
     try:
-        response = requests.get(request_url, headers={"PRIVATE-TOKEN":cli_args['token']})
+        response = requests.get(
+            request_url,
+            headers={"PRIVATE-TOKEN": cli_args["token"]}
+            if "token" in cli_args
+            else None,
+        )
         response.raise_for_status()
     except requests.exceptions.HTTPError as ex:
         logger.error(
@@ -83,7 +95,12 @@ def get_last_tagged_release_date(cli_args: dict) -> str:
         f"Requesting tags for project {cli_args['project']} with URL: {request_url}"
     )
     try:
-        response = requests.get(request_url, headers={"PRIVATE-TOKEN":cli_args['token']})
+        response = requests.get(
+            request_url,
+            headers={"PRIVATE-TOKEN": cli_args["token"]}
+            if "token" in cli_args
+            else None,
+        )
         response.raise_for_status()
     except requests.exceptions.HTTPError as ex:
         logger.error(
@@ -113,7 +130,12 @@ def get_commits_since_date(date: str, cli_args: dict) -> list:
         f"Requesting commits on branch '{cli_args['branch_two']}' in repository '{cli_args['project']}' since date '{date}' with URL: {request_url}"
     )
     try:
-        response = requests.get(request_url, headers={"PRIVATE-TOKEN":cli_args['token']})
+        response = requests.get(
+            request_url,
+            headers={"PRIVATE-TOKEN": cli_args["token"]}
+            if "token" in cli_args
+            else None,
+        )
         response.raise_for_status()
     except requests.exceptions.HTTPError as ex:
         logger.error(
diff --git a/changelog_generator/entry_point.py b/changelog_generator/entry_point.py
index a84a57b..83765f6 100644
--- a/changelog_generator/entry_point.py
+++ b/changelog_generator/entry_point.py
@@ -76,6 +76,7 @@ def process_arguments() -> dict:
         "branch_two": args.branches[1],
         "version": args.version,
         "changelog": args.changelog,
+        "token": args.token,
     }
 
 
diff --git a/setup.py b/setup.py
index af76bc5..7c72372 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
 
 setuptools.setup(
     name="gitlab-changelog-generator",
-    version="1.0.2",
+    version="1.0.3",
     author="Stuart McColl",
     author_email="it@stuartmccoll.co.uk",
     description="A small command line utility for generating CHANGELOG.md "


Test patch:
diff --git a/changelog_generator/tests/test_entry_point.py b/changelog_generator/tests/test_entry_point.py
index cf2de26..c05877c 100644
--- a/changelog_generator/tests/test_entry_point.py
+++ b/changelog_generator/tests/test_entry_point.py
@@ -19,6 +19,8 @@ class TestGenerator(unittest.TestCase):
             "master",
             "--version",
             "1.2.3",
+            "--token",
+            "test-token",
         ]
         expected_result = {
             "ip_address": "localhost",
@@ -29,6 +31,7 @@ class TestGenerator(unittest.TestCase):
             "branch_two": "master",
             "version": "1.2.3",
             "changelog": "N",
+            "token": "test-token",
         }
 
         result = process_arguments()