Skip to content

Commit 1db908e

Browse files
authored
Merge branch 'master' into fix_issue-284-temp
2 parents 4a9e775 + a08f8d3 commit 1db908e

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 1.2.4 (2020-06-03)
4+
* Add ability to reference a git repo by branch name and directory via `<repo>.git//<directory>?ref=<branch-name`. ([#218](https://github.com/eerkunt/terraform-compliance/issues/218))
5+
36
## 1.2.3 (2020-05-25)
47
* Fixed a crash where some module outputs could not be processed. ([#275](https://github.com/eerkunt/terraform-compliance/issues/275))
58

docs/pages/usage/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ or if the repository is a private repository ;
7070
The authentication to that git repository will be handled via your `~/.ssh/config`. If you are using a different
7171
ssh key for this repository then you also need to provide `-i` parameter to pointing your private key.
7272
73+
New in `1.2.4`, a repository can be referenced by branch name and directory. This uses syntax similar to Terraform
74+
[Modules in Package Sub-directories](https://www.terraform.io/docs/modules/sources.html#modules-in-package-sub-directories).
75+
The reference must include `//` after `.git` and end with `?ref=<branch-name>` or `?ref=<tag>`.
76+
```
77+
[~] $ terraform-compliance -f git:ssh://github.com/user/repo.git//directory?ref=v1.0.0 ...
78+
```
79+
The directory is optional.
80+
```
81+
[~] $ terraform-compliance -f git:ssh://github.com/user/repo.git//?ref=staging ...
82+
```
83+
84+
7385
### -p / --planfile
7486
{: .d-inline-block }
7587
REQUIRED

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
radish-bdd==0.13.1
22
mock==4.0.2
3-
gitpython==3.1.2
3+
gitpython==3.1.3
44
netaddr==0.7.19
55
colorful==0.5.4
66
filetype==1.0.7
77
junit-xml==1.9
88
emoji==0.5.4
99
lxml==4.5.1
1010
ddt==1.4.1
11-
pytest==5.4.2
11+
pytest==5.4.3
1212
nose==1.3.7

terraform_compliance/main.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,34 @@ def cli(arghandling=ArgHandling(), argparser=ArgumentParser(prog=__app_name__,
6161
if args.ssh_key:
6262
ssh_cmd = {'GIT_SSH_COMMAND': 'ssh -l {} -i {}'.format('git', args.ssh_key)}
6363

64+
features_dir = '/'
6465
# A remote repository used here
6566
if args.features.startswith(('http', 'https', 'ssh')):
66-
features_git_repo = args.features
67+
# Default to master branch and full repository
68+
if args.features.endswith('.git'):
69+
features_git_repo = args.features
70+
features_git_branch = 'master'
71+
72+
# Optionally allow for directory and branch
73+
elif '.git//' in args.features and '?ref=' in args.features:
74+
# Split on .git/
75+
features_git_list = args.features.split('.git/', 1)
76+
# Everything up to .git is the repository
77+
features_git_repo = features_git_list[0] + '.git'
78+
79+
# Split the directory and branch ref
80+
features_git_list = features_git_list[1].split('?ref=', 1)
81+
features_dir = features_git_list[0]
82+
features_git_branch = features_git_list[1]
83+
84+
else: # invalid
85+
raise ValueError("Bad feature directory:" + args.features)
86+
87+
# Clone repository
6788
args.features = mkdtemp()
89+
Repo.clone_from(url=features_git_repo, to_path=args.features, env=ssh_cmd, depth=1, branch=features_git_branch)
6890

69-
Repo.clone_from(url=features_git_repo, to_path=args.features, env=ssh_cmd)
70-
71-
features_directory = os.path.join(os.path.abspath(args.features))
91+
features_directory = os.path.join(os.path.abspath(args.features) + features_dir)
7292

7393
commands = ['radish',
7494
'--write-steps-once',

0 commit comments

Comments
 (0)