-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_script.py
47 lines (36 loc) · 1.51 KB
/
generate_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Generates a shell script for performing operations on Bitbucket repos. This
is useful for performing batch commits, for example when updating a Jenkinsfile.
"""
import textwrap
import utils
from project import Project
class GenerateScript:
"""Driver for generating scripts."""
def __init__(self):
self.project = Project()
def generate(self):
config = utils.parse_config()
commands = config.get('commands')
output = ''
separator = ' && '
for repo in self.project.get_repos(**config):
clone_info = repo.get('links').get('clone')
for clone_info_item in clone_info:
if clone_info_item.get('name') == 'http':
clone_http_href = clone_info_item.get('href')
if clone_info_item.get('name') == 'ssh':
clone_ssh_href = clone_info_item.get('href')
for command in commands:
command_replaced = command.replace(
'{url}', clone_http_href).replace(
'{url:htttp}', clone_http_href).replace(
'{url:ssh}', clone_ssh_href).replace(
'{project}', config.get('bitbucket').get(
'project')).replace('{repo}', repo.get('slug'))
output += textwrap.dedent(f'{command_replaced}{separator}')
if output.endswith(separator):
output=output[:len(output)-4]
print(output)
if __name__ == '__main__':
GenerateScript().generate()