Skip to content

Commit

Permalink
0.5 support downstream pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Nov1kov committed Mar 24, 2021
1 parent 85bc7a4 commit e1be980
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stages:
- deploy

variables:
PROJECT_VERSION: "0.4"
PROJECT_VERSION: "0.5"

build docker:
stage: build
Expand Down
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.5
- support downstream pipelines

# 0.4
- global command "pipeline-mermaid"
- custom message ability
Expand Down
19 changes: 12 additions & 7 deletions pipeline_mermaid/gitlab_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def __show_pipeline_in_mr(self, merge_request, pipeline_id, type, message):
return
text = ''
if message:
text += message
text += '\n' + self.pipeline_as_mermaid(pipeline_id, type)
text += message + '\n'
text += self.pipeline_as_mermaid(pipeline_id, type)
merge_request.notes.create({"body": text})

def __get_mr(self):
Expand All @@ -52,11 +52,20 @@ def __get_mr_by_branch(self, branch_name):
def pipeline_as_mermaid(self, pipeline_id, type):
project = self.get_project()
pipeline = project.pipelines.get(id=pipeline_id)
jobs = pipeline.jobs.list()
jobs = get_jobs_with_child(pipeline)
generator = get_mermaid_generator(jobs, type)
return generator.to_mermaid()


def get_jobs_with_child(pl):
jobs = pl.jobs.list()
for bridge in pl.bridges.list():
if bridge.downstream_pipeline:
child_pl = pl.manager.get(bridge.downstream_pipeline['id'])
jobs += get_jobs_with_child(child_pl)
return jobs


def get_mermaid_generator(jobs, type):
if type == 'gantt':
return GanttGenerator(jobs)
Expand All @@ -67,7 +76,3 @@ def get_mermaid_generator(jobs, type):
else:
raise Exception("Unknown type of diagram")


if __name__ == "__main__":
gl = GitlabHelper()
result = eval("GitlabHelper." + sys.argv[1])(gl, *sys.argv[2:])

0 comments on commit e1be980

Please sign in to comment.