Skip to content

Commit d012bcf

Browse files
Merge pull request #3 from GeorgeDavis-Ibexlabs/github-actions
Fixes: GitHub actions
2 parents 180fa01 + 722d0f2 commit d012bcf

File tree

3 files changed

+62
-43
lines changed

3 files changed

+62
-43
lines changed

.env.example

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
input_type=file
2-
input_format=sarif
3-
jira_cloud_url=https://XXXX.atlassian.net/
4-
jira_project_key=PROJ-XYZ
5-
jira_auth_email=test@example.com
6-
jira_api_token=<INSERT-YOUR-JIRA-CLOUD-API-TOKEN>
7-
jira_default_issue_labels=Label1,Label2
8-
jira_use_atlassian_document_format=false
9-
jira_create_sub_tasks=false
1+
INPUT_TYPE=file
2+
INPUT_FORMAT=sarif
3+
JIRA_CLOUD_URL=https://XXXX.atlassian.net/
4+
JIRA_PROJECT_KEY=PROJ-XYZ
5+
JIRA_AUTH_EMAIL=test@example.com
6+
JIRA_API_TOKEN=<INSERT-YOUR-JIRA-CLOUD-API-TOKEN>
7+
JIRA_DEFAULT_ISSUE_LABELS=Label1,Label2
8+
JIRA_USE_ATLASSIAN_DOCUMENT_FORMAT=false
9+
JIRA_CREATE_SUB_TASKS=false

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Project Status: **In Active Development**
4747

4848
| Tools | Link | Status |
4949
|-------|------|--------|
50-
| `cfn-lint` | (aws-cloudformation/cfn-lint)[https://github.com/aws-cloudformation/cfn-lint] | :white_check_mark: |
51-
| `trivy` | (aquasecurity/trivy)[https://github.com/aquasecurity/trivy] | :white_check_mark: |
50+
| `cfn-lint` | [aws-cloudformation/cfn-lint](https://github.com/aws-cloudformation/cfn-lint) | :white_check_mark: |
51+
| `trivy` | [aquasecurity/trivy](https://github.com/aquasecurity/trivy) | :white_check_mark: |
5252

5353

5454
## :construction: Work in progress
@@ -82,6 +82,7 @@ If you're thinking of adding a new feature, consider opening an issue first to d
8282
```sh
8383
docker login
8484
```
85+
8586
```sh
8687
docker build --no-cache --progress=plain . -f Dockerfile -t github-sarif-to-jira:latest 2>&1 | tee build.log
8788
```

config_handler/config_handler.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
from python_json_config import ConfigBuilder, config_node
66
from mergedeep import merge
77

8+
# The ConfigMap - Mapping between runtime environment variable keys and JSON Config keys. Will need to append 'INPUT_' when looking to map within GitHub Actions environment
89
ConfigKeyValuePair = {
9-
'input_type': 'input.type',
10-
'input_format': 'input.format',
11-
'jira_cloud_url': 'jira.cloud_url',
12-
'jira_project_key': 'jira.project_key',
13-
'jira_auth_email': 'jira.auth_email',
14-
'jira_api_token': 'jira.api_token',
15-
'jira_default_issue_labels': 'jira.default_issue_labels',
16-
'jira_use_atlassian_document_format': 'jira.use_atlassian_document_format',
17-
'jira_create_sub_tasks': 'jira.create_sub_tasks'
10+
'INPUT_TYPE': 'input.type',
11+
'INPUT_FORMAT': 'input.format',
12+
'JIRA_CLOUD_URL': 'jira.cloud_url',
13+
'JIRA_PROJECT_KEY': 'jira.project_key',
14+
'JIRA_AUTH_EMAIL': 'jira.auth_email',
15+
'JIRA_API_TOKEN': 'jira.api_token',
16+
'JIRA_DEFAULT_ISSUE_LABELS': 'jira.default_issue_labels',
17+
'JIRA_USE_ATLASSIAN_DOCUMENT_FORMAT': 'jira.use_atlassian_document_format',
18+
'JIRA_CREATE_SUB_TASKS': 'jira.create_sub_tasks'
1819
}
1920

2021
# SARIF - class to handle Static Analysis Results Interchange Format (SARIF)
@@ -102,8 +103,8 @@ def load_config_file(self) -> dict:
102103
local_directory = getcwd()
103104
if 'GITHUB_ACTIONS' in environ.keys():
104105

105-
# self.logger.debug("Running inside GitHub Actions")
106-
local_directory = environ.get("GITHUB_WORKSPACE")
106+
# self.logger.debug('Running inside GitHub Actions')
107+
local_directory = environ.get('GITHUB_WORKSPACE')
107108

108109
for file in listdir(local_directory):
109110
if file == 'config.json':
@@ -142,11 +143,11 @@ def load_config_file(self) -> dict:
142143
# self.builder.validate_field_type('config.jira.use_atlassian_document_format', bool)
143144
# self.builder.validate_field_type('config.jira.create_sub_tasks', bool)
144145

145-
self.logger.debug("Config from the config.json file - " + str(self.config))
146+
self.logger.debug('Config from the config.json file - ' + str(self.config))
146147
return self.config.to_dict() if isinstance(self.config, config_node.Config) else self.config
147148

148149
except Exception as e:
149-
self.logger.error("Error loading config.json file: " + str(traceback.print_tb(e.__traceback__)))
150+
self.logger.error('Error loading config.json file: ' + str(traceback.print_tb(e.__traceback__)))
150151

151152
# Load the config.json file from environment variables instead if running inside GitHub Actions. Environment variables override config.json values to enable CI workflows.
152153
def load_config_env(self) -> dict:
@@ -159,49 +160,66 @@ def load_config_env(self) -> dict:
159160
if config_key in environ.keys():
160161
temp_list.append(config_value)
161162

163+
self.logger.debug('ConfigMap JSON key values found within environment variables - ' + str(temp_list))
164+
162165
unique_parent_list = []
163166
for item in temp_list:
164167
if item.split('.')[0] not in unique_parent_list:
165168
unique_parent_list.append(item.split('.')[0])
166169

170+
self.logger.debug('Parent config attributes found within environment variables - ' + str(unique_parent_list))
171+
167172
for parent_item in unique_parent_list:
168173

169174
temp_config_dict = {}
170-
for list_item in [x for x in temp_list if re.match(parent_item+".*", x)]:
175+
for list_item in [x for x in temp_list if re.match(parent_item+'.*', x)]:
176+
177+
if 'GITHUB_ACTIONS' in environ.keys():
178+
if environ['GITHUB_ACTIONS']:
179+
list_item = 'INPUT_' + list_item
180+
181+
self.logger.debug('Config `' + str(list_item) + '` within parent `' + str(parent_item) + '` - ' + str(environ[list_item.replace('.', '_').upper()]))
182+
171183
item_path = list_item.split('.')
172184
for item in reversed(item_path):
173-
# temp_config_dict.update({item: environ[list_item.replace('.', '_')]})
185+
# temp_config_dict.update({item: environ[list_item.replace('.', '_').upper()]})
174186
# break
175-
if list_item == "jira.default_issue_labels":
176-
temp_config_dict.update({item: environ[list_item.replace('.', '_')].split(",")})
187+
if list_item == 'jira.default_issue_labels':
188+
temp_config_dict.update({
189+
item: environ[list_item.replace('.', '_').upper()].split(',')
190+
})
177191
else:
178192
if list_item in ['jira.use_atlassian_document_format', 'jira.create_sub_tasks']:
179-
temp_config_dict.update({item: self.get_boolean(environ[list_item.replace('.', '_')])})
193+
temp_config_dict.update({
194+
item: self.get_boolean(environ[list_item.replace('.', '_').upper()])
195+
})
180196
else:
181-
temp_config_dict.update({item: environ[list_item.replace('.', '_')]})
197+
temp_config_dict.update({
198+
item: environ[list_item.replace('.', '_').upper()]
199+
})
182200
break
183201
config.update({list_item.split('.')[0]: temp_config_dict})
184-
self.logger.debug("Config from environment variables - " + str(config))
202+
self.logger.debug('Config from environment variables - ' + str(config))
185203
return config
186204

187205
except Exception as e:
188-
self.logger.error("Error loading environment variables: " + str(traceback.print_tb(e.__traceback__)))
206+
self.logger.error('Error loading environment variables: ' + str(traceback.print_tb(e.__traceback__)))
189207

190-
# self.input_type = self.check_if_env_var_exists(env_key="input_type", existing_value=self.input_type)
191-
# self.input_format = self.check_if_env_var_exists(env_key="input_format", existing_value=self.input_format)
192-
# self.jira_cloud_url = self.check_if_env_var_exists(env_key="jira_cloud_url", existing_value=self.jira_cloud_url)
193-
# self.jira_project_key = self.check_if_env_var_exists(env_key="jira_project_key", existing_value=self.jira_project_key)
194-
# self.auth_email = self.check_if_env_var_exists(env_key="jira_auth_email", existing_value=self.auth_email)
195-
# self.api_token = self.check_if_env_var_exists(env_key="jira_api_token", existing_value=self.api_token)
196-
# self.default_issue_labels = self.check_if_env_var_exists(env_key="jira_default_issue_labels", existing_value=self.default_issue_labels)
197-
# self.use_atlassian_document_format = self.check_if_env_var_exists(env_key="jira_use_atlassian_document_format", existing_value=self.use_atlassian_document_format)
198-
# self.create_sub_tasks = self.check_if_env_var_exists(env_key="jira_create_sub_tasks", existing_value=self.create_sub_tasks)
208+
# self.input_type = self.check_if_env_var_exists(env_key='input_type', existing_value=self.input_type)
209+
# self.input_format = self.check_if_env_var_exists(env_key='input_format', existing_value=self.input_format)
210+
# self.jira_cloud_url = self.check_if_env_var_exists(env_key='jira_cloud_url', existing_value=self.jira_cloud_url)
211+
# self.jira_project_key = self.check_if_env_var_exists(env_key='jira_project_key', existing_value=self.jira_project_key)
212+
# self.auth_email = self.check_if_env_var_exists(env_key='jira_auth_email', existing_value=self.auth_email)
213+
# self.api_token = self.check_if_env_var_exists(env_key='jira_api_token', existing_value=self.api_token)
214+
# self.default_issue_labels = self.check_if_env_var_exists(env_key='jira_default_issue_labels', existing_value=self.default_issue_labels)
215+
# self.use_atlassian_document_format = self.check_if_env_var_exists(env_key='jira_use_atlassian_document_format', existing_value=self.use_atlassian_document_format)
216+
# self.create_sub_tasks = self.check_if_env_var_exists(env_key='jira_create_sub_tasks', existing_value=self.create_sub_tasks)
199217

200218
def get_combined_config(self, config_file: dict, config_env: dict) -> dict:
201219

202220
try:
203221
# merged_config = config_env | config_file
204-
# self.logger.debug("Final Config Object - " + str(merged_config))
222+
# self.logger.debug('Final Config Object - ' + str(merged_config))
205223
# return merged_config
206224

207225
# for k in set(config_file.keys()).union(config_env.keys()):
@@ -221,5 +239,5 @@ def get_combined_config(self, config_file: dict, config_env: dict) -> dict:
221239
return merge(config_file, config_env)
222240

223241
except Exception as e:
224-
self.logger.error("Error merging config: " + str(traceback.print_tb(e.__traceback__)))
242+
self.logger.error('Error merging config: ' + str(traceback.print_tb(e.__traceback__)))
225243

0 commit comments

Comments
 (0)