Skip to content

Commit 19319b8

Browse files
authored
feat(deploy): add optional commit message argument
Feat/deploy commit message
2 parents 2f9cdff + 9bdb29b commit 19319b8

5 files changed

Lines changed: 77 additions & 6 deletions

File tree

‎docs/commands/deploy.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ Date: Thu Mar 12 15:30:00 2020 +0100
7171
backend.env.[0].value: 'bar'
7272
```
7373

74+
### Specific Commit Message
75+
76+
If you want to specify the commit message of the deployment then you can use the following param:
77+
78+
`--commit-message`
79+
80+
```bash
81+
gitopscli deploy \
82+
--git-provider-url https://bitbucket.baloise.dev \
83+
--username $GIT_USERNAME \
84+
--password $GIT_PASSWORD \
85+
--git-user "GitOps CLI" \
86+
--git-email "gitopscli@baloise.dev" \
87+
--organisation "deployment" \
88+
--repository-name "myapp-non-prod" \
89+
--commit-message "test commit message" \
90+
--file "example/values.yaml" \
91+
--values "{frontend.tag: 1.1.0, backend.tag: 1.1.0, backend.env.[0].value: bar}"
92+
```
93+
94+
This will end up in one single commit with your specified commit-message.
95+
7496
### Create Pull Request
7597

7698
In some cases you might want to create a pull request for your updates. You can achieve this by adding `--create-pr` to the command. The pull request can be left open or merged directly with `--auto-merge`.

‎gitopscli/cliparser.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def __add_deploy_command_parser(subparsers):
4545
const=True,
4646
default=False,
4747
)
48+
deploy_p.add_argument(
49+
"--commit-message", help="Specify exact commit message of deployment commit", type=str, default=None,
50+
)
4851

4952
__add_git_parser_args(deploy_p)
5053
__add_branch_pr_parser_args(deploy_p)

‎gitopscli/commands/deploy.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def deploy_command(
2323
repository_name,
2424
git_provider,
2525
git_provider_url,
26+
commit_message=None,
2627
):
2728
assert command == "deploy"
2829

@@ -49,7 +50,7 @@ def deploy_command(
4950
git.new_branch(config_branch)
5051
logging.info("Created branch %s", config_branch)
5152

52-
updated_values = __update_values(git, file, values, single_commit)
53+
updated_values = __update_values(git, file, values, single_commit, commit_message)
5354
if not updated_values:
5455
logging.info("All values already up-to-date. I'm done here")
5556
return
@@ -63,7 +64,7 @@ def deploy_command(
6364
__create_pr(git, config_branch, file, updated_values, auto_merge)
6465

6566

66-
def __update_values(git, file, values, single_commit):
67+
def __update_values(git, file, values, single_commit, commit_message):
6768
full_file_path = git.get_full_file_path(file)
6869
if not os.path.isfile(full_file_path):
6970
raise GitOpsException(f"No such file: {file}")
@@ -81,10 +82,10 @@ def __update_values(git, file, values, single_commit):
8182
logging.info("Updated yaml property %s to %s", key, value)
8283
updated_values[key] = value
8384

84-
if not single_commit:
85+
if not single_commit and commit_message is None:
8586
git.commit(f"changed '{key}' to '{value}' in {file}")
8687

87-
if updated_values and single_commit:
88+
if updated_values and single_commit and commit_message is None:
8889
if len(updated_values) == 1:
8990
key, value = list(updated_values.items())[0]
9091
git.commit(f"changed '{key}' to '{value}' in {file}")
@@ -93,6 +94,9 @@ def __update_values(git, file, values, single_commit):
9394
msg += f"\n\n{yaml_dump(updated_values)}"
9495
git.commit(msg)
9596

97+
if updated_values and commit_message is not None:
98+
git.commit(commit_message)
99+
96100
return updated_values
97101

98102

‎tests/commands/test_deploy.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,44 @@ def test_single_commit_happy_flow(self):
218218
call.delete_tmp_dir("/tmp/created-tmp-dir"),
219219
]
220220

221+
def test_commit_message_happy_flow(self):
222+
deploy_command(
223+
command="deploy",
224+
file="test/file.yml",
225+
values={"a.b.c": "foo", "a.b.d": "bar"},
226+
username="USERNAME",
227+
password="PASSWORD",
228+
git_user="GIT_USER",
229+
git_email="GIT_EMAIL",
230+
create_pr=False,
231+
auto_merge=False,
232+
single_commit=False,
233+
organisation="ORGA",
234+
repository_name="REPO",
235+
git_provider="github",
236+
git_provider_url=None,
237+
commit_message="testcommit",
238+
)
239+
240+
assert self.mock_manager.mock_calls == [
241+
call.create_tmp_dir(),
242+
call.create_git(
243+
"USERNAME", "PASSWORD", "GIT_USER", "GIT_EMAIL", "ORGA", "REPO", "github", None, "/tmp/created-tmp-dir"
244+
),
245+
call.git_util.checkout("master"),
246+
call.logging.info("Master checkout successful"),
247+
call.git_util.get_full_file_path("test/file.yml"),
248+
call.os.path.isfile("/tmp/created-tmp-dir/test/file.yml"),
249+
call.update_yaml_file("/tmp/created-tmp-dir/test/file.yml", "a.b.c", "foo"),
250+
call.logging.info("Updated yaml property %s to %s", "a.b.c", "foo"),
251+
call.update_yaml_file("/tmp/created-tmp-dir/test/file.yml", "a.b.d", "bar"),
252+
call.logging.info("Updated yaml property %s to %s", "a.b.d", "bar"),
253+
call.git_util.commit("testcommit"),
254+
call.git_util.push("master"),
255+
call.logging.info("Pushed branch %s", "master"),
256+
call.delete_tmp_dir("/tmp/created-tmp-dir"),
257+
]
258+
221259
def test_checkout_error(self):
222260
checkout_exception = GitOpsException("dummy checkout error")
223261
self.git_util_mock.checkout.side_effect = checkout_exception

‎tests/test_cliparser.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@
244244

245245
EXPECTED_DEPLOY_NO_ARGS_ERROR = """\
246246
usage: gitopscli deploy [-h] --file FILE --values VALUES
247-
[--single-commit [SINGLE_COMMIT]] --username USERNAME
247+
[--single-commit [SINGLE_COMMIT]]
248+
[--commit-message COMMIT_MESSAGE] --username USERNAME
248249
--password PASSWORD [--git-user GIT_USER]
249250
[--git-email GIT_EMAIL] --organisation ORGANISATION
250251
--repository-name REPOSITORY_NAME
@@ -257,7 +258,8 @@
257258

258259
EXPECTED_DEPLOY_HELP = """\
259260
usage: gitopscli deploy [-h] --file FILE --values VALUES
260-
[--single-commit [SINGLE_COMMIT]] --username USERNAME
261+
[--single-commit [SINGLE_COMMIT]]
262+
[--commit-message COMMIT_MESSAGE] --username USERNAME
261263
--password PASSWORD [--git-user GIT_USER]
262264
[--git-email GIT_EMAIL] --organisation ORGANISATION
263265
--repository-name REPOSITORY_NAME
@@ -273,6 +275,8 @@
273275
desired value as value
274276
--single-commit [SINGLE_COMMIT]
275277
Create only single commit for all updates
278+
--commit-message COMMIT_MESSAGE
279+
Specify exact commit message of deployment commit
276280
--username USERNAME Git username
277281
--password PASSWORD Git password or token
278282
--git-user GIT_USER Git Username

0 commit comments

Comments
 (0)